From 1f48f6ad85d738f94e97332ed65694293b6ca071 Mon Sep 17 00:00:00 2001 From: Yuzu Date: Thu, 16 Sep 2021 23:55:32 -0700 Subject: [PATCH] Added command for Interaction --- src/discord/Interaction.ts | 54 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/discord/Interaction.ts diff --git a/src/discord/Interaction.ts b/src/discord/Interaction.ts new file mode 100644 index 0000000..071304b --- /dev/null +++ b/src/discord/Interaction.ts @@ -0,0 +1,54 @@ +import { Message } from "discord.js"; +import { makeInfoEmbed, makeErrorEmbed, makeSuccessEmbed, makeProcessingEmbed, sendMessage, sendReply } from "../utils/DiscordMessage"; +import DiscordProvider from "../providers/Discord"; +import {registerAllGuildsCommands, unregisterAllGuildsCommands} from "../utils/DiscordInteraction"; +import Prisma from "../providers/Prisma"; + +export default class Interaction { + async onCommand(command: string, args: any, message: Message) { + if(command.toLowerCase() !== 'interaction') return; + + if(!message.guildId) return; + if(message.member === null) return; + if(message.guild === null) return; + + // TODO: Add dev check + + if(args.length === 0) + return await sendReply(message, { + embeds: [makeInfoEmbed ({ + title: 'Interaction', + description: `Manage interaction`, + fields: [ + { + name: 'Available arguments', + value: '``reloadAll``' + } + ], + user: message.author + })] + }); + else { + if(args[0].toLowerCase() === "reloadall") { + try { + await unregisterAllGuildsCommands(); + await registerAllGuildsCommands(); + return await sendReply(message, { + embeds: [makeSuccessEmbed ({ + title: 'Reloaded all Interaction', + user: message.author + })] + }); + } catch (err) { + return await sendReply(message, { + embeds: [makeErrorEmbed ({ + title: 'An error occurred while trying to reload interaction', + description: '```' + err + '```', + user: message.author + })] + }); + } + } + } + } +} \ No newline at end of file