This commit is contained in:
2024-12-27 01:23:35 +01:00
parent 7d349a37d4
commit c06ac10d09
18 changed files with 543 additions and 0 deletions

View File

@@ -0,0 +1,83 @@
import { Commands, type CommandsType } from "components/commands.component";
import type {
ButtonInteraction,
CacheType,
ChatInputCommandInteraction,
Interaction,
ModalSubmitInteraction,
} from "discord.js";
import client from "lib/client";
import EventEmitter from "node:events";
import DiscordService from "services/discord.service";
import { WaterMeService } from "services/water-me.service";
export default class DiscordController extends EventEmitter {
private discordService!: DiscordService;
waterMeService: WaterMeService;
constructor() {
super();
this.discordService = new DiscordService();
this.waterMeService = new WaterMeService();
// log when running
client.once("ready", () => {
console.log("Listening...");
});
// listen for interactions
client.on("interactionCreate", this.handleInteraction.bind(this));
}
async init() {
await this.discordService.init();
}
async handleInteraction(interaction: Interaction<CacheType>) {
if (interaction.isModalSubmit()) {
await this.handleModalSubmit(interaction);
return;
}
if (interaction.isChatInputCommand()) {
await this.handleChatInputCommand(interaction);
return;
}
if (interaction.isButton()) {
await this.handleButton(interaction);
return;
}
}
async handleButton(interaction: ButtonInteraction<CacheType>) {
const { customId } = interaction;
console.log(interaction.customId);
if (customId === "moreWater") {
await this.waterMeService.handleInteraction(interaction);
}
}
async handleChatInputCommand(
interaction: ChatInputCommandInteraction<CacheType>,
) {
const commandName = interaction.commandName as CommandsType;
// add commands
switch (commandName) {
case Commands.Enum["water-me"]:
await this.waterMeService.handleInteraction(interaction);
return;
default:
break;
}
}
// wenn neues fenster durch buttonclick or so
async handleModalSubmit(interaction: ModalSubmitInteraction<CacheType>) {
const { customId } = interaction;
switch (customId) {
default:
break;
}
}
}