Replaced clang format with prettuier (sadly)

This commit is contained in:
2023-12-28 16:47:52 +01:00
parent ca5bbd0b81
commit 117140fe9d
99 changed files with 13519 additions and 12011 deletions

View File

@@ -1,13 +1,22 @@
import { Command } from "../interfaces"
import config from "./Config"
import color from "./Colors"
import { REST, RESTGetAPIApplicationGuildCommandResult, RESTPutAPIApplicationGuildCommandsJSONBody, Routes } from "discord.js"
import {
REST,
RESTGetAPIApplicationGuildCommandResult,
RESTPutAPIApplicationGuildCommandsJSONBody,
Routes,
} from "discord.js"
import fs = require("fs")
async function autoDeployCommands() {
const commands = []
const commandFiles = fs.readdirSync("./dist/src/commands/").filter(file => file.endsWith(".js"))
const contentMenuCommands = fs.readdirSync("./dist/src/commands-contextmenu/").filter(file => file.endsWith(".js"))
const commandFiles = fs
.readdirSync("./dist/src/commands/")
.filter(file => file.endsWith(".js"))
const contentMenuCommands = fs
.readdirSync("./dist/src/commands-contextmenu/")
.filter(file => file.endsWith(".js"))
for (const file of commandFiles) {
const command = require(`../commands/${file}`)
@@ -24,9 +33,9 @@ async function autoDeployCommands() {
const rest = new REST({ version: "10" }).setToken(config.dev.devtoken)
const currentCommands = await rest.get(
const currentCommands = (await rest.get(
Routes.applicationGuildCommands(config.dev.devid, config.dev.guildid),
) as RESTGetAPIApplicationGuildCommandResult[]
)) as RESTGetAPIApplicationGuildCommandResult[]
const currentCommandsInfo = currentCommands.map(command => {
return {
@@ -41,40 +50,65 @@ async function autoDeployCommands() {
}
})
const sortedCurrentCommandsInfo = currentCommandsInfo.sort((a, b) => a.name.localeCompare(b.name))
const sortedNewCommandsInfo = newCommandsInfo.sort((a, b) => a.name.localeCompare(b.name))
const sortedCurrentCommandsInfo = currentCommandsInfo.sort((a, b) =>
a.name.localeCompare(b.name),
)
const sortedNewCommandsInfo = newCommandsInfo.sort((a, b) =>
a.name.localeCompare(b.name),
)
const newCmds = sortedNewCommandsInfo.map(cmd => {
return " " + cmd.name + " was registered."
}).join("\n")
const currentCmds = sortedCurrentCommandsInfo.map(cmd => {
return " " + cmd.name + " was unregistered."
}).join("\n")
const newCmds = sortedNewCommandsInfo
.map(cmd => {
return " " + cmd.name + " was registered."
})
.join("\n")
const currentCmds = sortedCurrentCommandsInfo
.map(cmd => {
return " " + cmd.name + " was unregistered."
})
.join("\n")
if (JSON.stringify(sortedNewCommandsInfo) === JSON.stringify(sortedCurrentCommandsInfo)) {
console.log(color.colorize("Commands are the same, skipping deploy.", "green"))
if (
JSON.stringify(sortedNewCommandsInfo) ===
JSON.stringify(sortedCurrentCommandsInfo)
) {
console.log(
color.colorize("Commands are the same, skipping deploy.", "green"),
)
console.log(color.colorize(currentCmds, "green"))
return
}
(async () => {
;(async () => {
try {
console.log(color.colorize("Commands are different, starting deploy.", "red"))
console.log(
color.colorize(
"Commands are different, starting deploy.",
"red",
),
)
console.log(color.colorize(currentCmds, "red"))
console.log(`Started refreshing ${commands.length} application (/) commands.`)
console.log(
`Started refreshing ${commands.length} application (/) commands.`,
)
const data = await rest.put(
Routes.applicationGuildCommands(config.dev.devid, config.dev.guildid),
const data = (await rest.put(
Routes.applicationGuildCommands(
config.dev.devid,
config.dev.guildid,
),
{ body: commands },
) as RESTPutAPIApplicationGuildCommandsJSONBody[]
)) as RESTPutAPIApplicationGuildCommandsJSONBody[]
console.log(color.colorize("New commands deployed.", "green"))
console.log(color.colorize(newCmds, "green"))
console.log(`Successfully reloaded ${data.length} application (/) commands.`)
console.log(
`Successfully reloaded ${data.length} application (/) commands.`,
)
} catch (error) {
console.error(error)
}
})()
}
export { autoDeployCommands }
export { autoDeployCommands }

View File

@@ -6,9 +6,9 @@ import { Modal } from "../interfaces"
import { Autocomplete } from "../interfaces"
export class ExtendedClient extends Client {
commands: Collection<string, Command>= new Collection()
contextmenus: Collection<string, ContextMenu>= new Collection()
buttons: Collection<string, Button>= new Collection()
modals: Collection<string, Modal>= new Collection()
autocomplete: Collection<string, Autocomplete>= new Collection()
}
commands: Collection<string, Command> = new Collection()
contextmenus: Collection<string, ContextMenu> = new Collection()
buttons: Collection<string, Button> = new Collection()
modals: Collection<string, Modal> = new Collection()
autocomplete: Collection<string, Autocomplete> = new Collection()
}

View File

@@ -1,33 +1,33 @@
const colors = {
reset: "\x1b[0m",
bright: "\x1b[1m",
dim: "\x1b[2m",
underscore: "\x1b[4m",
blink: "\x1b[5m",
reverse: "\x1b[7m",
hidden: "\x1b[8m",
reset: "\x1b[0m",
bright: "\x1b[1m",
dim: "\x1b[2m",
underscore: "\x1b[4m",
blink: "\x1b[5m",
reverse: "\x1b[7m",
hidden: "\x1b[8m",
black: "\x1b[30m",
red: "\x1b[31m",
green: "\x1b[32m",
yellow: "\x1b[33m",
blue: "\x1b[34m",
magenta: "\x1b[35m",
cyan: "\x1b[36m",
white: "\x1b[37m",
black: "\x1b[30m",
red: "\x1b[31m",
green: "\x1b[32m",
yellow: "\x1b[33m",
blue: "\x1b[34m",
magenta: "\x1b[35m",
cyan: "\x1b[36m",
white: "\x1b[37m",
bgBlack: "\x1b[40m",
bgRed: "\x1b[41m",
bgGreen: "\x1b[42m",
bgYellow: "\x1b[43m",
bgBlue: "\x1b[44m",
bgMagenta: "\x1b[45m",
bgCyan: "\x1b[46m",
bgWhite: "\x1b[47m",
bgBlack: "\x1b[40m",
bgRed: "\x1b[41m",
bgGreen: "\x1b[42m",
bgYellow: "\x1b[43m",
bgBlue: "\x1b[44m",
bgMagenta: "\x1b[45m",
bgCyan: "\x1b[46m",
bgWhite: "\x1b[47m",
}
function colorize(text: string, color: keyof typeof colors) {
return colors[color] + text + colors.reset
return colors[color] + text + colors.reset
}
export default { colorize }
export default { colorize }

View File

@@ -2,19 +2,19 @@ import { Config } from "../interfaces"
import "dotenv/config"
const config: Config = {
prod: {
token: process.env.TOKEN!,
mongoURI: process.env.MONGOURI!,
dev: process.env.DEV!,
hypixelapikey: process.env.HYPIXELAPIKEY!,
redisURI: process.env.REDISURI!
},
dev: {
devtoken: process.env.DEVTOKEN!,
clientid: process.env.CLIENTID!,
devid: process.env.DEVID!,
guildid: process.env.GUILDID!,
}
prod: {
token: process.env.TOKEN!,
mongoURI: process.env.MONGOURI!,
dev: process.env.DEV!,
hypixelapikey: process.env.HYPIXELAPIKEY!,
redisURI: process.env.REDISURI!,
},
dev: {
devtoken: process.env.DEVTOKEN!,
clientid: process.env.CLIENTID!,
devid: process.env.DEVID!,
guildid: process.env.GUILDID!,
},
}
export default config
export default config

View File

@@ -13,4 +13,4 @@ export function loadAllEvents(client: Client) {
loadContextMenuEvents(client)
loadModalEvents(client)
loadAutocompleteEvents(client)
}
}

View File

@@ -3,4 +3,10 @@ export { bedwarsLevel } from "./functions/bedwars"
export { hypixelLevel } from "./functions/hypixel"
export { formatUuid } from "./functions/uuid"
export { guildLevel, scaledGEXP } from "./functions/guild"
export { getUUID, getIGN, getPlayer, getGuild, getHeadURL } from "./functions/account"
export {
getUUID,
getIGN,
getPlayer,
getGuild,
getHeadURL,
} from "./functions/account"

View File

@@ -3,4 +3,4 @@ import config from "./Config"
const redis = new Redis(config.prod.redisURI)
export { redis }
export { redis }

View File

@@ -5,18 +5,31 @@ import path = require("path")
import fs = require("fs")
function loadAutocompleteEvents(client: Client) {
const autocompletePath = path.join(__dirname, "..", "..", "events", "autocomplete")
const autocompleteFiles = fs.readdirSync(autocompletePath).filter(file => file.endsWith(".js"))
const autocompletePath = path.join(
__dirname,
"..",
"..",
"events",
"autocomplete",
)
const autocompleteFiles = fs
.readdirSync(autocompletePath)
.filter(file => file.endsWith(".js"))
for (const file of autocompleteFiles) {
const filePath = path.join(autocompletePath, file)
const autocomplete: Autocomplete = require(filePath)
if ("name" in autocomplete && "execute" in autocomplete && autocomplete.type === "autocomplete") {
if (
"name" in autocomplete &&
"execute" in autocomplete &&
autocomplete.type === "autocomplete"
) {
client.autocomplete.set(autocomplete.name, autocomplete)
} else {
console.log(`[WARNING] The autocomplete at ${filePath} is missing a required "name", "execute" or "type" property.`)
console.log(
`[WARNING] The autocomplete at ${filePath} is missing a required "name", "execute" or "type" property.`,
)
}
}
@@ -26,7 +39,9 @@ function loadAutocompleteEvents(client: Client) {
const autocomplete = client.autocomplete.get(interaction.commandName)
if (!autocomplete) {
console.error(`No autocomplete matching ${interaction.commandName} was found.`)
console.error(
`No autocomplete matching ${interaction.commandName} was found.`,
)
return
}

View File

@@ -6,28 +6,32 @@ import fs = require("fs")
function loadButtonEvents(client: Client) {
const btnPath = path.join(__dirname, "..", "..", "events", "buttons")
const btnFiles = fs.readdirSync(btnPath).filter(file => file.endsWith(".js"))
const btnFiles = fs
.readdirSync(btnPath)
.filter(file => file.endsWith(".js"))
for (const file of btnFiles) {
const filePath = path.join(btnPath, file)
const btn: Button = require(filePath)
if ("name" in btn && "execute" in btn && btn.type === "button") {
client.buttons.set(btn.name, btn)
} else {
console.log(`[WARNING] The button at ${filePath} is missing a required "name", "execute" or "type" property.`)
console.log(
`[WARNING] The button at ${filePath} is missing a required "name", "execute" or "type" property.`,
)
}
}
client.on(Events.InteractionCreate, async interaction => {
if (!interaction.isButton())
return
if (!interaction.isButton()) return
const button = client.buttons.get(interaction.customId)
if (!button) {
console.error(`No event matching ${interaction.customId} was found.`)
console.error(
`No event matching ${interaction.customId} was found.`,
)
return
}
@@ -37,7 +41,7 @@ function loadButtonEvents(client: Client) {
console.error(error)
await interaction.reply({
content: "There was an error while executing this event!",
ephemeral: true
ephemeral: true,
})
}
})

View File

@@ -6,29 +6,33 @@ import fs = require("fs")
function loadSlashCommandsEvents(client: Client) {
const cmdPath = path.join(__dirname, "..", "..", "commands")
const cmdFiles = fs.readdirSync(cmdPath).filter(file => file.endsWith(".js"))
const cmdFiles = fs
.readdirSync(cmdPath)
.filter(file => file.endsWith(".js"))
for (const file of cmdFiles) {
const filePath = path.join(cmdPath, file)
const cmd: Command = require(filePath)
if ("data" in cmd && "execute" in cmd && cmd.type === "slash") {
client.commands.set(cmd.data.name, cmd)
} else {
console.log(`[WARNING] The command at ${filePath} is missing a required "data", "execute" or "type" property.`)
console.log(
`[WARNING] The command at ${filePath} is missing a required "data", "execute" or "type" property.`,
)
}
}
//! command handler
client.on(Events.InteractionCreate, async interaction => {
if (!interaction.isChatInputCommand())
return
if (!interaction.isChatInputCommand()) return
const command = client.commands.get(interaction.commandName)
if (!command) {
console.error(`No command matching ${interaction.commandName} was found.`)
console.error(
`No command matching ${interaction.commandName} was found.`,
)
return
}
@@ -38,7 +42,7 @@ function loadSlashCommandsEvents(client: Client) {
console.error(error)
await interaction.reply({
content: "There was an error while executing this command!",
ephemeral: true
ephemeral: true,
})
}
})

View File

@@ -5,30 +5,39 @@ import path = require("path")
import fs = require("fs")
function loadContextMenuEvents(client: Client) {
const contextMenuPath = path.join(__dirname, "..", "..", "commands-contextmenu")
const contextMenuFiles = fs.readdirSync(contextMenuPath).filter(file => file.endsWith(".js"))
const contextMenuPath = path.join(
__dirname,
"..",
"..",
"commands-contextmenu",
)
const contextMenuFiles = fs
.readdirSync(contextMenuPath)
.filter(file => file.endsWith(".js"))
for (const file of contextMenuFiles) {
const filePath = path.join(contextMenuPath, file)
const cmd: ContextMenu = require(filePath)
if ("data" in cmd && "execute" in cmd && cmd.type === "contextmenu") {
client.contextmenus.set(cmd.data.name, cmd)
} else {
console.log(`[WARNING] The command at ${filePath} is missing a required "data", "execute" or "type" property.`)
console.log(
`[WARNING] The command at ${filePath} is missing a required "data", "execute" or "type" property.`,
)
}
}
//! context menu command handler
client.on(Events.InteractionCreate, async interaction => {
if (!interaction.isContextMenuCommand())
return
if (!interaction.isContextMenuCommand()) return
const command = client.contextmenus.get(interaction.commandName)
if (!command) {
console.error(`No command matching ${interaction.commandName} was found.`)
console.error(
`No command matching ${interaction.commandName} was found.`,
)
return
}
@@ -38,7 +47,7 @@ function loadContextMenuEvents(client: Client) {
console.error(error)
await interaction.reply({
content: "There was an error while executing this command!",
ephemeral: true
ephemeral: true,
})
}
})

View File

@@ -14,7 +14,6 @@ function loadEvents(client: Client) {
client.on(event.event, event.execute)
}
}
}
export { loadEvents }
export { loadEvents }

View File

@@ -6,28 +6,32 @@ import fs = require("fs")
function loadModalEvents(client: Client) {
const modalPath = path.join(__dirname, "..", "..", "events", "modals")
const modalFiles = fs.readdirSync(modalPath).filter(file => file.endsWith(".js"))
const modalFiles = fs
.readdirSync(modalPath)
.filter(file => file.endsWith(".js"))
for (const file of modalFiles) {
const filePath = path.join(modalPath, file)
const modal: Modal = require(filePath)
if ("name" in modal && "execute" in modal && modal.type === "modal") {
client.modals.set(modal.name, modal)
} else {
console.log(`[WARNING] The modal at ${filePath} is missing a required "name", "execute" or "type" property.`)
console.log(
`[WARNING] The modal at ${filePath} is missing a required "name", "execute" or "type" property.`,
)
}
}
client.on(Events.InteractionCreate, async interaction => {
if (!interaction.isModalSubmit())
return
if (!interaction.isModalSubmit()) return
const modal = client.modals.get(interaction.customId)
if (!modal) {
console.error(`No modal matching ${interaction.customId} was found.`)
console.error(
`No modal matching ${interaction.customId} was found.`,
)
return
}
@@ -37,7 +41,7 @@ function loadModalEvents(client: Client) {
console.error(error)
await interaction.reply({
content: "There was an error while executing this modal!",
ephemeral: true
ephemeral: true,
})
}
})

View File

@@ -10,7 +10,7 @@ const hypixel = "https://api.hypixel.net/player"
const guild = "https://api.hypixel.net/guild"
const minotar = "https://minotar.net/helm/"
async function getUUID(ign: string): Promise<string|null> {
async function getUUID(ign: string): Promise<string | null> {
try {
const req: Profile = await fetch(mojang + ign)
return req.data.id
@@ -19,7 +19,7 @@ async function getUUID(ign: string): Promise<string|null> {
}
}
async function getIGN(uuid: string): Promise<string|null> {
async function getIGN(uuid: string): Promise<string | null> {
try {
const req: Profile2 = await fetch(mojanguuid + uuid)
return req.data.name
@@ -28,12 +28,12 @@ async function getIGN(uuid: string): Promise<string|null> {
}
}
async function getPlayer(uuid: string): Promise<PlayerData|null> {
async function getPlayer(uuid: string): Promise<PlayerData | null> {
const playerReq: Player = await fetch(hypixel, {
params: {
key: apikey,
uuid: uuid
}
uuid: uuid,
},
})
if (!playerReq.data.player) {
@@ -43,14 +43,17 @@ async function getPlayer(uuid: string): Promise<PlayerData|null> {
return playerReq.data.player
}
async function getGuild(query: string, type?: string): Promise<GuildData|null> {
async function getGuild(
query: string,
type?: string,
): Promise<GuildData | null> {
const reqType = type ? type : "player"
const guildReq: Guild = await fetch(guild, {
params: {
key: apikey,
[reqType]: query
}
[reqType]: query,
},
})
if (!guildReq.data.guild) {
@@ -60,14 +63,8 @@ async function getGuild(query: string, type?: string): Promise<GuildData|null> {
return guildReq.data.guild
}
async function getHeadURL(ign: string): Promise<string|null> {
async function getHeadURL(ign: string): Promise<string | null> {
return minotar + ign
}
export {
getUUID,
getIGN,
getPlayer,
getGuild,
getHeadURL
}
export { getUUID, getIGN, getPlayer, getGuild, getHeadURL }

View File

@@ -10,14 +10,14 @@ function getExpForLevel(level: number): number {
}
switch (respectedLevel) {
case 1:
return 500
case 2:
return 1000
case 3:
return 2000
case 4:
return 3500
case 1:
return 500
case 2:
return 1000
case 3:
return 2000
case 4:
return 3500
}
return 5000
}
@@ -25,8 +25,7 @@ function getExpForLevel(level: number): number {
function getLevelRespectingPrestige(level: number): number {
if (level > HIGHEST_PRESTIGE * LEVELS_PER_PRESTIGE) {
return level - HIGHEST_PRESTIGE * LEVELS_PER_PRESTIGE
}
else {
} else {
return level % LEVELS_PER_PRESTIGE
}
}
@@ -39,7 +38,7 @@ const HIGHEST_PRESTIGE = 50
function bedwarsLevel(exp: number): number {
const prestiges = Math.floor(exp / XP_PER_PRESTIGE)
let level = prestiges * LEVELS_PER_PRESTIGE
let expWithoutPrestiges = exp - (prestiges * XP_PER_PRESTIGE)
let expWithoutPrestiges = exp - prestiges * XP_PER_PRESTIGE
for (let i = 1; i <= EASY_LEVELS; ++i) {
const expForEasyLevel = getExpForLevel(i)
@@ -52,4 +51,4 @@ function bedwarsLevel(exp: number): number {
return level + expWithoutPrestiges / 5000
}
export { bedwarsLevel }
export { bedwarsLevel }

View File

@@ -3,21 +3,8 @@
*/
function guildLevel(exp: number): number {
const EXP_NEEDED = [
100000,
150000,
250000,
500000,
750000,
1000000,
1250000,
1500000,
2000000,
2500000,
2500000,
2500000,
2500000,
2500000,
3000000,
100000, 150000, 250000, 500000, 750000, 1000000, 1250000, 1500000,
2000000, 2500000, 2500000, 2500000, 2500000, 2500000, 3000000,
]
let level = 0
@@ -28,13 +15,15 @@ function guildLevel(exp: number): number {
let need = 0
if (i >= EXP_NEEDED.length) {
need = EXP_NEEDED[EXP_NEEDED.length - 1]
} else { need = EXP_NEEDED[i] }
} else {
need = EXP_NEEDED[i]
}
// If the required exp to get to the next level isn't met returns
// the current level plus progress towards the next (unused exp/need)
// Otherwise increments the level and substracts the used exp from exp var
if ((exp - need) < 0) {
return Math.round((level + (exp / need)) * 100) / 100
if (exp - need < 0) {
return Math.round((level + exp / need) * 100) / 100
}
level += 1
exp -= need
@@ -49,9 +38,11 @@ function guildLevel(exp: number): number {
*/
function scaledGEXP(input: number): number {
if (input <= 200000) return Number(input)
if (input <= 700000) return Number(Math.round(((input - 200000) / 10) + 200000))
if (input > 700000) return Number(Math.round(((input - 700000) / 33) + 250000))
if (input <= 700000)
return Number(Math.round((input - 200000) / 10 + 200000))
if (input > 700000)
return Number(Math.round((input - 700000) / 33 + 250000))
return 0
}
export { guildLevel, scaledGEXP }
export { guildLevel, scaledGEXP }

View File

@@ -9,7 +9,13 @@ const REVERSE_CONST = REVERSE_PQ_PREFIX * REVERSE_PQ_PREFIX
const GROWTH_DIVIDES_2 = 2 / GROWTH
function getLevel(exp: number): number {
return exp <= 1 ? 1 : Math.floor(1 + REVERSE_PQ_PREFIX + Math.sqrt(REVERSE_CONST + GROWTH_DIVIDES_2 * exp))
return exp <= 1
? 1
: Math.floor(
1 +
REVERSE_PQ_PREFIX +
Math.sqrt(REVERSE_CONST + GROWTH_DIVIDES_2 * exp),
)
}
function hypixelLevel(exp: number): number {
@@ -17,8 +23,8 @@ function hypixelLevel(exp: number): number {
}
function getTotalExpToLevel(level: number): number {
const lv = Math.floor(level); const
x0 = getTotalExpToFullLevel(lv)
const lv = Math.floor(level)
const x0 = getTotalExpToFullLevel(lv)
if (level === lv) return x0
return (getTotalExpToFullLevel(lv + 1) - x0) * (level % 1) + x0
}
@@ -33,5 +39,4 @@ function getPercentageToNextLevel(exp: number): number {
return (exp - x0) / (getTotalExpToLevel(lv + 1) - x0)
}
export { hypixelLevel }
export { hypixelLevel }

View File

@@ -19,4 +19,4 @@ function skywarsLevel(xp: number): number {
return 0
}
export { skywarsLevel }
export { skywarsLevel }

View File

@@ -2,4 +2,4 @@ function formatUuid(uuid: string): string {
return uuid.replace(/(.{8})(.{4})(.{4})(.{4})(.{12})/, "$1-$2-$3-$4-$5")
}
export { formatUuid }
export { formatUuid }