From 494440f28975cbc79cfd6aa60faccca0fdc5f17b Mon Sep 17 00:00:00 2001 From: loicbersier Date: Tue, 18 Feb 2020 18:59:38 +0100 Subject: [PATCH] unbanword alias --- commands/admin/banword.js | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/commands/admin/banword.js b/commands/admin/banword.js index 15aa9edb..aac1fece 100644 --- a/commands/admin/banword.js +++ b/commands/admin/banword.js @@ -4,7 +4,7 @@ const BannedWords = require('../../models').bannedWords; class BannedWordsCommand extends Command { constructor() { super('BannedWords', { - aliases: ['bannedword', 'banword'], + aliases: ['bannedword', 'banword', 'unbanword'], category: 'admin', userPermissions: ['MANAGE_MESSAGES'], clientPermissions: ['MANAGE_MESSAGES', 'SEND_MESSAGES'], @@ -27,7 +27,7 @@ class BannedWordsCommand extends Command { ], channelRestriction: 'guild', description: { - content: 'Ban word on the server. --remove to delete a banned word. --removeaall to remove every banned word', + content: 'Ban word on the server. use the unbanword alias to delete a banned word, unbanword alias and --removeaall to remove every banned word', usage: '[word to ban]', examples: ['owo'] } @@ -35,23 +35,30 @@ class BannedWordsCommand extends Command { } async exec(message, args) { - if (args.removeall) { - BannedWords.destroy({where: {serverID: message.guild.id}}); - return message.channel.send('The banned words have been reset.'); - } - - if (!args.word) return message.channel.send('Please specify a word to ban!'); - + if (!args.word) args.word = ''; args.word = args.word.replace(/[\u0250-\ue007]/g, ''); const bannedWords = await BannedWords.findOne({where: {word: args.word.toLowerCase(), serverID: message.guild.id}}); + if (message.util.parsed.alias == 'unbanword') { + if (args.removeall) { + BannedWords.destroy({where: {serverID: message.guild.id}}); + return message.channel.send('The banned words have been reset.'); + } + + if (bannedWords) { + BannedWords.destroy({where: {word: args.word.toLowerCase(), serverID: message.guild.id}}); + return message.channel.send(`The word ${args.word.toLowerCase()} is no longer banned`); + } else { + return message.channel.send('There was no word to unban'); + } + } + + if (!args.word) return message.channel.send('Please specify a word to ban!'); + if (!bannedWords) { const body = {word: args.word.toLowerCase(), serverID: message.guild.id}; await BannedWords.create(body); return message.channel.send(`The word ${args.word.toLowerCase()} has been banned`); - } else if (args.remove && bannedWords) { - BannedWords.destroy({where: {word: args.word.toLowerCase(), serverID: message.guild.id}}); - return message.channel.send(`The word ${args.word.toLowerCase()} is no longer banned`); } else { message.channel.send('This word is already banned'); }