diff --git a/commands/fun/ytp.js b/commands/fun/ytp.js index bd312d8..feecdad 100644 --- a/commands/fun/ytp.js +++ b/commands/fun/ytp.js @@ -8,7 +8,7 @@ const downloader = require('../../utils/download'); const md5File = require('md5-file'); const ytpHash = require('../../models').ytpHash; const { ytpChannel } = require('../../config.json'); -const ytpblacklist = require('../../models').ytpblacklist; +//const ytpblacklist = require('../../models').ytpblacklist; const MAX_CLIPS = 20; @@ -165,11 +165,13 @@ class ytpCommand extends Command { } if (args.add) { + /* const blacklist = await ytpblacklist.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 next time.`); } + */ if (args.proxy && !args.proxyAuto) { // args.proxyAuto is only provided when the command is run after a error 429 args.proxy = args.proxy -1; diff --git a/commands/general/tweet.js b/commands/general/tweet.js index a07c61c..db3b5f9 100644 --- a/commands/general/tweet.js +++ b/commands/general/tweet.js @@ -4,7 +4,8 @@ const fetch = require('node-fetch'); const os = require('os'); const fs = require('fs'); const rand = require('../../rand.js'); -const TwitterBlacklist = require('../../models').TwitterBlacklist; +//const TwitterBlacklist = require('../../models').TwitterBlacklist; +const Blacklists = require('../../models').Blacklists; const { twiConsumer, twiConsumerSecret, twiToken, twiTokenSecret, twiChannel } = require('../../config.json'); const wordToCensor = require('../../json/censor.json'); @@ -37,11 +38,13 @@ class tweetCommand extends Command { let date = new Date(); // 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 next time.`); } + */ // If account is less than 6 months old don't accept the tweet ( alt prevention ) if (message.author.createdAt > date.setMonth(date.getMonth() - 6)) { return message.channel.send('Your account is too new to be able to use this command!'); @@ -55,8 +58,12 @@ class tweetCommand extends Command { if (args.text) { // Detect banned word (Blacklist the user directly) if (wordToCensor.includes(args.text)) { - const body = {userID: message.author.id, reason: 'Automatic ban from banned word.'}; + const body = {type:'tweet', uid: message.author.id, reason: 'Automatic ban from banned word.'}; + Blacklists.create(body); + /* + const body = {userID: message.author.id, reason: }; TwitterBlacklist.create(body); + */ return message.channel.send('Sike, you just posted cringe! Enjoy the blacklist :)'); } diff --git a/commands/owner/YtpBlacklist.js b/commands/owner/YtpBlacklist similarity index 100% rename from commands/owner/YtpBlacklist.js rename to commands/owner/YtpBlacklist diff --git a/commands/owner/blacklist.js b/commands/owner/blacklist.js index da4c76c..6633412 100644 --- a/commands/owner/blacklist.js +++ b/commands/owner/blacklist.js @@ -1,5 +1,6 @@ const { Command } = require('discord-akairo'); const userBlacklist = require('../../models').userBlacklist; +const Blacklists = require('../../models').Blacklists; class userBlacklistCommand extends Command { constructor() { @@ -9,12 +10,25 @@ class userBlacklistCommand extends Command { ownerOnly: 'true', userPermissions: ['MANAGE_MESSAGES'], args: [ + { + id: 'command', + type: 'string', + prompt: { + start: 'Which command do you want to get a user blacklisted from?' + } + }, { id: 'userID', type: 'string', prompt: { start: 'Who do you want to blacklist?', } + }, + { + id: 'reason', + type: 'string', + match: 'rest', + default: 'No reason specified.' } ], channel: 'guild', @@ -27,12 +41,13 @@ class userBlacklistCommand extends Command { } async exec(message, args) { - const blacklist = await userBlacklist.findOne({where: {userID:args.userID}}); - + const blacklist = await Blacklists.findOne({where: {type:args.command, uid:message.author.id}}); + if (!blacklist) { - const body = {userID: args.userID}; - userBlacklist.create(body); - return message.channel.send(`The following ID have been blacklisted globally: ${args.userID}`); + const body = {type:args.command, uid: args.userID, reason: args.reason}; + Blacklists.create(body); + let user = this.client.users.resolve(args.userID); + return message.channel.send(`${user.tag} has been blacklisted from ${args.command} with the following reason ${args.reason}`); } else { message.channel.send('This user is already blacklisted, do you want to unblacklist him? y/n'); const filter = m => m.content && m.author.id === message.author.id; @@ -42,8 +57,8 @@ class userBlacklistCommand extends Command { let messageContent = messages.map(messages => messages.content); console.log(messageContent); if (messageContent[0] === 'y' || messageContent[0] === 'yes') { - userBlacklist.destroy({where: {userID:args.userID}}); - return message.channel.send(`The following ID have been unblacklisted globally: ${args.userID}`); + Blacklists.destroy({where: {type:args.command, uid:args.userID}}); + return message.channel.send(`The following ID have been unblacklisted from ${args.command}: ${args.userID}`); } }) .catch(err => { diff --git a/commands/owner/serverblacklist.js b/commands/owner/serverblacklist similarity index 100% rename from commands/owner/serverblacklist.js rename to commands/owner/serverblacklist diff --git a/commands/owner/twitterBlacklist.js b/commands/owner/twitterBlacklist similarity index 100% rename from commands/owner/twitterBlacklist.js rename to commands/owner/twitterBlacklist diff --git a/event/inhibitors/blacklist.js b/event/inhibitors/blacklist.js index a83f984..1d4fa1e 100644 --- a/event/inhibitors/blacklist.js +++ b/event/inhibitors/blacklist.js @@ -1,5 +1,5 @@ const { Inhibitor } = require('discord-akairo'); -const userBlacklist = require('../../models').userBlacklist; +const Blacklists = require('../../models').Blacklists; class BlacklistInhibitor extends Inhibitor { constructor() { @@ -9,9 +9,8 @@ class BlacklistInhibitor extends Inhibitor { } async exec(message) { - //const blacklist = ['501856229123948545', '497730155691638784', '29476879240658944', '530399670728392737', '595102888796356628', '342039250302140418', '319180626928336896', '476412819278004236']; - - const blacklist = await userBlacklist.findOne({where: {userID:message.author.id}}); + + const blacklist = await Blacklists.findOne({where: {type:'global', uid:message.author.id}}); if (blacklist) return true; } diff --git a/event/inhibitors/commandBlacklist.js b/event/inhibitors/commandBlacklist.js new file mode 100644 index 0000000..2c7143e --- /dev/null +++ b/event/inhibitors/commandBlacklist.js @@ -0,0 +1,18 @@ +const { Inhibitor } = require('discord-akairo'); +const Blacklists = require('../../models').Blacklists; + +class commandblacklistInhibitor extends Inhibitor { + constructor() { + super('commandblacklist', { + reason: 'commandblacklist' + }); + } + + async exec(message, command) { + const blacklist = await Blacklists.findOne({where: {type:command.id, uid:message.author.id}}); + + if (blacklist) return true; + } +} + +module.exports = commandblacklistInhibitor; \ No newline at end of file diff --git a/event/inhibitors/serverblacklist.js b/event/inhibitors/serverblacklist.js index 477bfe6..7ad8788 100644 --- a/event/inhibitors/serverblacklist.js +++ b/event/inhibitors/serverblacklist.js @@ -1,5 +1,5 @@ const { Inhibitor } = require('discord-akairo'); -const guildBlacklist = require('../../models').guildBlacklist; +const Blacklists = require('../../models').Blacklists; class serverblacklistInhibitor extends Inhibitor { constructor() { @@ -10,7 +10,8 @@ class serverblacklistInhibitor extends Inhibitor { async exec(message) { if (message.channel.type == 'dm') return; - const blacklist = await guildBlacklist.findOne({where: {guildID:message.guild.id}}); + + const blacklist = await Blacklists.findOne({where: {type:'guild', uid:message.guild.id}}); if (blacklist) return true; diff --git a/event/listeners/commandblocked.js b/event/listeners/commandblocked.js index 4153039..471eb00 100644 --- a/event/listeners/commandblocked.js +++ b/event/listeners/commandblocked.js @@ -1,4 +1,5 @@ const { Listener } = require('discord-akairo'); +const Blacklists = require('../../models').Blacklists; class CommandBlockedListener extends Listener { constructor() { @@ -9,6 +10,7 @@ class CommandBlockedListener extends Listener { } async exec(message, command, reason) { + const blacklist = await Blacklists.findOne({where: {type:command.id, uid:message.author.id}}); console.log(`${message.author.username} was blocked from using ${command.id} because of ${reason}!`); let ownerMessage; let blacklistMessage; @@ -47,6 +49,11 @@ class CommandBlockedListener extends Listener { Embed.setDescription('The admins of this server blocked this command.'); message.channel.send(Embed); break; + case 'commandblacklist': + Embed.setTitle('Command blocked.'); + Embed.setDescription(`You've been blocked from this command for the following reason: \`${blacklist.reason}\``); + message.channel.send(Embed); + break; } } } diff --git a/migrations/20210313154536-create-blacklists.js b/migrations/20210313154536-create-blacklists.js new file mode 100644 index 0000000..2c4282f --- /dev/null +++ b/migrations/20210313154536-create-blacklists.js @@ -0,0 +1,33 @@ +'use strict'; +module.exports = { + up: async (queryInterface, Sequelize) => { + await queryInterface.createTable('Blacklists', { + id: { + allowNull: false, + autoIncrement: true, + primaryKey: true, + type: Sequelize.INTEGER + }, + type: { + type: Sequelize.STRING + }, + uid: { + type: Sequelize.STRING + }, + reason: { + type: Sequelize.STRING + }, + createdAt: { + allowNull: false, + type: Sequelize.DATE + }, + updatedAt: { + allowNull: false, + type: Sequelize.DATE + } + }); + }, + down: async (queryInterface, Sequelize) => { + await queryInterface.dropTable('Blacklists'); + } +}; \ No newline at end of file diff --git a/migrations/20210313170727-create-commandblockuser.js b/migrations/20210313170727-create-commandblockuser.js new file mode 100644 index 0000000..da039e4 --- /dev/null +++ b/migrations/20210313170727-create-commandblockuser.js @@ -0,0 +1,33 @@ +'use strict'; +module.exports = { + up: async (queryInterface, Sequelize) => { + await queryInterface.createTable('commandblockusers', { + id: { + allowNull: false, + autoIncrement: true, + primaryKey: true, + type: Sequelize.INTEGER + }, + serverID: { + type: Sequelize.BIGINT + }, + userID: { + type: Sequelize.BIGINT + }, + command: { + type: Sequelize.STRING + }, + createdAt: { + allowNull: false, + type: Sequelize.DATE + }, + updatedAt: { + allowNull: false, + type: Sequelize.DATE + } + }); + }, + down: async (queryInterface, Sequelize) => { + await queryInterface.dropTable('commandblockusers'); + } +}; \ No newline at end of file diff --git a/models/blacklists.js b/models/blacklists.js new file mode 100644 index 0000000..b26ff8a --- /dev/null +++ b/models/blacklists.js @@ -0,0 +1,25 @@ +'use strict'; +const { + Model +} = require('sequelize'); +module.exports = (sequelize, DataTypes) => { + class Blacklists extends Model { + /** + * Helper method for defining associations. + * This method is not a part of Sequelize lifecycle. + * The `models/index` file will call this method automatically. + */ + static associate(models) { + // define association here + } + }; + Blacklists.init({ + type: DataTypes.STRING, + uid: DataTypes.STRING, + reason: DataTypes.STRING + }, { + sequelize, + modelName: 'Blacklists', + }); + return Blacklists; +}; \ No newline at end of file diff --git a/models/commandblockuser.js b/models/commandblockuser.js new file mode 100644 index 0000000..f600a79 --- /dev/null +++ b/models/commandblockuser.js @@ -0,0 +1,25 @@ +'use strict'; +const { + Model +} = require('sequelize'); +module.exports = (sequelize, DataTypes) => { + class commandblockuser extends Model { + /** + * Helper method for defining associations. + * This method is not a part of Sequelize lifecycle. + * The `models/index` file will call this method automatically. + */ + static associate(models) { + // define association here + } + }; + commandblockuser.init({ + serverID: DataTypes.BIGINT, + userID: DataTypes.BIGINT, + command: DataTypes.STRING + }, { + sequelize, + modelName: 'commandblockuser', + }); + return commandblockuser; +}; \ No newline at end of file