From 7249e047903e9641cb0d5e423bf36f891b4fcac9 Mon Sep 17 00:00:00 2001 From: Miikka Virtanen Date: Fri, 30 Dec 2016 17:58:34 +0200 Subject: [PATCH] Allow direct usage of block, unblock, and logs from modmail threads (without specifying the id) --- index.js | 47 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 15 deletions(-) diff --git a/index.js b/index.js index 4e8df97..ab9d191 100644 --- a/index.js +++ b/index.js @@ -359,6 +359,7 @@ bot.on('messageCreate', msg => { // These messages get relayed back to the DM thread between the bot and the user // Attachments are shown as URLs bot.registerCommand('reply', (msg, args) => { + if (! (msg.channel instanceof Eris.GuildChannel)) return; if (msg.channel.guild.id !== modMailGuild.id) return; if (! msg.member.permission.has('manageRoles')) return; @@ -411,6 +412,7 @@ bot.registerCommand('reply', (msg, args) => { bot.registerCommandAlias('r', 'reply'); bot.registerCommand('close', (msg, args) => { + if (! (msg.channel instanceof Eris.GuildChannel)) return; if (msg.channel.guild.id !== modMailGuild.id) return; if (! msg.member.permission.has('manageRoles')) return; @@ -441,16 +443,21 @@ Logs: <${logurl}>`; }); bot.registerCommand('block', (msg, args) => { + if (! (msg.channel instanceof Eris.GuildChannel)) return; if (msg.channel.guild.id !== modMailGuild.id) return; if (! msg.member.permission.has('manageRoles')) return; - if (args.length !== 1) return; let userId; - if (args[0].match(/^[0-9]+$/)) { - userId = args[0]; + if (args[0]) { + if (args[0].match(/^[0-9]+$/)) { + userId = args[0]; + } else { + let mentionMatch = args[0].match(userMentionRegex); + if (mentionMatch) userId = mentionMatch[1]; + } } else { - let mentionMatch = args[0].match(userMentionRegex); - if (mentionMatch) userId = mentionMatch[1]; + const modmailChannelInfo = getModmailChannelInfo(msg.channel); + if (modmailChannelInfo) userId = modmailChannelInfo.userId; } if (! userId) return; @@ -461,16 +468,21 @@ bot.registerCommand('block', (msg, args) => { }); bot.registerCommand('unblock', (msg, args) => { + if (! (msg.channel instanceof Eris.GuildChannel)) return; if (msg.channel.guild.id !== modMailGuild.id) return; if (! msg.member.permission.has('manageRoles')) return; - if (args.length !== 1) return; let userId; - if (args[0].match(/^[0-9]+$/)) { - userId = args[0]; + if (args[0]) { + if (args[0].match(/^[0-9]+$/)) { + userId = args[0]; + } else { + let mentionMatch = args[0].match(userMentionRegex); + if (mentionMatch) userId = mentionMatch[1]; + } } else { - let mentionMatch = args[0].match(userMentionRegex); - if (mentionMatch) userId = mentionMatch[1]; + const modmailChannelInfo = getModmailChannelInfo(msg.channel); + if (modmailChannelInfo) userId = modmailChannelInfo.userId; } if (! userId) return; @@ -481,16 +493,21 @@ bot.registerCommand('unblock', (msg, args) => { }); bot.registerCommand('logs', (msg, args) => { + if (! (msg.channel instanceof Eris.GuildChannel)) return; if (msg.channel.guild.id !== modMailGuild.id) return; if (! msg.member.permission.has('manageRoles')) return; - if (args.length !== 1) return; let userId; - if (args[0].match(/^[0-9]+$/)) { - userId = args[0]; + if (args[0]) { + if (args[0].match(/^[0-9]+$/)) { + userId = args[0]; + } else { + let mentionMatch = args[0].match(userMentionRegex); + if (mentionMatch) userId = mentionMatch[1]; + } } else { - let mentionMatch = args[0].match(userMentionRegex); - if (mentionMatch) userId = mentionMatch[1]; + const modmailChannelInfo = getModmailChannelInfo(msg.channel); + if (modmailChannelInfo) userId = modmailChannelInfo.userId; } if (! userId) return;