forked from Supositware/Haha-Yes
banning word system
This commit is contained in:
parent
aeab4e1a11
commit
2e392da2f6
4 changed files with 114 additions and 1 deletions
50
commands/admin/banword.js
Normal file
50
commands/admin/banword.js
Normal file
|
@ -0,0 +1,50 @@
|
|||
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'],
|
||||
args: [
|
||||
{
|
||||
id: 'word',
|
||||
type: 'string',
|
||||
prompt: {
|
||||
start: 'What word should be banned',
|
||||
},
|
||||
match: 'rest'
|
||||
},
|
||||
{
|
||||
id: 'remove',
|
||||
match: 'flag',
|
||||
flag: '--remove'
|
||||
}
|
||||
],
|
||||
channelRestriction: 'guild',
|
||||
description: {
|
||||
content: 'Ban word on the server. --remove to delete a banned word',
|
||||
usage: '[word to ban]',
|
||||
examples: ['owo']
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async exec(message, args) {
|
||||
const bannedWords = await BannedWords.findOne({where: {word: args.word, serverID: message.guild.id}});
|
||||
|
||||
if (!bannedWords) {
|
||||
const body = {word: args.word, serverID: message.guild.id};
|
||||
await BannedWords.create(body);
|
||||
return message.channel.send(`The word ${args.word} have been banned`);
|
||||
} else if (args.remove && bannedWords) {
|
||||
BannedWords.destroy({where: {word: args.word, serverID: message.guild.id}});
|
||||
return message.channel.send(`The word ${args.word} is no longer banned`);
|
||||
} else {
|
||||
message.channel.send('This word is already banned');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = BannedWordsCommand;
|
|
@ -1,9 +1,11 @@
|
|||
const { Listener } = require('discord-akairo');
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
const rand = require('../../rand.js');
|
||||
const Sequelize = require('sequelize');
|
||||
const Tag = require('../../models').Tag;
|
||||
const autoResponse = require('../../models').autoresponse;
|
||||
const autoResponseStat = require('../../models').autoresponseStat;
|
||||
const BannedWords = require('../../models').bannedWords;
|
||||
|
||||
class messageListener extends Listener {
|
||||
constructor() {
|
||||
|
@ -15,8 +17,28 @@ class messageListener extends Listener {
|
|||
|
||||
async exec(message) {
|
||||
if (message.author.bot) return;
|
||||
const autoresponseStat = await autoResponseStat.findOne({where: {serverID: message.guild.id}});
|
||||
|
||||
|
||||
// Banned words
|
||||
|
||||
const bannedWords = await BannedWords.findAll({where: {word: Sequelize.where(Sequelize.fn('LOCATE', Sequelize.col('word'), message.content), Sequelize.Op.ne, 0), serverID: message.guild.id}});
|
||||
if (bannedWords[0].get('word')) {
|
||||
let censoredMessage = message.content;
|
||||
for (let i = 0; i < bannedWords.length; i++) {
|
||||
censoredMessage = censoredMessage.replace(bannedWords[i].get('word'), '█'.repeat(bannedWords[i].get('word').length));
|
||||
console.log(censoredMessage);
|
||||
}
|
||||
let Embed = new MessageEmbed()
|
||||
.setColor('#FF0000')
|
||||
.setAuthor(message.author.username, message.author.displayAvatarURL())
|
||||
.setDescription(censoredMessage);
|
||||
|
||||
message.channel.send(Embed);
|
||||
return message.delete();
|
||||
}
|
||||
|
||||
// auto responses
|
||||
const autoresponseStat = await autoResponseStat.findOne({where: {serverID: message.guild.id}});
|
||||
if (autoresponseStat) {
|
||||
// Infinit haha very yes
|
||||
if (message.content.toLowerCase().startsWith('haha very') && message.content.toLowerCase().endsWith('yes')) {
|
||||
|
|
30
migrations/20190821164402-create-banned-words.js
Normal file
30
migrations/20190821164402-create-banned-words.js
Normal file
|
@ -0,0 +1,30 @@
|
|||
'use strict';
|
||||
module.exports = {
|
||||
up: (queryInterface, Sequelize) => {
|
||||
return queryInterface.createTable('bannedWords', {
|
||||
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('bannedWords');
|
||||
}
|
||||
};
|
11
models/bannedwords.js
Normal file
11
models/bannedwords.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
'use strict';
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
const bannedWords = sequelize.define('bannedWords', {
|
||||
word: DataTypes.STRING,
|
||||
serverID: DataTypes.BIGINT
|
||||
}, {});
|
||||
bannedWords.associate = function(models) {
|
||||
// associations can be defined here
|
||||
};
|
||||
return bannedWords;
|
||||
};
|
Loading…
Reference in a new issue