From bc888b9c111d42c5bfdb599cdd44727847fd8bee Mon Sep 17 00:00:00 2001 From: Kieran Date: Fri, 20 Nov 2020 21:42:12 +0000 Subject: [PATCH] some shit is done yes --- commands/blacklist.js | 88 +++++++++++++++++++++++++++++++++++++++++++ models/guild.js | 3 +- package-lock.json | 6 +-- 3 files changed, 93 insertions(+), 4 deletions(-) create mode 100644 commands/blacklist.js diff --git a/commands/blacklist.js b/commands/blacklist.js new file mode 100644 index 0000000..265ed32 --- /dev/null +++ b/commands/blacklist.js @@ -0,0 +1,88 @@ +const Discord = require('discord.js'); +const UserData = require('../models/user'); +const GuildData = require('../models/guild') + +module.exports = { + name: "blacklist", + aliases: ['bl'], + help: "Disables a user from using Natsuki ( Usage: {{p}}blacklist )", + async execute(message, msg, args, cmd, prefix, mention, client) { + + let tu = await UserData.findOne({ uid: message.author.id }); + + if (['g', 'guild'].includes(args[0].toLowerCase())) { + if(!tu || !tu.admin) { return message.channel.send('Sorry... you have to be a Natsuki Admin to do this!');} + + let guild = !args[1].match(/\d+/) ? message.guild ? message.guild : null : client.guilds.cache.has(args[1]) ? client.guilds.cache.get(args[1]) : null; + if (!guild) {return message.channel.send("You must provide a guild ID or be in a guild that you wish to blacklist!");} + + let tg = await GuildData.findOne({gid: guild.id}) || new GuildData({gid: guild.id}); + + if (args[1].match(/\d+/)) {args.shift();} + if (!args[1]) {return message.channel.send("You must specify whether to `add` or `del` a guild's blacklist!");} + + let tu = await UserData.findOne({uid: message.author.id}); + if (!tu || !tu.admin) {return message.reply("You must be a Natsuki Admin to blacklist!");} + if (message.guild.id === "762707532417335296") {return message.reply("You can't blacklist my support server!");} + + if (['a', 'add'].includes(args[1].toLowerCase())) { + if (tg.blacklisted) {return message.reply("That guild is already blacklisted!");} + tg.blacklisted = true; + tg.save(); + return message.channel.send("Gotcha! This server will not be able to use my commands!"); + } + + if (['r', 'rem', 'remove', 'd', 'del', 'delete'].includes(args[1].toLowerCase())) { + if (tg.blacklisted) {return message.reply("That guild isn't blacklisted in the first place!");} + tg.blacklisted = false; + tg.save(); + return message.channel.send("I have graced your merciful request; this server can once again make use of my wonderous abilities!"); + } + + return message.channel.send("Valid args: `[guildID] `"); + + } + + if (['u', 'user'].includes(args[0].toLowerCase())) { + + args.shift(); + + if (!args[1]) {return message.channel.send("You must specify whether to `add` or `del` a user's blacklist!");} + + function checkPerms(tu, bu) { + if (!tu.developer && bu.support) {message.channel.send("You can't blacklist any member of staff unless you're a developer!"); return null;} + if (!tu.admin) {message.channel.send("You must be at least admin to do that!"); return null;} + if (bu.developer) {message.channel.send("Developers cannot be blacklisted!"); return null;} + } + + if(['a', 'add'].includes(args[1].toLowerCase())) { + let blacklistUser = args[0].match(/^<@(?:!?)(?:\d+)>$/) && mention && client.users.cache.has(mention.id) ? mention.id : client.users.cache.has(args[0]) ? client.users.cache.get(args[0]).id : null; + if (!blacklistUser) {return message.reply("You must specify a user to blacklist!");} + let usersData = await UserData.findOne( { uid: blacklistUser } ) || new UserData({uid: blacklistUser}); + + if (!checkPerms(tu, usersData);) {return;} + + if (usersData.blacklisted === true) {return message.reply('they\'re already blacklisted :eyes:');} + + await UserData.findOneAndUpdate({ uid: blacklistUser }, { blacklisted: true }.catch(() => {})); + return message.channel.send(`Another one bites the dust! **${blacklistUser.user.tag}** has been blacklisted!`) + } + + if(['r', 'rem', 'remove', 'd', 'del', 'delete'].includes(args[1].toLowerCase())) { + let blacklistedUser = args[0].match(/^<@(?:!?)(?:\d+)>$/) && mention && client.users.cache.has(mention.id) ? mention.id : client.users.cache.has(args[0]) ? client.users.cache.get(args[0]).id : null; + if (!blacklistedUser) { return message.reply("You need to specify who you're letting free..." );} + let userData = await UserData.findOne( { uid: blacklistedUser } ) || new UserData({uid: blacklistedUser}); + + if (!checkPerms(tu, userData);) {return;} + + if(userData.blacklisted === false) {return message.reply('hate to break it you... they\'re not even blacklisted!');} + + await UserData.findOneAndUpdate({ uid: blacklistedUser }, { blacklisted: false }.catch(() => {})); + return message.channel.send(`Alright, there you go, I unblacklisted **${blacklistedUser.user.tag}**`) + } + + return message.channel.send("Valid args: ` `"); + + } + + }}; \ No newline at end of file diff --git a/models/guild.js b/models/guild.js index a2ca5fd..480bd5e 100644 --- a/models/guild.js +++ b/models/guild.js @@ -18,7 +18,8 @@ const guildSchema = new mongoose.Schema({ nostatus: {type: Boolean, default: false}, starchannel: {type: String, default: ''}, starreq: {type: Number, default: 5}, - starsenabled: {type: Boolean, default: false} + starsenabled: {type: Boolean, default: false}, + blacklisted: {type: Boolean, default: false} }); module.exports = mongoose.model("guild", guildSchema); \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 93413ab..8566a6a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1428,9 +1428,9 @@ "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=" }, "debug": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.2.0.tgz", - "integrity": "sha512-IX2ncY78vDTjZMFUdmsvIRFY2Cf4FnD0wRs+nQwJU8Lu99/tPFdb0VybiiMTPe3I6rQmwsqQqRBvxU+bZ/I8sg==", + "version": "4.3.1", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.1.tgz", + "integrity": "sha512-doEwdvm4PCeK4K3RQN2ZC2BYUBaxwLARCqZmMjtF8a51J2Rb0xpVloFRnCODwqjpwnAoao4pelN8l3RJdv3gRQ==", "requires": { "ms": "2.1.2" }