Allow direct usage of block, unblock, and logs from modmail threads (without specifying the id)

master
Miikka Virtanen 2016-12-30 17:58:34 +02:00
parent e12996f4b7
commit 7249e04790
1 changed files with 32 additions and 15 deletions

View File

@ -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;