forked from Supositware/Haha-Yes
Whitelist word
This commit is contained in:
parent
a878ea977c
commit
63c10d758c
4 changed files with 117 additions and 0 deletions
68
commands/admin/whitelistword.js
Normal file
68
commands/admin/whitelistword.js
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
const { Command } = require('discord-akairo');
|
||||||
|
const whitelistWord = require('../../models').whitelistWord;
|
||||||
|
|
||||||
|
class whitelistWordCommand extends Command {
|
||||||
|
constructor() {
|
||||||
|
super('whitelistWord', {
|
||||||
|
aliases: ['whitelistWord'],
|
||||||
|
category: 'admin',
|
||||||
|
userPermissions: ['MANAGE_MESSAGES'],
|
||||||
|
clientPermissions: ['MANAGE_MESSAGES', 'SEND_MESSAGES'],
|
||||||
|
args: [
|
||||||
|
{
|
||||||
|
id: 'word',
|
||||||
|
type: 'string',
|
||||||
|
match: 'rest'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'remove',
|
||||||
|
match: 'flag',
|
||||||
|
flag: '--remove'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'removeall',
|
||||||
|
match: 'flag',
|
||||||
|
flag: '--removeall'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
channelRestriction: 'guild',
|
||||||
|
description: {
|
||||||
|
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']
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async exec(message, args) {
|
||||||
|
if (!args.word) args.word = '';
|
||||||
|
args.word = args.word.replace(/[\u0250-\ue007]/g, '');
|
||||||
|
const WhitelistWord = await whitelistWord.findOne({where: {word: args.word.toLowerCase(), serverID: message.guild.id}});
|
||||||
|
|
||||||
|
if (message.util.parsed.alias == 'unbanword') {
|
||||||
|
if (args.removeall) {
|
||||||
|
whitelistWord.destroy({where: {serverID: message.guild.id}});
|
||||||
|
return message.channel.send('The whitelisted words has been reset.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (WhitelistWord) {
|
||||||
|
whitelistWord.destroy({where: {word: args.word.toLowerCase(), serverID: message.guild.id}});
|
||||||
|
return message.channel.send(`The word ${args.word.toLowerCase()} is no longer whitelisted`);
|
||||||
|
} else {
|
||||||
|
return message.channel.send('There was no word to whiteliste');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!args.word) return message.channel.send('Please specify a word to whiteliste!');
|
||||||
|
|
||||||
|
if (!WhitelistWord) {
|
||||||
|
const body = {word: args.word.toLowerCase(), serverID: message.guild.id};
|
||||||
|
await whitelistWord.create(body);
|
||||||
|
return message.channel.send(`The word ${args.word.toLowerCase()} has been whitelisted`);
|
||||||
|
} else {
|
||||||
|
message.channel.send('This word is already whitelisted');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = whitelistWordCommand;
|
|
@ -5,6 +5,7 @@ const Tag = require('../../models').Tag;
|
||||||
const autoResponse = require('../../models').autoresponse;
|
const autoResponse = require('../../models').autoresponse;
|
||||||
const autoResponseStat = require('../../models').autoresponseStat;
|
const autoResponseStat = require('../../models').autoresponseStat;
|
||||||
const BannedWords = require('../../models').bannedWords;
|
const BannedWords = require('../../models').bannedWords;
|
||||||
|
const WhitelistWord = require('../../models').whitelistWord;
|
||||||
|
|
||||||
class messageListener extends Listener {
|
class messageListener extends Listener {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
@ -27,6 +28,12 @@ class messageListener extends Listener {
|
||||||
|
|
||||||
// Banned words
|
// Banned words
|
||||||
const bannedWords = await BannedWords.findAll({where: {word: Sequelize.where(Sequelize.fn('LOCATE', Sequelize.col('word'), message.content.replace(/\u200B/g, '').replace(/[\u0250-\ue007]/g, '')), Sequelize.Op.ne, 0), serverID: message.guild.id}});
|
const bannedWords = await BannedWords.findAll({where: {word: Sequelize.where(Sequelize.fn('LOCATE', Sequelize.col('word'), message.content.replace(/\u200B/g, '').replace(/[\u0250-\ue007]/g, '')), Sequelize.Op.ne, 0), serverID: message.guild.id}});
|
||||||
|
const whitelistWord = await WhitelistWord.findAll({where: {word: Sequelize.where(Sequelize.fn('LOCATE', Sequelize.col('word'), message.content.replace(/\u200B/g, '').replace(/[\u0250-\ue007]/g, '')), Sequelize.Op.ne, 0), serverID: message.guild.id}});
|
||||||
|
|
||||||
|
if (whitelistWord[0]) {
|
||||||
|
return; // If word is whitelisted just return
|
||||||
|
}
|
||||||
|
|
||||||
if (bannedWords[0]) {
|
if (bannedWords[0]) {
|
||||||
// Remove accent
|
// Remove accent
|
||||||
let censoredMessage = message.content.toLowerCase().normalize('NFD').replace(/[\u0300-\u036f]/g, '');
|
let censoredMessage = message.content.toLowerCase().normalize('NFD').replace(/[\u0300-\u036f]/g, '');
|
||||||
|
@ -46,6 +53,7 @@ class messageListener extends Listener {
|
||||||
|
|
||||||
message.channel.send(Embed);
|
message.channel.send(Embed);
|
||||||
return message.delete({reason: `Deleted message: ${message.content}`});
|
return message.delete({reason: `Deleted message: ${message.content}`});
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// auto responses
|
// auto responses
|
||||||
const autoresponseStat = await autoResponseStat.findOne({where: {serverID: message.guild.id}});
|
const autoresponseStat = await autoResponseStat.findOne({where: {serverID: message.guild.id}});
|
||||||
|
|
30
migrations/20200224133009-create-whitelist-word.js
Normal file
30
migrations/20200224133009-create-whitelist-word.js
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
'use strict';
|
||||||
|
module.exports = {
|
||||||
|
up: (queryInterface, Sequelize) => {
|
||||||
|
return queryInterface.createTable('whitelistWords', {
|
||||||
|
id: {
|
||||||
|
allowNull: false,
|
||||||
|
autoIncrement: true,
|
||||||
|
primaryKey: true,
|
||||||
|
type: Sequelize.INTEGER
|
||||||
|
},
|
||||||
|
word: {
|
||||||
|
type: Sequelize.STRING
|
||||||
|
},
|
||||||
|
serverID: {
|
||||||
|
type: Sequelize.BIGINT
|
||||||
|
},
|
||||||
|
createdAt: {
|
||||||
|
allowNull: false,
|
||||||
|
type: Sequelize.DATE
|
||||||
|
},
|
||||||
|
updatedAt: {
|
||||||
|
allowNull: false,
|
||||||
|
type: Sequelize.DATE
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
down: (queryInterface, Sequelize) => {
|
||||||
|
return queryInterface.dropTable('whitelistWords');
|
||||||
|
}
|
||||||
|
};
|
11
models/whitelistword.js
Normal file
11
models/whitelistword.js
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
'use strict';
|
||||||
|
module.exports = (sequelize, DataTypes) => {
|
||||||
|
const whitelistWord = sequelize.define('whitelistWord', {
|
||||||
|
word: DataTypes.STRING,
|
||||||
|
serverID: DataTypes.BIGINT
|
||||||
|
}, {});
|
||||||
|
whitelistWord.associate = function(models) {
|
||||||
|
// associations can be defined here
|
||||||
|
};
|
||||||
|
return whitelistWord;
|
||||||
|
};
|
Loading…
Reference in a new issue