From 2a966f93074c1da06edc3ab723182580c77cd6f4 Mon Sep 17 00:00:00 2001 From: loicbersier Date: Sat, 16 Jan 2021 09:00:59 +0100 Subject: [PATCH] blacklist added for ytp Signed-off-by: loicbersier --- commands/fun/ytp.js | 8 +++- commands/owner/YtpBlacklist.js | 65 ++++++++++++++++++++++++++++++ commands/owner/blacklist.js | 6 +-- commands/owner/twitterBlacklist.js | 6 +-- models/ytpblacklist.js | 11 +++++ 5 files changed, 89 insertions(+), 7 deletions(-) create mode 100644 commands/owner/YtpBlacklist.js create mode 100644 models/ytpblacklist.js diff --git a/commands/fun/ytp.js b/commands/fun/ytp.js index 73caacc..3f8c223 100644 --- a/commands/fun/ytp.js +++ b/commands/fun/ytp.js @@ -8,6 +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 MAX_CLIPS = 20; @@ -164,6 +165,12 @@ 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; if (!proxy[args.proxy]) args.proxy = 0; @@ -268,7 +275,6 @@ class ytpCommand extends Command { let channel = this.client.channels.resolve(ytpChannel); return channel.send(url, {embed: Embed}); - }); } else { loadingmsg.delete(); diff --git a/commands/owner/YtpBlacklist.js b/commands/owner/YtpBlacklist.js new file mode 100644 index 0000000..68dc572 --- /dev/null +++ b/commands/owner/YtpBlacklist.js @@ -0,0 +1,65 @@ +const { Command } = require('discord-akairo'); +const ytpblacklist = require('../../models').ytpblacklist; + +class ytpblacklistCommand extends Command { + constructor() { + super('ytpblacklist', { + aliases: ['YTPBlacklist', 'ytpblacklist', 'yblacklist'], + category: 'owner', + ownerOnly: 'true', + userPermissions: ['MANAGE_MESSAGES'], + args: [ + { + id: 'userID', + type: 'string', + prompt: { + start: 'Who do you want to blacklist?', + } + }, + { + id: 'reason', + match: 'rest', + type: 'string', + default: 'no reasons provided', + prompt: { + start: 'What should the reason be?', + optional: true, + } + } + ], + channel: 'guild', + description: { + content: 'Blacklist user from the YTP command', + usage: '[userID]', + examples: [''] + } + }); + } + + async exec(message, args) { + const blacklist = await ytpblacklist.findOne({where: {userID:args.userID}}); + + if (!blacklist) { + const body = {userID: args.userID, reason: args.reason}; + ytpblacklist.create(body); + return message.channel.send(`The user with the following id have been blacklisted from the YTP: ${args.userID}`); + } 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; + message.channel.awaitMessages(filter, {time: 5000 * 1000, max: 1, errors: ['time'] }) + .then(messages => { + let messageContent = messages.map(messages => messages.content); + if (messageContent[0] === 'y' || messageContent[0] === 'yes') { + ytpblacklist.destroy({where: {userID:args.userID}}); + return message.channel.send(`The user with the following id have been unblacklisted from the YTP: ${args.userID}`); + } + }) + .catch(err => { + console.error(err); + return message.channel.send('Took too long to answer. didin\'t unblacklist anyone.'); + }); + } + } +} + +module.exports = ytpblacklistCommand; \ No newline at end of file diff --git a/commands/owner/blacklist.js b/commands/owner/blacklist.js index 9fc0873..da4c76c 100644 --- a/commands/owner/blacklist.js +++ b/commands/owner/blacklist.js @@ -4,7 +4,7 @@ const userBlacklist = require('../../models').userBlacklist; class userBlacklistCommand extends Command { constructor() { super('userBlacklist', { - aliases: ['userblacklist'], + aliases: ['userblacklist', 'ublacklist'], category: 'owner', ownerOnly: 'true', userPermissions: ['MANAGE_MESSAGES'], @@ -32,7 +32,7 @@ class userBlacklistCommand extends Command { if (!blacklist) { const body = {userID: args.userID}; userBlacklist.create(body); - return message.channel.send(`The following ID have been blacklisted: ${args.userID}`); + return message.channel.send(`The following ID have been blacklisted globally: ${args.userID}`); } 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; @@ -43,7 +43,7 @@ class userBlacklistCommand extends Command { 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: ${args.userID}`); + return message.channel.send(`The following ID have been unblacklisted globally: ${args.userID}`); } }) .catch(err => { diff --git a/commands/owner/twitterBlacklist.js b/commands/owner/twitterBlacklist.js index 1a2d5a6..47e7f23 100644 --- a/commands/owner/twitterBlacklist.js +++ b/commands/owner/twitterBlacklist.js @@ -42,16 +42,16 @@ class TwitterBlacklistCommand extends Command { if (!blacklist) { const body = {userID: args.userID, reason: args.reason}; TwitterBlacklist.create(body); - return message.channel.send(`The user with the following id have been blacklisted: ${args.userID}`); + return message.channel.send(`The user with the following id have been blacklisted from the twitter command: ${args.userID}`); } 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; + const filter = m => m.content && m.author.id === message.author.id; message.channel.awaitMessages(filter, {time: 5000 * 1000, max: 1, errors: ['time'] }) .then(messages => { let messageContent = messages.map(messages => messages.content); if (messageContent[0] === 'y' || messageContent[0] === 'yes') { TwitterBlacklist.destroy({where: {userID:args.userID}}); - return message.channel.send(`The user with the following id have been unblacklisted: ${args.userID}`); + return message.channel.send(`The user with the following id have been unblacklisted from the twitter command: ${args.userID}`); } }) .catch(err => { diff --git a/models/ytpblacklist.js b/models/ytpblacklist.js new file mode 100644 index 0000000..921f359 --- /dev/null +++ b/models/ytpblacklist.js @@ -0,0 +1,11 @@ +'use strict'; +module.exports = (sequelize, DataTypes) => { + const ytpblacklist = sequelize.define('ytpblacklist', { + userID: DataTypes.BIGINT, + reason: DataTypes.STRING + }, {}); + ytpblacklist.associate = function(models) { + // associations can be defined here + }; + return ytpblacklist; +}; \ No newline at end of file