From 6fb370147e58aab104656a359743088e8ef49dbb Mon Sep 17 00:00:00 2001 From: Marius Begby Date: Thu, 7 Sep 2023 11:58:57 +0200 Subject: [PATCH] small changes --- src/interactions/autocomplete/lyrics.ts | 1 - src/interactions/commands/system/shards.ts | 3 +-- src/utils/deploySlashCommands.ts | 25 +++++++++++----------- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/interactions/autocomplete/lyrics.ts b/src/interactions/autocomplete/lyrics.ts index f9b974d..d09866d 100644 --- a/src/interactions/autocomplete/lyrics.ts +++ b/src/interactions/autocomplete/lyrics.ts @@ -31,7 +31,6 @@ class LyricsAutocomplete extends BaseAutocompleteInteraction { const genius = lyricsExtractor(); const lyricsResult: LyricsData = (await genius.search(query).catch(() => null)) as LyricsData; - // TODO: Update TS Type for lyricsResult and create response object type let response: ApplicationCommandOptionChoiceData[] = []; if (!lyricsResult) { diff --git a/src/interactions/commands/system/shards.ts b/src/interactions/commands/system/shards.ts index 84b0d7e..739fd94 100644 --- a/src/interactions/commands/system/shards.ts +++ b/src/interactions/commands/system/shards.ts @@ -49,8 +49,7 @@ class ShardsCommand extends BaseSlashCommandInteraction { (process.memoryUsage().heapUsed / 1024 / 1024).toFixed(2) ); - // TODO: Create shardInfo type - const shardInfo = { + const shardInfo: ShardInfo = { shardId: shardClient.shard!.ids[0], memUsage: nodeProcessMemUsageInMb, guildCount: shardClient.guilds.cache.size, diff --git a/src/utils/deploySlashCommands.ts b/src/utils/deploySlashCommands.ts index 77f1d69..9090f5b 100644 --- a/src/utils/deploySlashCommands.ts +++ b/src/utils/deploySlashCommands.ts @@ -5,6 +5,7 @@ import { randomUUID as uuidv4 } from 'node:crypto'; import fs from 'node:fs'; import path from 'node:path'; import { Logger } from 'pino'; +import { BaseSlashCommandInteraction } from '../classes/interactions'; import loggerModule from '../services/logger'; import { SystemOptions } from '../types/configTypes'; @@ -17,10 +18,8 @@ const logger: Logger = loggerModule.child({ executionId: executionId }); -//TODO: Fix deploying not working with require() - -const slashCommands: RESTPostAPIChatInputApplicationCommandsJSONBody[] = []; -const systemCommands: RESTPostAPIChatInputApplicationCommandsJSONBody[] = []; +const userSlashCommands: RESTPostAPIChatInputApplicationCommandsJSONBody[] = []; +const systemSlashCommands: RESTPostAPIChatInputApplicationCommandsJSONBody[] = []; const commandFolders: string[] = fs.readdirSync(path.resolve('./dist/interactions/commands')); if (!process.env.DISCORD_BOT_TOKEN) { @@ -47,19 +46,21 @@ const rest: REST = new REST({ version: '10' }).setToken(process.env.DISCORD_BOT_ .filter((file) => file.endsWith('.js')); for (const file of commandFiles) { - // TODO: create commandModule type const { default: command } = await import(`../interactions/commands/${folder}/${file}`); - command.isSystemCommand - ? systemCommands.push(command.data.toJSON()) - : slashCommands.push(command.data.toJSON()); + const slashCommand = command as BaseSlashCommandInteraction; + slashCommand.isSystemCommand + ? systemSlashCommands.push(slashCommand.data.toJSON()) + : userSlashCommands.push(slashCommand.data.toJSON()); } } try { - logger.debug(`Bot user slash commands found: ${slashCommands.map((command) => `/${command.name}`).join(', ')}`); + logger.debug( + `Bot user slash commands found: ${userSlashCommands.map((command) => `/${command.name}`).join(', ')}` + ); logger.info('Started refreshing user slash commands.'); - await refreshCommands(Routes.applicationCommands(process.env.DISCORD_APPLICATION_ID!), slashCommands); + await refreshCommands(Routes.applicationCommands(process.env.DISCORD_APPLICATION_ID!), userSlashCommands); logger.info('Successfully refreshed user slash commands.'); } catch (error) { logger.error(error, 'Failed to refresh user slash commands.'); @@ -67,7 +68,7 @@ const rest: REST = new REST({ version: '10' }).setToken(process.env.DISCORD_BOT_ try { logger.debug( - `Bot system slash commands found: ${systemCommands + `Bot system slash commands found: ${systemSlashCommands .map((systemCommand) => `/${systemCommand.name}`) .join(', ')}` ); @@ -79,7 +80,7 @@ const rest: REST = new REST({ version: '10' }).setToken(process.env.DISCORD_BOT_ logger.debug(`Refreshing system slash command for guild id '${systemGuildId}'.`); refreshCommands( Routes.applicationGuildCommands(process.env.DISCORD_APPLICATION_ID!, systemGuildId), - systemCommands + systemSlashCommands ); }) );