feature/5-drop-command (#17)

#5

Reviewed-on: https://gitea.vylpes.xyz/External/card-drop/pulls/17
Co-authored-by: Ethan Lane <ethan@vylpes.com>
Co-committed-by: Ethan Lane <ethan@vylpes.com>
This commit is contained in:
Ethan Lane 2023-09-03 20:27:29 +01:00 committed by Vylpes
parent 51d97bacd5
commit 58d1541e47
21 changed files with 382 additions and 48 deletions

View file

@ -1,29 +1,18 @@
import { Interaction } from "discord.js";
import ICommandItem from "../contracts/ICommandItem";
import { CoreClient } from "./client";
import ChatInputCommand from "./interactionCreate/ChatInputCommand";
import Button from "./interactionCreate/Button";
export class Events {
public async onInteractionCreate(interaction: Interaction) {
if (!interaction.isChatInputCommand()) return;
if (!interaction.guildId) return;
const item = CoreClient.commandItems.find(x => x.Name == interaction.commandName && !x.ServerId);
const itemForServer = CoreClient.commandItems.find(x => x.Name == interaction.commandName && x.ServerId == interaction.guildId);
let itemToUse: ICommandItem;
if (!itemForServer) {
if (!item) {
await interaction.reply('Command not found');
return;
}
itemToUse = item;
} else {
itemToUse = itemForServer;
if (interaction.isChatInputCommand()) {
ChatInputCommand.onChatInput(interaction);
}
itemToUse.Command.execute(interaction);
if (interaction.isButton()) {
Button.onButtonClicked(interaction);
}
}
// Emit when bot is logged in and ready to use