From c6068c924c21299f95e3f5950abff10b39a656c7 Mon Sep 17 00:00:00 2001 From: loicbersier Date: Sun, 6 Oct 2019 20:29:42 +0200 Subject: [PATCH] put the blacklist in mysql --- commands/general/tweet.js | 15 +++++----- event/inhibitors/blacklist.js | 8 +++-- event/inhibitors/serverblacklist.js | 7 +++-- ...20191006180114-create-twitter-blacklist.js | 30 +++++++++++++++++++ .../20191006181945-create-guild-blacklist.js | 27 +++++++++++++++++ .../20191006181953-create-user-blacklist.js | 27 +++++++++++++++++ models/guildblacklist.js | 10 +++++++ models/twitterblacklist.js | 11 +++++++ models/userblacklist.js | 10 +++++++ 9 files changed, 134 insertions(+), 11 deletions(-) create mode 100644 migrations/20191006180114-create-twitter-blacklist.js create mode 100644 migrations/20191006181945-create-guild-blacklist.js create mode 100644 migrations/20191006181953-create-user-blacklist.js create mode 100644 models/guildblacklist.js create mode 100644 models/twitterblacklist.js create mode 100644 models/userblacklist.js diff --git a/commands/general/tweet.js b/commands/general/tweet.js index 9e569147..dfe4d738 100644 --- a/commands/general/tweet.js +++ b/commands/general/tweet.js @@ -4,8 +4,8 @@ const rand = require('../../rand.js'); const { MessageEmbed } = require('discord.js'); //const Filter = require('bad-words'); //let filter = new Filter(); +const TwitterBlacklist = require('../../models').TwitterBlacklist; const { twiConsumer, twiConsumerSecret, twiToken, twiTokenSecret, twiChannel } = require('../../config.json'); -const reload = require('auto-reload'); class tweetCommand extends Command { constructor() { @@ -32,24 +32,25 @@ class tweetCommand extends Command { async exec(message, args) { /* + // Censor words let censor = reload('../../json/censor.json'); let uncensor = reload('../../json/uncensor.json'); filter.addWords(...censor); filter.removeWords(...uncensor); */ + // see if user is not banned + const blacklist = await TwitterBlacklist.findOne({where: {userID:message.author.id}}); + if (blacklist) { + return message.channel.send(`You have been blacklisted for the following reasons: \`\`${blacklist.get('reason')}\`\` be less naughty less time.`); + } + // Don't let account new account use this command to prevent spam let date = new Date(); if (message.author.createdAt > date.setDate(date.getDate() - 7)) { return message.channel.send('Your account is too new to be able to use this command!'); } - const blacklist = reload('../../json/twiBlacklist.json'); - - if (blacklist.includes(message.author.id)) { - return message.channel.send('You have been blacklisted from this command... be less naughty next time.'); - } - // remove zero width space let text = args.text.replace('​', ''); if (!text) diff --git a/event/inhibitors/blacklist.js b/event/inhibitors/blacklist.js index 803487f7..a83f9841 100644 --- a/event/inhibitors/blacklist.js +++ b/event/inhibitors/blacklist.js @@ -1,4 +1,5 @@ const { Inhibitor } = require('discord-akairo'); +const userBlacklist = require('../../models').userBlacklist; class BlacklistInhibitor extends Inhibitor { constructor() { @@ -8,8 +9,11 @@ class BlacklistInhibitor extends Inhibitor { } async exec(message) { - const blacklist = ['501856229123948545', '497730155691638784', '29476879240658944', '530399670728392737', '595102888796356628', '342039250302140418', '319180626928336896', '476412819278004236']; - return blacklist.includes(message.author.id); + //const blacklist = ['501856229123948545', '497730155691638784', '29476879240658944', '530399670728392737', '595102888796356628', '342039250302140418', '319180626928336896', '476412819278004236']; + + const blacklist = await userBlacklist.findOne({where: {userID:message.author.id}}); + + if (blacklist) return true; } } diff --git a/event/inhibitors/serverblacklist.js b/event/inhibitors/serverblacklist.js index 8a8a58d2..e71d5d9a 100644 --- a/event/inhibitors/serverblacklist.js +++ b/event/inhibitors/serverblacklist.js @@ -1,4 +1,5 @@ const { Inhibitor } = require('discord-akairo'); +const guildBlacklist = require('../../models').guildBlacklist; class serverblacklistInhibitor extends Inhibitor { constructor() { @@ -8,8 +9,10 @@ class serverblacklistInhibitor extends Inhibitor { } async exec(message) { - const blacklist = ['595100178915262464', '630127127450091521', '630128971576770580']; - return blacklist.includes(message.guild.id); + const blacklist = await guildBlacklist.findOne({where: {guildID:message.guild.id}}); + + if (blacklist) return true; + } } diff --git a/migrations/20191006180114-create-twitter-blacklist.js b/migrations/20191006180114-create-twitter-blacklist.js new file mode 100644 index 00000000..72289cb6 --- /dev/null +++ b/migrations/20191006180114-create-twitter-blacklist.js @@ -0,0 +1,30 @@ +'use strict'; +module.exports = { + up: (queryInterface, Sequelize) => { + return queryInterface.createTable('TwitterBlacklists', { + id: { + allowNull: false, + autoIncrement: true, + primaryKey: true, + type: Sequelize.INTEGER + }, + userID: { + type: Sequelize.BIGINT + }, + reason: { + type: Sequelize.STRING + }, + createdAt: { + allowNull: false, + type: Sequelize.DATE + }, + updatedAt: { + allowNull: false, + type: Sequelize.DATE + } + }); + }, + down: (queryInterface, Sequelize) => { + return queryInterface.dropTable('TwitterBlacklists'); + } +}; \ No newline at end of file diff --git a/migrations/20191006181945-create-guild-blacklist.js b/migrations/20191006181945-create-guild-blacklist.js new file mode 100644 index 00000000..d50830be --- /dev/null +++ b/migrations/20191006181945-create-guild-blacklist.js @@ -0,0 +1,27 @@ +'use strict'; +module.exports = { + up: (queryInterface, Sequelize) => { + return queryInterface.createTable('guildBlacklists', { + id: { + allowNull: false, + autoIncrement: true, + primaryKey: true, + type: Sequelize.INTEGER + }, + guildID: { + type: Sequelize.BIGINT + }, + createdAt: { + allowNull: false, + type: Sequelize.DATE + }, + updatedAt: { + allowNull: false, + type: Sequelize.DATE + } + }); + }, + down: (queryInterface, Sequelize) => { + return queryInterface.dropTable('guildBlacklists'); + } +}; \ No newline at end of file diff --git a/migrations/20191006181953-create-user-blacklist.js b/migrations/20191006181953-create-user-blacklist.js new file mode 100644 index 00000000..5089d1b6 --- /dev/null +++ b/migrations/20191006181953-create-user-blacklist.js @@ -0,0 +1,27 @@ +'use strict'; +module.exports = { + up: (queryInterface, Sequelize) => { + return queryInterface.createTable('userBlacklists', { + id: { + allowNull: false, + autoIncrement: true, + primaryKey: true, + type: Sequelize.INTEGER + }, + userID: { + type: Sequelize.BIGINT + }, + createdAt: { + allowNull: false, + type: Sequelize.DATE + }, + updatedAt: { + allowNull: false, + type: Sequelize.DATE + } + }); + }, + down: (queryInterface, Sequelize) => { + return queryInterface.dropTable('userBlacklists'); + } +}; \ No newline at end of file diff --git a/models/guildblacklist.js b/models/guildblacklist.js new file mode 100644 index 00000000..3f79b436 --- /dev/null +++ b/models/guildblacklist.js @@ -0,0 +1,10 @@ +'use strict'; +module.exports = (sequelize, DataTypes) => { + const guildBlacklist = sequelize.define('guildBlacklist', { + guildID: DataTypes.BIGINT + }, {}); + guildBlacklist.associate = function(models) { + // associations can be defined here + }; + return guildBlacklist; +}; \ No newline at end of file diff --git a/models/twitterblacklist.js b/models/twitterblacklist.js new file mode 100644 index 00000000..105aeb5a --- /dev/null +++ b/models/twitterblacklist.js @@ -0,0 +1,11 @@ +'use strict'; +module.exports = (sequelize, DataTypes) => { + const TwitterBlacklist = sequelize.define('TwitterBlacklist', { + userID: DataTypes.BIGINT, + reason: DataTypes.STRING + }, {}); + TwitterBlacklist.associate = function(models) { + // associations can be defined here + }; + return TwitterBlacklist; +}; \ No newline at end of file diff --git a/models/userblacklist.js b/models/userblacklist.js new file mode 100644 index 00000000..6255d9ee --- /dev/null +++ b/models/userblacklist.js @@ -0,0 +1,10 @@ +'use strict'; +module.exports = (sequelize, DataTypes) => { + const userBlacklist = sequelize.define('userBlacklist', { + userID: DataTypes.BIGINT + }, {}); + userBlacklist.associate = function(models) { + // associations can be defined here + }; + return userBlacklist; +}; \ No newline at end of file