Enhance bot command handling with new leveling, economy, and utility features
- Integrated leveling and economy commands, including XP management and shop interactions. - Added context menu support for utility commands, improving user interaction options. - Updated command registration to include new commands and context menus, enhancing overall functionality. - Improved logging to track the registration of commands and context menus. - Refactored interaction handling to accommodate new command types and ensure smooth execution.
This commit is contained in:
@@ -1,4 +1,9 @@
|
||||
import { REST, Routes, type ChatInputCommandInteraction } from 'discord.js';
|
||||
import {
|
||||
REST,
|
||||
Routes,
|
||||
type ChatInputCommandInteraction,
|
||||
type MessageContextMenuCommandInteraction
|
||||
} from 'discord.js';
|
||||
import { t } from '@nexumi/shared';
|
||||
import { env } from './env.js';
|
||||
import { logger } from './logger.js';
|
||||
@@ -7,22 +12,37 @@ import { moderationCommands } from './modules/moderation/commands.js';
|
||||
import { automodCommands } from './modules/automod/commands.js';
|
||||
import { welcomeCommands } from './modules/welcome/commands.js';
|
||||
import { verificationCommands } from './modules/verification/commands.js';
|
||||
import { levelingCommands } from './modules/leveling/commands.js';
|
||||
import { economyCommands } from './modules/economy/commands.js';
|
||||
import { utilityCommands, utilityContextMenus } from './modules/utility/index.js';
|
||||
import { funCommands } from './modules/fun/index.js';
|
||||
import type { BotContext, SlashCommand } from './types.js';
|
||||
|
||||
const commands: SlashCommand[] = [
|
||||
...moderationCommands,
|
||||
...automodCommands,
|
||||
...welcomeCommands,
|
||||
...verificationCommands
|
||||
...verificationCommands,
|
||||
...levelingCommands,
|
||||
...economyCommands,
|
||||
...utilityCommands,
|
||||
...funCommands
|
||||
];
|
||||
const map = new Map(commands.map((c) => [c.data.name, c]));
|
||||
const contextMenuMap = new Map(utilityContextMenus.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())
|
||||
body: [
|
||||
...commands.map((c) => c.data.toJSON()),
|
||||
...utilityContextMenus.map((c) => c.data.toJSON())
|
||||
]
|
||||
});
|
||||
logger.info({ count: commands.length }, 'Registered application commands');
|
||||
logger.info(
|
||||
{ count: commands.length, contextMenus: utilityContextMenus.length },
|
||||
'Registered application commands'
|
||||
);
|
||||
}
|
||||
|
||||
export async function routeCommand(interaction: ChatInputCommandInteraction, context: BotContext) {
|
||||
@@ -34,3 +54,16 @@ export async function routeCommand(interaction: ChatInputCommandInteraction, con
|
||||
}
|
||||
await command.execute(interaction, context);
|
||||
}
|
||||
|
||||
export async function routeContextMenu(
|
||||
interaction: MessageContextMenuCommandInteraction,
|
||||
context: BotContext
|
||||
) {
|
||||
const command = contextMenuMap.get(interaction.commandName);
|
||||
const locale = await getGuildLocale(context.prisma, interaction.guildId);
|
||||
if (!command) {
|
||||
await interaction.reply({ content: t(locale, 'generic.unknownCommand'), ephemeral: true });
|
||||
return;
|
||||
}
|
||||
await command.execute(interaction, context);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user