Some checks failed
Auto Build and Push Docker Image / build (push) Failing after 15s
76 lines
3.3 KiB
TypeScript
76 lines
3.3 KiB
TypeScript
import { Events, Interaction } from 'discord.js';
|
|
import { ExtendedClient } from '../structures/ExtendedClient.js';
|
|
|
|
import { DB } from '../structures/Database.js';
|
|
|
|
export default {
|
|
name: Events.InteractionCreate,
|
|
async execute(interaction: Interaction, client: ExtendedClient) {
|
|
// --- SLASH COMMANDS & CONTEXT MENUS ---
|
|
if (interaction.isChatInputCommand() || interaction.isMessageContextMenuCommand()) {
|
|
const command = client.commands.get(interaction.commandName);
|
|
|
|
if (!command) {
|
|
console.error(`No command matching ${interaction.commandName} was found.`);
|
|
return;
|
|
}
|
|
|
|
try {
|
|
// Typ-Check für die Ausführung
|
|
if (interaction.isChatInputCommand()) {
|
|
await (command.execute as (interaction: ChatInputCommandInteraction, client: ExtendedClient) => Promise<void>)(interaction, client);
|
|
} else if (interaction.isMessageContextMenuCommand()) {
|
|
await (command.execute as (interaction: MessageContextMenuCommandInteraction, client: ExtendedClient) => Promise<void>)(interaction, client);
|
|
}
|
|
|
|
// Statistik nur für Slash-Commands (oder optional für beides)
|
|
if (interaction.isChatInputCommand()) {
|
|
DB.run(`
|
|
INSERT INTO command_stats (command_name, uses)
|
|
VALUES (?, 1)
|
|
ON CONFLICT(command_name) DO UPDATE SET uses = uses + 1
|
|
`, interaction.commandName);
|
|
}
|
|
|
|
// DM Nutzer registrieren
|
|
if (!interaction.guildId) {
|
|
DB.run(`
|
|
INSERT INTO dm_users (user_id, username, last_seen)
|
|
VALUES (?, ?, CURRENT_TIMESTAMP)
|
|
ON CONFLICT(user_id) DO UPDATE SET
|
|
username = excluded.username,
|
|
last_seen = CURRENT_TIMESTAMP
|
|
`, interaction.user.id, interaction.user.tag);
|
|
}
|
|
|
|
} catch (error) {
|
|
console.error(error);
|
|
const replyOptions = { content: 'There was an error while executing this command!', ephemeral: true };
|
|
if (interaction.replied || interaction.deferred) {
|
|
await interaction.followUp(replyOptions);
|
|
} else {
|
|
await interaction.reply(replyOptions);
|
|
}
|
|
}
|
|
return;
|
|
}
|
|
|
|
// --- MODAL SUBMISSIONS ---
|
|
if (interaction.isModalSubmit()) {
|
|
// Wir suchen das Kommando anhand des Modal-Custom-IDs (wir nutzen hier ein Präfix-System)
|
|
const [commandName] = interaction.customId.split('-');
|
|
const command = client.commands.get(commandName);
|
|
|
|
if (command && command.handleModal) {
|
|
try {
|
|
await command.handleModal(interaction, client);
|
|
} catch (error) {
|
|
console.error(error);
|
|
await interaction.reply({ content: 'Fehler beim Verarbeiten des Formulars.', ephemeral: true });
|
|
}
|
|
}
|
|
return;
|
|
}
|
|
},
|
|
};
|