Update ESLint rules, enhance environment schema with new metrics and health port, and refactor Redis import. Change TypeScript definitions path in package.json.
This commit is contained in:
25
apps/bot/src/commands.ts
Normal file
25
apps/bot/src/commands.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { REST, Routes, type ChatInputCommandInteraction } from 'discord.js';
|
||||
import { env } from './env.js';
|
||||
import { logger } from './logger.js';
|
||||
import { moderationCommands } from './modules/moderation/commands.js';
|
||||
import type { BotContext, SlashCommand } from './types.js';
|
||||
|
||||
const commands: SlashCommand[] = [...moderationCommands];
|
||||
const map = new Map(commands.map((c) => [c.data.name, c]));
|
||||
|
||||
export async function registerCommands() {
|
||||
const rest = new REST({ version: '10' }).setToken(env.BOT_TOKEN);
|
||||
await rest.put(Routes.applicationCommands(env.BOT_CLIENT_ID), {
|
||||
body: commands.map((c) => c.data.toJSON())
|
||||
});
|
||||
logger.info({ count: commands.length }, 'Registered application commands');
|
||||
}
|
||||
|
||||
export async function routeCommand(interaction: ChatInputCommandInteraction, context: BotContext) {
|
||||
const command = map.get(interaction.commandName);
|
||||
if (!command) {
|
||||
await interaction.reply({ content: 'Unknown command.', ephemeral: true });
|
||||
return;
|
||||
}
|
||||
await command.execute(interaction, context);
|
||||
}
|
||||
Reference in New Issue
Block a user