diff --git a/src/interfaces/Command.ts b/src/interfaces/Command.ts index bf578f0..124acb4 100644 --- a/src/interfaces/Command.ts +++ b/src/interfaces/Command.ts @@ -10,8 +10,5 @@ export default interface Command { disabled?: boolean subcommands?: boolean data: SlashCommandBuilder - execute: ( - interaction: ChatInputCommandInteraction, - client: Client - ) => Promise + execute: (interaction: ChatInputCommandInteraction, client: Client) => Promise } diff --git a/src/utils/Autodeploy.ts b/src/utils/Autodeploy.ts index e43f04a..3a1f615 100644 --- a/src/utils/Autodeploy.ts +++ b/src/utils/Autodeploy.ts @@ -1,12 +1,7 @@ import { Command } from "interfaces" import color from "./functions/colors" import env from "./Env" -import { - REST, - RESTGetAPIApplicationGuildCommandResult, - RESTPutAPIApplicationGuildCommandsJSONBody, - Routes -} from "discord.js" +import { REST, RESTGetAPIApplicationGuildCommandResult, RESTPutAPIApplicationGuildCommandsJSONBody, Routes } from "discord.js" import fs from "fs" type FileType = "js" | "ts" @@ -16,19 +11,11 @@ export default async function autoDeployCommands(fileType: FileType) { let contentMenuCommands: string[] = [] if (fileType === "js") { - commandFiles = fs - .readdirSync("./dist/commands/") - .filter(file => file.endsWith(fileType)) - contentMenuCommands = fs - .readdirSync("./dist/commands-contextmenu/") - .filter(file => file.endsWith(fileType)) + commandFiles = fs.readdirSync("./dist/commands/").filter(file => file.endsWith(fileType)) + contentMenuCommands = fs.readdirSync("./dist/commands-contextmenu/").filter(file => file.endsWith(fileType)) } else if (fileType === "ts") { - commandFiles = fs - .readdirSync("./src/commands/") - .filter(file => file.endsWith(fileType)) - contentMenuCommands = fs - .readdirSync("./src/commands-contextmenu/") - .filter(file => file.endsWith(fileType)) + commandFiles = fs.readdirSync("./src/commands/").filter(file => file.endsWith(fileType)) + contentMenuCommands = fs.readdirSync("./src/commands-contextmenu/").filter(file => file.endsWith(fileType)) } for (const file of commandFiles) { @@ -70,24 +57,15 @@ export default async function autoDeployCommands(fileType: FileType) { 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("Commands are the same, skipping deploy.", "lavender") - ) + if (JSON.stringify(sortedNewCommandsInfo) === JSON.stringify(sortedCurrentCommandsInfo)) { + console.log(color("Commands are the same, skipping deploy.", "lavender")) console.log(color(newCmds, "lavender")) return } @@ -95,9 +73,7 @@ export default async function autoDeployCommands(fileType: FileType) { try { console.log(color("Commands are different, starting deploy.", "red")) console.log(color(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(env.dev.devid!, env.dev.guildid!), @@ -106,9 +82,7 @@ export default async function autoDeployCommands(fileType: FileType) { console.log(color("New commands deployed.", "lavender")) console.log(color(newCmds, "lavender")) - console.log( - `Successfully reloaded ${data.length} application (/) commands.` - ) + console.log(`Successfully reloaded ${data.length} application (/) commands.`) } catch (error) { console.error(error) } diff --git a/src/utils/Client.ts b/src/utils/Client.ts index 83fe95e..83b0593 100644 --- a/src/utils/Client.ts +++ b/src/utils/Client.ts @@ -3,7 +3,6 @@ import color from "./functions/colors" import { Command, ContextMenu, Button, Modal, Autocomplete } from "interfaces" import env from "./Env" import autoDeployCommands from "./Autodeploy" -import { loadAllEvents } from "./Events" export class ExtendedClient extends Client { commands: Collection = new Collection() @@ -34,20 +33,15 @@ export class ExtendedClient extends Client { async start() { let token: string if (process.env.NODE_ENV === "dev" && process.env.TYPESCRIPT) { - console.log( - color("Running in development mode. [ts-node]", "lavender") - ) - loadAllEvents(this, "ts") + console.log(color("Running in development mode. [ts-node]", "lavender")) token = env.dev.devtoken! autoDeployCommands("ts") } else if (process.env.NODE_ENV === "dev" && !process.env.TYPESCRIPT) { console.log(color("Running in development mode.", "lavender")) - loadAllEvents(this, "js") token = env.dev.devtoken! autoDeployCommands("js") } else { console.log(color("Running in production mode.", "green")) - loadAllEvents(this, "js") token = env.prod.token! } diff --git a/src/utils/Events/autocomplete.ts b/src/utils/Events/autocomplete.ts index 0214bfa..6ad7463 100644 --- a/src/utils/Events/autocomplete.ts +++ b/src/utils/Events/autocomplete.ts @@ -10,16 +10,8 @@ type FileType = "js" | "ts" const embedColor = Number(color.replace("#", "0x")) export default function loadAutocompleteEvents(client: Client, ft: FileType) { - const autocompletePath = path.join( - __dirname, - "..", - "..", - "components", - "autocomplete" - ) - const autocompleteFiles = fs - .readdirSync(autocompletePath) - .filter(file => file.endsWith(ft)) + const autocompletePath = path.join(__dirname, "..", "..", "components", "autocomplete") + const autocompleteFiles = fs.readdirSync(autocompletePath).filter(file => file.endsWith(ft)) for (const file of autocompleteFiles) { const filePath = path.join(autocompletePath, file) @@ -43,9 +35,7 @@ export default function loadAutocompleteEvents(client: Client, ft: FileType) { 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 } @@ -54,21 +44,15 @@ export default function loadAutocompleteEvents(client: Client, ft: FileType) { } catch (error) { if (process.env.NODE_ENV !== "dev") { await logToChannel("error", { - embeds: [ - { - title: "Autocomplete error occured", - description: String(error), - color: embedColor, - footer: { - icon_url: - interaction.guild!.iconURL() || undefined, - text: - interaction.user.username + - " | " + - interaction.commandName - } + embeds: [{ + title: "Autocomplete error occured", + description: "```" + error + "```", + color: embedColor, + footer: { + icon_url: interaction.guild!.iconURL() || undefined, + text: interaction.user.username + " | " + interaction.commandName } - ] + }] }) } console.error(error) diff --git a/src/utils/Events/button.ts b/src/utils/Events/button.ts index 3b4ceb6..3c34a8e 100644 --- a/src/utils/Events/button.ts +++ b/src/utils/Events/button.ts @@ -35,9 +35,7 @@ export default function loadButtonEvents(client: Client, ft: FileType) { 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 } @@ -46,45 +44,33 @@ export default function loadButtonEvents(client: Client, ft: FileType) { } catch (error) { if (process.env.NODE_ENV !== "dev") { await logToChannel("error", { - embeds: [ - { - title: "Button error occured", - description: "```" + error + "```", - color: embedColor, - footer: { - icon_url: - interaction.guild!.iconURL() || undefined, - text: - interaction.user.username + - " | " + - interaction.customId - } + embeds: [{ + title: "Button error occured", + description: "```" + error + "```", + color: embedColor, + footer: { + icon_url: interaction.guild!.iconURL() || undefined, + text: interaction.user.username + " | " + interaction.customId } - ] + }] }) } console.error(error) if (!interaction.deferred) { await interaction.reply({ - embeds: [ - { - description: - "There was an error while executing this button!", - color: embedColor - } - ], + embeds: [{ + description: "There was an error while executing this button!", + color: embedColor + }], ephemeral: true }) } else { await interaction.editReply({ - embeds: [ - { - description: - "There was an error while executing this button! 2", - color: embedColor - } - ] + embeds: [{ + description: "There was an error while executing this button! 2", + color: embedColor + }] }) } } diff --git a/src/utils/Events/command.ts b/src/utils/Events/command.ts index fca4da4..e44b0a0 100644 --- a/src/utils/Events/command.ts +++ b/src/utils/Events/command.ts @@ -47,45 +47,33 @@ export default function loadSlashCommandsEvents(client: Client, ft: FileType) { } catch (error) { if (process.env.NODE_ENV !== "dev") { await logToChannel("error", { - embeds: [ - { - title: "Command error occured", - description: "```" + error + "```", - color: embedColor, - footer: { - icon_url: - interaction.guild!.iconURL() || undefined, - text: - interaction.user.username + - " | " + - interaction.commandName - } + embeds: [{ + title: "Command error occured", + description: "```" + error + "```", + color: embedColor, + footer: { + icon_url: interaction.guild!.iconURL() || undefined, + text: interaction.user.username + " | " + interaction.commandName } - ] + }] }) } console.error(error) if (!interaction.deferred) { await interaction.reply({ - embeds: [ - { - description: - "There was an error while executing this command!", - color: embedColor - } - ], + embeds: [{ + description: "There was an error while executing this command!", + color: embedColor + }], ephemeral: true }) } else { await interaction.editReply({ - embeds: [ - { - description: - "There was an error while executing this command!", - color: embedColor - } - ] + embeds: [{ + description: "There was an error while executing this command!", + color: embedColor + }] }) } } diff --git a/src/utils/Events/contextmenu.ts b/src/utils/Events/contextmenu.ts index 8880504..405d3de 100644 --- a/src/utils/Events/contextmenu.ts +++ b/src/utils/Events/contextmenu.ts @@ -10,15 +10,8 @@ type FileType = "js" | "ts" const embedColor = Number(color.replace("#", "0x")) export default function loadContextMenuEvents(client: Client, ft: FileType) { - const contextMenuPath = path.join( - __dirname, - "..", - "..", - "commands-contextmenu" - ) - const contextMenuFiles = fs - .readdirSync(contextMenuPath) - .filter(file => file.endsWith(ft)) + const contextMenuPath = path.join(__dirname, "..", "..", "commands-contextmenu") + const contextMenuFiles = fs.readdirSync(contextMenuPath).filter(file => file.endsWith(ft)) for (const file of contextMenuFiles) { const filePath = path.join(contextMenuPath, file) @@ -43,9 +36,7 @@ export default function loadContextMenuEvents(client: Client, ft: FileType) { 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 } @@ -54,45 +45,33 @@ export default function loadContextMenuEvents(client: Client, ft: FileType) { } catch (error) { if (process.env.NODE_ENV !== "dev") { await logToChannel("error", { - embeds: [ - { - title: "Contextmenu error occured", - description: "```" + error + "```", - color: embedColor, - footer: { - icon_url: - interaction.guild!.iconURL() || undefined, - text: - interaction.user.username + - " | " + - interaction.commandName - } + embeds: [{ + title: "Contextmenu error occured", + description: "```" + error + "```", + color: embedColor, + footer: { + icon_url: interaction.guild!.iconURL() || undefined, + text: interaction.user.username + " | " + interaction.commandName } - ] + }] }) } console.error(error) if (!interaction.deferred) { await interaction.reply({ - embeds: [ - { - description: - "There was an error while executing this contextmenu command!", - color: embedColor - } - ], + embeds: [{ + description: "There was an error while executing this contextmenu command!", + color: embedColor + }], ephemeral: true }) } else { await interaction.editReply({ - embeds: [ - { - description: - "There was an error while executing this contextmenu command!", - color: embedColor - } - ] + embeds: [{ + description: "There was an error while executing this contextmenu command!", + color: embedColor + }] }) } } diff --git a/src/utils/Events/cron.ts b/src/utils/Events/cron.ts index 530d787..3727ae3 100644 --- a/src/utils/Events/cron.ts +++ b/src/utils/Events/cron.ts @@ -5,33 +5,20 @@ import { Cron } from "interfaces" export default function loadCronEvents() { const cronPath = path.join(__dirname, "..", "..", "events", "cron") - const cronFiles = fs - .readdirSync(cronPath) - .filter(file => file.endsWith(".js")) + const cronFiles = fs.readdirSync(cronPath).filter(file => file.endsWith(".js")) for (const file of cronFiles) { const filePath = path.join(cronPath, file) const cron: Cron = require(filePath) const time = - cron.time.seconds + - " " + - cron.time.minutes + - " " + - cron.time.hours + - " " + - cron.time.dayOfMonth + - " " + - cron.time.month + - " " + + cron.time.seconds + " " + + cron.time.minutes + " " + + cron.time.hours + " " + + cron.time.dayOfMonth + " " + + cron.time.month + " " + cron.time.dayOfWeek - new CronJob( - time, - cron.execute, - cron.onComplete, - cron.start, - cron.timeZone - ).start() + new CronJob(time, cron.execute, cron.onComplete, cron.start, cron.timeZone).start() } } diff --git a/src/utils/Events/index.ts b/src/utils/Events/index.ts index 86d6f1f..e1c2ad6 100644 --- a/src/utils/Events/index.ts +++ b/src/utils/Events/index.ts @@ -6,9 +6,8 @@ import loadContextMenuEvents from "./contextmenu" import loadCronEvents from "./cron" import loadEvents from "./events" import loadModalEvents from "./modal" -type FileType = "js" | "ts" -export function loadAllEvents(client: Client, ft: FileType) { +export default function loadAllEvents(client: Client, ft: "js" | "ts") { loadEvents(client) loadButtonEvents(client, ft) loadSlashCommandsEvents(client, ft) diff --git a/src/utils/Events/modal.ts b/src/utils/Events/modal.ts index 0aeba2a..7e3c61c 100644 --- a/src/utils/Events/modal.ts +++ b/src/utils/Events/modal.ts @@ -11,9 +11,7 @@ const embedColor = Number(color.replace("#", "0x")) export default function loadModalEvents(client: Client, ft: FileType) { const modalPath = path.join(__dirname, "..", "..", "components", "modals") - const modalFiles = fs - .readdirSync(modalPath) - .filter(file => file.endsWith(ft)) + const modalFiles = fs.readdirSync(modalPath).filter(file => file.endsWith(ft)) for (const file of modalFiles) { const filePath = path.join(modalPath, file) @@ -37,9 +35,7 @@ export default function loadModalEvents(client: Client, ft: FileType) { 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 } @@ -48,44 +44,32 @@ export default function loadModalEvents(client: Client, ft: FileType) { } catch (error) { if (process.env.NODE_ENV !== "dev") { await logToChannel("error", { - embeds: [ - { - title: "Button error occured", - description: "```" + error + "```", - color: embedColor, - footer: { - icon_url: - interaction.guild!.iconURL() || undefined, - text: - interaction.user.username + - " | " + - interaction.customId - } + embeds: [{ + title: "Button error occured", + description: "```" + error + "```", + color: embedColor, + footer: { + icon_url: interaction.guild!.iconURL() || undefined, + text: interaction.user.username + " | " + interaction.customId } - ] + }] }) } console.error(error) if (!interaction.deferred) { await interaction.reply({ - embeds: [ - { - description: - "There was an error while executing this modal!", - color: embedColor - } - ] + embeds: [{ + description: "There was an error while executing this modal!", + color: embedColor + }] }) } else { await interaction.editReply({ - embeds: [ - { - description: - "There was an error while executing this modal!", - color: embedColor - } - ] + embeds: [{ + description: "There was an error while executing this modal!", + color: embedColor + }] }) } } diff --git a/src/utils/Hypixel/account.ts b/src/utils/Hypixel/account.ts index 1765923..3140083 100644 --- a/src/utils/Hypixel/account.ts +++ b/src/utils/Hypixel/account.ts @@ -8,7 +8,7 @@ const mojanguuid = "https://sessionserver.mojang.com/session/minecraft/profile/" const hypixel = "https://api.hypixel.net/player" const guild = "https://api.hypixel.net/guild" const minotar = "https://minotar.net/helm/" -type GuildQuerqType = "player" | "name" | "id" +type GuildQueryType = "player" | "name" | "id" type Profile = { data: { @@ -47,8 +47,10 @@ async function getIGN(uuid: string): Promise { async function getPlayer(uuid: string): Promise { const playerReq: Player = await fetch(hypixel, { params: { - key: apikey, uuid: uuid + }, + headers: { + "API-Key": apikey } }) @@ -59,16 +61,15 @@ async function getPlayer(uuid: string): Promise { return playerReq.data.player } -async function getGuild( - query: string, - type?: GuildQuerqType -): Promise { +async function getGuild(query: string, type?: GuildQueryType): Promise { const reqType = type ? type : "player" const guildReq: Guild = await fetch(guild, { params: { - key: apikey, [reqType]: query + }, + headers: { + "API-Key": apikey } }) diff --git a/src/utils/Hypixel/guild.ts b/src/utils/Hypixel/guild.ts index 6f82f7f..978f115 100644 --- a/src/utils/Hypixel/guild.ts +++ b/src/utils/Hypixel/guild.ts @@ -38,10 +38,8 @@ 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 } diff --git a/src/utils/Illegitimate.ts b/src/utils/Illegitimate.ts index bc625c5..4b23a7c 100644 --- a/src/utils/Illegitimate.ts +++ b/src/utils/Illegitimate.ts @@ -3,13 +3,25 @@ import color from "utils/functions/colors" import { Redis } from "ioredis" import env from "utils/Env" import { connect } from "mongoose" +import loadAllEvents from "./Events" const client = new Client() const redis = new Redis(env.prod.redisURI!) +let ft: "js" | "ts" +if (process.env.NODE_ENV === "dev" && process.env.TYPESCRIPT === "true") { + ft = "ts" +} else { + ft = "js" +} class Bot { async start() { this.init() + loadAllEvents(client, ft) client.start() + this.databases() + } + + private async databases() { redis.on("ready", () => { console.log(color("Connected to Redis", "green")) }) diff --git a/src/utils/functions/logtochannel.ts b/src/utils/functions/logtochannel.ts index a36a47a..bf05fdf 100644 --- a/src/utils/functions/logtochannel.ts +++ b/src/utils/functions/logtochannel.ts @@ -21,10 +21,7 @@ const channels = { type Channel = keyof typeof channels -export default async function logToChannel( - channel: Channel, - message: MessageCreateOptions -): Promise { +export default async function logToChannel(channel: Channel, message: MessageCreateOptions): Promise { const guild = Illegitimate.client.guilds.cache.get(guildid) as Guild let logChannel: TextChannel @@ -35,9 +32,7 @@ export default async function logToChannel( } if (!logChannel) { - console.log( - `[ERROR] Could not find channel used for ${channel} logging.` - ) + console.log(`[ERROR] Could not find channel used for ${channel} logging.`) return } diff --git a/src/utils/functions/rolesmanage.ts b/src/utils/functions/rolesmanage.ts index a1726be..72b49dd 100644 --- a/src/utils/functions/rolesmanage.ts +++ b/src/utils/functions/rolesmanage.ts @@ -30,63 +30,46 @@ type RoleType = | "default" | "all" -export default function roleManage(role: RoleType): { - rolesToRemove: string[] - rolesToAdd: string[] -} { +export default function roleManage(role: RoleType): { rolesToRemove: string[], rolesToAdd: string[] } { if (role === "gm") { - const rolesToRemove = roles.filter( - role => role !== gm && role !== guildStaff && role !== guildRole - ) + const rolesToRemove = roles.filter(role => role !== gm && role !== guildStaff && role !== guildRole) const rolesToAdd = [gm, guildStaff, guildRole] return { rolesToRemove, rolesToAdd } } if (role === "manager") { - const rolesToRemove = roles.filter( - role => - role !== manager && role !== guildStaff && role !== guildRole - ) + const rolesToRemove = roles.filter(role => role !== manager && role !== guildStaff && role !== guildRole) const rolesToAdd = [manager, guildStaff, guildRole] return { rolesToRemove, rolesToAdd } } if (role === "moderator") { - const rolesToRemove = roles.filter( - role => - role !== moderator && role !== guildStaff && role !== guildRole - ) + const rolesToRemove = roles.filter(role => role !== moderator && role !== guildStaff && role !== guildRole) const rolesToAdd = [moderator, guildStaff, guildRole] return { rolesToRemove, rolesToAdd } } if (role === "beast") { - const rolesToRemove = roles.filter( - role => role !== beast && role !== guildRole - ) + const rolesToRemove = roles.filter(role => role !== beast && role !== guildRole) const rolesToAdd = [beast, guildRole] return { rolesToRemove, rolesToAdd } } if (role === "elite") { - const rolesToRemove = roles.filter( - role => role !== elite && role !== guildRole - ) + const rolesToRemove = roles.filter(role => role !== elite && role !== guildRole) const rolesToAdd = [elite, guildRole] return { rolesToRemove, rolesToAdd } } if (role === "member") { - const rolesToRemove = roles.filter( - role => role !== member && role !== guildRole - ) + const rolesToRemove = roles.filter(role => role !== member && role !== guildRole) const rolesToAdd = [member, guildRole] return { rolesToRemove, rolesToAdd } } if (role === "default") { const rolesToRemove = roles - const rolesToAdd: string[] = [defaultMember] + const rolesToAdd = [defaultMember] return { rolesToRemove, rolesToAdd } }