From 135448939a1bca3329bbbc7fed7cd3f2ca7a980f Mon Sep 17 00:00:00 2001 From: toast-ts <96593068+toast-ts@users.noreply.github.com> Date: Fri, 10 Feb 2023 15:01:55 +1100 Subject: [PATCH] boredom mopping --- src/client.ts | 4 ++++ src/events/interactionCreate.ts | 10 ++-------- src/index.ts | 23 ++++++----------------- src/typings/interfaces.d.ts | 1 + 4 files changed, 13 insertions(+), 25 deletions(-) diff --git a/src/client.ts b/src/client.ts index f4f11a6..156aac0 100644 --- a/src/client.ts +++ b/src/client.ts @@ -93,6 +93,10 @@ export default class TClient extends Client { this.commands.set(command.default.data.name, command) this.registry.push(command.default.data.toJSON()) } + fs.readdirSync('src/events').forEach((file)=>{ + const eventFile = require(`./events/${file}`); + this.on(file.replace('.ts', ''), async(...args)=>eventFile.default.run(this,...args)); + }); } formatPunishmentType(punishment: Punishment, client: TClient, cancels?: Punishment){ if (punishment.type == 'removeOtherPunishment'){ diff --git a/src/events/interactionCreate.ts b/src/events/interactionCreate.ts index 505c497..294fb6c 100644 --- a/src/events/interactionCreate.ts +++ b/src/events/interactionCreate.ts @@ -3,15 +3,9 @@ import TClient from '../client'; export default { async run(client:TClient, interaction:Discord.ChatInputCommandInteraction){ if (!interaction.inGuild() || !interaction.inCachedGuild() || !interaction.command) return; - if (interaction.isCommand()){ - let Sub:string - try{ - Sub = ` ${interaction.options.getSubcommand()}` - }catch(e){ - Sub = '' - } + if (interaction.isChatInputCommand()){ const commandFile = client.commands.get(interaction.commandName); - console.log(`[${client.moment().format('DD/MM/YY HH:mm:ss')}] ${interaction.user.tag} used /${interaction.commandName}${Sub} in #${interaction.channel.name}`); + console.log(`[${client.moment().format('DD/MM/YY HH:mm:ss')}] ${interaction.user.tag} used /${interaction.commandName} ${interaction.options.getSubcommand(false) ?? ''} in #${interaction.channel.name}`); if (!client.config.botSwitches.commands && !client.config.eval.whitelist.includes(interaction.user.id)) return interaction.reply({content: 'Bot is currently being run in development mode.', ephemeral: true}); if (commandFile){ try{ diff --git a/src/index.ts b/src/index.ts index 082bbb0..abe9aad 100644 --- a/src/index.ts +++ b/src/index.ts @@ -30,29 +30,18 @@ client.on('ready', async()=>{ console.log(client.config.botSwitches); console.log(client.config.whitelistedServers); (client.channels.resolve(client.config.mainServer.channels.bot_status) as Discord.TextChannel).send(`${client.user.username} is active\n\`\`\`json\n${Object.entries(client.config.botSwitches).map((hi)=>`${hi[0]}: ${hi[1]}`).join('\n')}\`\`\``); - - // Event handler - fs.readdirSync('src/events').forEach((file)=>{ - const eventFile = require(`./events/${file}`); - client.on(file.replace('.ts', ''), async(...args)=>eventFile.default.run(client,...args)); - }); }) // Handle errors -function DZ(error:Error){// Yes, I may have shiternet but I don't need to wake up to like a hundred messages or so. +function DZ(error:Error, location:string){// Yes, I may have shiternet but I don't need to wake up to like a hundred messages or so. if (['getaddrinfo ENOTFOUND discord.com'].includes(error.message)) return; console.log(error); - (client.channels.resolve(client.config.mainServer.channels.errors) as Discord.TextChannel).send({embeds: [new client.embed().setColor('#420420').setTitle('Error caught!').setDescription(`**Error:** \`${error.message}\`\n\n**Stack:** \`${`${error.stack}`.slice(0, 2500)}\``)]}) + (client.channels.resolve(client.config.mainServer.channels.errors) as Discord.TextChannel).send({embeds: [new client.embed().setColor('#420420').setTitle('Error caught!').setFooter({text: location}).setDescription(`**Error:** \`${error.message}\`\n\n**Stack:** \`${`${error.stack}`.slice(0, 2500)}\``)]}) } -process.on('unhandledRejection', async(error: Error)=>{ - DZ(error) -}); -process.on('uncaughtException', async(error: Error)=>{ - DZ(error) -}); -process.on('error', async(error: Error)=>{ - DZ(error) -}); +process.on('unhandledRejection', async(error: Error)=>DZ(error, 'unhandledRejection')); +process.on('uncaughtException', async(error: Error)=>DZ(error, 'uncaughtException')); +process.on('error', async(error: Error)=>DZ(error, 'process-error')); +client.on('error', async(error: Error)=>DZ(error, 'client-error')); // Daggerwin MP loop setInterval(async()=>{ diff --git a/src/typings/interfaces.d.ts b/src/typings/interfaces.d.ts index 640a800..bb2837a 100644 --- a/src/typings/interfaces.d.ts +++ b/src/typings/interfaces.d.ts @@ -124,6 +124,7 @@ export interface Tokens { token_toast: string token_tae: string webhook_url: string + webhook_url_test: string } export interface Config { embedColor: ColorResolvable,