feat: add trading system with dedicated modules and centralize embed creation for commands

This commit is contained in:
syntaxbullet
2025-12-13 12:43:27 +01:00
parent 5f4efd372f
commit 421bb26ceb
13 changed files with 667 additions and 41 deletions

View File

@@ -3,6 +3,7 @@ import { KyokoClient } from "@lib/KyokoClient";
import { env } from "@lib/env";
import { userService } from "@/modules/user/user.service";
import { levelingService } from "@/modules/leveling/leveling.service";
import { createErrorEmbed } from "@lib/embeds";
// Load commands
await KyokoClient.loadCommands();
@@ -25,6 +26,17 @@ KyokoClient.on(Events.MessageCreate, async message => {
// handle commands
KyokoClient.on(Events.InteractionCreate, async interaction => {
// Handle Trade Interactions
if (interaction.isButton() || interaction.isStringSelectMenu() || interaction.isModalSubmit()) {
if (interaction.customId.startsWith("trade_") || interaction.customId === "amount") { // "amount" is the text input id, usually interaction wrapper keeps customId of modal?
// Wait, ModalSubmitInteraction customId IS likely 'trade_money_modal'.
// The components INSIDE have IDs. The Interaction has the Modal ID.
// So checking startWith("trade_") is correct for the modal itself.
await import("@/modules/trade/trade.interaction").then(m => m.handleTradeInteraction(interaction));
return;
}
}
if (!interaction.isChatInputCommand()) return;
const command = KyokoClient.commands.get(interaction.commandName);
@@ -50,14 +62,16 @@ KyokoClient.on(Events.InteractionCreate, async interaction => {
await command.execute(interaction);
} catch (error) {
console.error(error);
const errorEmbed = createErrorEmbed('There was an error while executing this command!');
if (interaction.replied || interaction.deferred) {
await interaction.followUp({ content: 'There was an error while executing this command!', ephemeral: true });
await interaction.followUp({ embeds: [errorEmbed], ephemeral: true });
} else {
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
await interaction.reply({ embeds: [errorEmbed], ephemeral: true });
}
}
});
// login with the token from .env
if (!env.DISCORD_BOT_TOKEN) {
throw new Error("❌ DISCORD_BOT_TOKEN is not set in environment variables.");