New blacklist format

akairo
supositware 3 years ago
parent 219ecfaab5
commit d835982972

@ -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;

@ -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 :)');
}

@ -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 => {

@ -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;
}

@ -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;

@ -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;

@ -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;
}
}
}

@ -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');
}
};

@ -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');
}
};

@ -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;
};

@ -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;
};
Loading…
Cancel
Save