From 9324ab5da99bfc5b931c964a3e1a7292adc9ef26 Mon Sep 17 00:00:00 2001 From: utarwyn Date: Thu, 28 Jul 2022 01:43:51 +0200 Subject: [PATCH] GH-292: check bot mention to use deploy commands --- src/bot/command/AppCommandRegister.ts | 29 ++++++++++++++++++--------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/bot/command/AppCommandRegister.ts b/src/bot/command/AppCommandRegister.ts index 389b054c..3d7f15b5 100644 --- a/src/bot/command/AppCommandRegister.ts +++ b/src/bot/command/AppCommandRegister.ts @@ -44,16 +44,25 @@ export default class AppCommandRegister { * @param message discord.js message object */ public async handleDeployMessage(message: Message): Promise { - if (message.guild && message.member && message.member.permissions.has('ADMINISTRATOR')) { - if (message.content === '?tttdeploy') { - await this.registerInGuild(message.guild.id); - await message.reply(`Command /${this.name} has been registered.`); - } else if (message.content === '?tttdelete') { - const executed = await this.deleteInGuild(message.guild.id); - if (executed) { - await message.reply(`Command /${this.name} has been unregistered.`); - } else { - await message.reply(`Command /${this.name} not found.`); + if ( + message.guild && + message.member && + message.client.user && + message.mentions.has(message.client.user) && + message.member.permissions.has('ADMINISTRATOR') + ) { + const words = message.content.split(' '); + if (words.length === 2) { + if (words.includes('tttdeploy')) { + await this.registerInGuild(message.guild.id); + await message.reply(`Command /${this.name} has been registered.`); + } else if (words.includes('tttdelete')) { + const executed = await this.deleteInGuild(message.guild.id); + if (executed) { + await message.reply(`Command /${this.name} has been unregistered.`); + } else { + await message.reply(`Command /${this.name} not found.`); + } } } }