Haha-Yes/commands/admin/banword.js

61 lines
1.8 KiB
JavaScript
Raw Normal View History

2019-08-21 19:58:51 +02:00
const { Command } = require('discord-akairo');
const BannedWords = require('../../models').bannedWords;
class BannedWordsCommand extends Command {
constructor() {
super('BannedWords', {
aliases: ['bannedword', 'banword'],
category: 'admin',
userPermissions: ['MANAGE_MESSAGES'],
2019-11-09 12:04:01 +01:00
clientPermissions: ['MANAGE_MESSAGES', 'SEND_MESSAGES'],
2019-08-21 19:58:51 +02:00
args: [
{
id: 'word',
type: 'string',
match: 'rest'
},
{
id: 'remove',
match: 'flag',
flag: '--remove'
2020-01-30 12:02:27 +01:00
},
{
id: 'removeall',
match: 'flag',
flag: '--removeall'
2019-08-21 19:58:51 +02:00
}
],
channelRestriction: 'guild',
description: {
2020-01-30 12:02:27 +01:00
content: 'Ban word on the server. --remove to delete a banned word. --removeaall to remove every banned word',
2019-08-21 19:58:51 +02:00
usage: '[word to ban]',
examples: ['owo']
}
});
}
async exec(message, args) {
2020-01-30 12:02:27 +01:00
if (args.removeall) {
BannedWords.destroy({where: {serverID: message.guild.id}});
return message.channel.send('The banned word have been reset.');
}
if (!args.word) return message.channel.send('Please specify a word to ban!');
2019-08-24 12:03:21 +02:00
args.word = args.word.replace(/[\u0250-\ue007]/g, '');
2019-08-21 20:03:29 +02:00
const bannedWords = await BannedWords.findOne({where: {word: args.word.toLowerCase(), serverID: message.guild.id}});
2019-08-21 19:58:51 +02:00
if (!bannedWords) {
2019-08-21 20:03:29 +02:00
const body = {word: args.word.toLowerCase(), serverID: message.guild.id};
2019-08-21 19:58:51 +02:00
await BannedWords.create(body);
2019-08-21 20:03:29 +02:00
return message.channel.send(`The word ${args.word.toLowerCase()} have been banned`);
2019-08-21 19:58:51 +02:00
} else if (args.remove && bannedWords) {
2019-08-21 20:03:29 +02:00
BannedWords.destroy({where: {word: args.word.toLowerCase(), serverID: message.guild.id}});
return message.channel.send(`The word ${args.word.toLowerCase()} is no longer banned`);
2019-08-21 19:58:51 +02:00
} else {
message.channel.send('This word is already banned');
}
}
}
module.exports = BannedWordsCommand;