From bc437a5ec7ce1d339094d608e2a61ac5f460c163 Mon Sep 17 00:00:00 2001 From: PalmDevs Date: Wed, 31 Jul 2024 19:33:40 +0700 Subject: [PATCH] fix: other small issues --- apis/websocket/package.json | 2 +- bots/discord/package.json | 2 +- .../src/events/discord/interactionCreate/chatCommand.ts | 3 ++- .../src/events/discord/messageCreate/messageCommand.ts | 2 +- bots/discord/src/events/discord/messageCreate/scanMessage.ts | 2 +- bots/discord/src/index.ts | 5 +++++ 6 files changed, 11 insertions(+), 5 deletions(-) diff --git a/apis/websocket/package.json b/apis/websocket/package.json index 9eef52e..43d73d7 100755 --- a/apis/websocket/package.json +++ b/apis/websocket/package.json @@ -37,4 +37,4 @@ "@types/ws": "^8.5.10", "typed-emitter": "^2.1.0" } -} \ No newline at end of file +} diff --git a/bots/discord/package.json b/bots/discord/package.json index 3c49da7..f577fd4 100644 --- a/bots/discord/package.json +++ b/bots/discord/package.json @@ -43,4 +43,4 @@ "discord-api-types": "^0.37.92", "drizzle-kit": "^0.22.8" } -} \ No newline at end of file +} diff --git a/bots/discord/src/events/discord/interactionCreate/chatCommand.ts b/bots/discord/src/events/discord/interactionCreate/chatCommand.ts index 28c7f56..b3d1c95 100644 --- a/bots/discord/src/events/discord/interactionCreate/chatCommand.ts +++ b/bots/discord/src/events/discord/interactionCreate/chatCommand.ts @@ -9,7 +9,8 @@ withContext(on, 'interactionCreate', async (context, interaction) => { const command = discord.commands[interaction.commandName] logger.debug(`Command ${interaction.commandName} being invoked by ${interaction.user.tag}`) - if (!command) return void logger.error(`Command ${interaction.commandName} not implemented but registered!!!`) + if (!command) + return void logger.error(`Interaction command ${interaction.commandName} not implemented but registered!!!`) try { logger.debug(`Command ${interaction.commandName} being executed`) diff --git a/bots/discord/src/events/discord/messageCreate/messageCommand.ts b/bots/discord/src/events/discord/messageCreate/messageCommand.ts index f1b680a..3b9440b 100644 --- a/bots/discord/src/events/discord/messageCreate/messageCommand.ts +++ b/bots/discord/src/events/discord/messageCreate/messageCommand.ts @@ -19,7 +19,7 @@ withContext(on, 'messageCreate', async (context, msg) => { const command = discord.commands[commandName] logger.debug(`Command ${commandName} being invoked by ${msg.author.id}`) - if (!command) return void logger.error(`Command ${commandName} not implemented`) + if (!command) return void logger.debug(`Message command ${commandName} not implemented`) const argsRegex: RegExp = /[^\s"]+|"([^"]*)"/g const args: CommandArguments = [] diff --git a/bots/discord/src/events/discord/messageCreate/scanMessage.ts b/bots/discord/src/events/discord/messageCreate/scanMessage.ts index 848253b..4fb83e0 100644 --- a/bots/discord/src/events/discord/messageCreate/scanMessage.ts +++ b/bots/discord/src/events/discord/messageCreate/scanMessage.ts @@ -33,7 +33,7 @@ withContext(on, 'messageCreate', async (context, msg) => { if (response) { logger.debug('Response found') - const toReply = replyToReplied ? await msg.fetchReference() : msg + const toReply = replyToReplied ? (msg.reference?.messageId ? await msg.fetchReference() : msg) : msg const reply = await toReply.reply({ ...response, embeds: response.embeds?.map(it => createMessageScanResponseEmbed(it, label ? 'nlp' : 'match')), diff --git a/bots/discord/src/index.ts b/bots/discord/src/index.ts index f7e77fd..2aaf35c 100644 --- a/bots/discord/src/index.ts +++ b/bots/discord/src/index.ts @@ -10,5 +10,10 @@ if (missingEnvs.length) { process.exit(1) } +// Handle uncaught exceptions + +process.on('uncaughtException', error => console.error('Uncaught exception:', error)) +process.on('unhandledRejection', reason => console.error('Unhandled rejection:', reason)) + api.client.connect() discord.client.login()