From b896029fc59585690a06bbb86308224dbb6a8fa0 Mon Sep 17 00:00:00 2001 From: konhi Date: Sat, 30 Oct 2021 00:53:35 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20Bot=20nie=20od=C5=9Bwie=C5=BCa=20szcz?= =?UTF-8?q?=C4=99=C5=9Bliwego=20numerka=20#2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/commands.ts | 45 ++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/src/core/commands.ts b/src/core/commands.ts index dc95372..e6118b1 100644 --- a/src/core/commands.ts +++ b/src/core/commands.ts @@ -28,26 +28,29 @@ const slashCommands: Discord.ChatInputApplicationCommandData[] = [ } ] -const replies: {[commandName: string]: Discord.InteractionReplyOptions} = { - github: { - content: 'https://github.com/ElektronPlus/discord', - ephemeral: true - }, - numerek: { - content: await getLuckyNumberInfo(), - ephemeral: true - }, - aplikacja: { - content: 'https://play.google.com/store/apps/details?id=pl.krystian_wybranowski.elektronPlus', - ephemeral: true - }, - spolecznosciowy: { - content: 'https://discord.gg/jrDxSTE', - ephemeral: true - }, - facebook: { - content: 'https://www.facebook.com/zgelektronik/ & https://www.facebook.com/suelektron/', - ephemeral: true +/** Use function instead of object to allow dynamic content, like lucky number */ +async function getReplies (): Promise<{ [commandName: string]: Discord.InteractionReplyOptions} > { + return { + github: { + content: 'https://github.com/ElektronPlus/discord', + ephemeral: true + }, + numerek: { + content: await getLuckyNumberInfo(), + ephemeral: true + }, + aplikacja: { + content: 'https://play.google.com/store/apps/details?id=pl.krystian_wybranowski.elektronPlus', + ephemeral: true + }, + spolecznosciowy: { + content: 'https://discord.gg/jrDxSTE', + ephemeral: true + }, + facebook: { + content: 'https://www.facebook.com/zgelektronik/ & https://www.facebook.com/suelektron/', + ephemeral: true + } } } @@ -74,6 +77,8 @@ export async function replyToSlashCommand (interaction: Discord.Interaction): Pr } for (const command of slashCommands) { + const replies = await getReplies() + if (interaction.commandName === command.name) { interaction.reply(replies[command.name]) log.info(`[${interaction.guild?.name}] Replied to interaction (${interaction.commandName}).`)