Warnings fixed and added n?clearwarn

master
Kit Kasune 4 years ago
parent 40db8704da
commit 18e28bdde4
  1. 62
      commands/clearwarnings.js
  2. 25
      commands/warn.js

@ -0,0 +1,62 @@
const Discord = require('discord.js');
const Mod = require('../models/mod');
module.exports = {
name: "clearwarnings",
aliases: ['clearwarn', 'cw', 'warnclear', 'wc', 'clearwarning'],
meta: {
category: "",
perms: "",
staff: false,
vip: "",
serverPerms: [],
writtenBy: "",
serverOnly: false
},
tags: [],
help: new Discord.MessageEmbed()
.setTitle("Help -> Warn Clearing")
.setDescription("Clears the warnigns of a user")
.addField("Syntax", "`clearwarnings <@user|userID>`")
.addField("Notice", "You must be a server administrator in order to use this command."),
async execute(message, msg, args, cmd, prefix, mention, client) {
if (!args.length) {return message.channel.send(`Syntax: \`${prefix}clearwarnings <@user|userID>\``);}
if (!message.guild) {return message.channel.send("This is a server-only command.");}
if (!message.member.permissions.has("ADMINISTRATOR")) {return message.reply("You must be a server administrator to use this command.");}
let user = message.mentions.members.first() && args[0].match(/^<@(?:!)(?:\d+)>$/) ? message.mentions.members.first() : message.guild.members.cache.has(args[0]) ? message.guild.members.cache.get(args[0]) : null;
if (!user) {return message.channel.send("Either you didn't mention a user, or I can't find that user!");}
if (user.id === client.user.id) {return message.reply("don't worry about clearing any warnings from me... you can't give me warnings in the first place");}
if (client.users.cache.get(user.id).bot) {return message.reply("it's not like a bot would have any warnings in the first place...");}
user = user ? user : message.member;
let mh = await Mod.findOne({gid: message.guild.id});
if (!mh || !Object.keys(mh.warnings).length) {return message.reply("There are no warnings available in this server.");}
if (!Object.keys(mh.warnings).includes(user.id) || !mh.warnings[user.id].length) {return message.reply(`${user.id === message.author.id ? 'You have' : 'That user has'} never been warned in this server.`);}
let mhcases = mh.cases;
let moddedcases = [];
let cwc = 0; var wc = 0;
let warning; for (warning of mh.warnings[user.id]) {
if (mhcases[`${warning - 1}`].status !== "Cleared") {
let tcase = mhcases[`${warning - 1}`];
tcase.status = "Cleared";
tcase.history.push(`${new Date().toISOString()} - ${message.author.username} - Cleared the warning.`);
moddedcases.push(`${warning - 1}`);
wc++;
if (!tcase.moderators.includes(message.author.id)) {tcase.moderators.push(message.author.id);}
mhcases[`${warning - 1}`] = tcase;
} else {cwc++;}
}
if (cwc === mh.warnings[user.id].length) {return message.reply("That user has no uncleared warnings.");}
if (moddedcases.length) {let c; for (c of moddedcases) {mh.markModified(`cases.${c}.history`);}}
mh.cases = mhcases;
mh.save();
return message.reply(`Cleared ${wc} warnings from ${user.displayName}.`);
}
};

@ -1,4 +1,5 @@
const Discord = require('discord.js'); const Discord = require('discord.js');
const Mod = require('../models/mod'); const Mod = require('../models/mod');
const {TagFilter} = require('../util/tagfilter'); const {TagFilter} = require('../util/tagfilter');
@ -52,23 +53,27 @@ module.exports = {
else if (['clear', 'e', 'empty'].includes(args[0].toLowerCase())) { else if (['clear', 'e', 'empty'].includes(args[0].toLowerCase())) {
user = user ? user : message.member; user = user ? user : message.member;
let mh = await Mod.findOne({gid: message.guild.id}); let mh = await Mod.findOne({gid: message.guild.id});
if (!mh || !mh.warnings.size) {return message.reply("There are no warnings available in this server.");} if (!mh || !Object.keys(mh.warnings).length) {return message.reply("There are no warnings available in this server.");}
if (!mh.warnings.has(user.id) || !mh.warnings.get(user.id).length) {return message.reply(`${user.id === message.author.id ? 'You have' : 'That user has'} never been warned in this server.`);} if (!Object.keys(mh.warnings).includes(user.id) || !mh.warnings[user.id].length) {return message.reply(`${user.id === message.author.id ? 'You have' : 'That user has'} never been warned in this server.`);}
let mhcases = mh.cases; let mhcases = mh.cases;
let moddedcases = [];
let cwc = 0; var wc = 0; let cwc = 0; var wc = 0;
let warning; for (warning of mh.warnings.get(user.id)) { let warning; for (warning of mh.warnings[user.id]) {
if (mhcases.get(`${warning}`).status !== "Cleared") { if (mhcases[`${warning - 1}`].status !== "Cleared") {
let tcase = mhcases.get(`${warning}`); let tcase = mhcases[`${warning - 1}`];
tcase.status = "Cleared"; tcase.status = "Cleared";
tcase.history.push(`${new Date().toISOString()} - ${message.author.username} - Cleared the warning.`); tcase.history.push(`${new Date().toISOString()} - ${message.author.username} - Cleared the warning.`);
moddedcases.push(`${warning - 1}`);
wc++; wc++;
if (!tcase.moderators.includes(message.author.id)) {tcase.moderators.push(message.author.id);} if (!tcase.moderators.includes(message.author.id)) {tcase.moderators.push(message.author.id);}
mhcases.set(`${warning}`, tcase); mhcases[`${warning - 1}`] = tcase;
} else {cwc++;} } else {cwc++;}
} }
if (cwc === mh.warnings.get(user.id).length) {return message.reply("That user has no uncleared warnings.");} if (cwc === mh.warnings[user.id].length) {return message.reply("That user has no uncleared warnings.");}
if (moddedcases.length) {let c; for (c of moddedcases) {mh.markModified(`cases.${c}.history`);}}
mh.cases = mhcases; mh.cases = mhcases;
mh.save(); mh.save();
@ -110,13 +115,9 @@ module.exports = {
let mhwarnings = mh.warnings; let mhwarnings = mh.warnings;
let mhwarningsk = Object.keys(mhwarnings); let mhwarningsk = Object.keys(mhwarnings);
console.log(mhwarnings);
if (mhwarningsk.includes(user.id)) {let tw = mhwarnings[user.id]; tw.push(mhcases.length); mhwarnings[user.id] = tw;} if (mhwarningsk.includes(user.id)) {let tw = mhwarnings[user.id]; tw.push(mhcases.length); mhwarnings[user.id] = tw;}
else {mhwarnings[user.id] = [mhcases.length];} else {mhwarnings[user.id] = [mhcases.length];}
console.log(mhwarnings);
mh.warnings = mhwarnings; mh.warnings = mhwarnings;
mh.warnings[user.id] = mhwarnings[user.id]; mh.warnings[user.id] = mhwarnings[user.id];
mh.cases = mhcases; mh.cases = mhcases;
@ -124,6 +125,8 @@ module.exports = {
if (!options.silent) {message.channel.send(`Case ${mh.cases.length} - Member has been warned. Reason: \`${reason}\``);} if (!options.silent) {message.channel.send(`Case ${mh.cases.length} - Member has been warned. Reason: \`${reason}\``);}
if (!options.silent && !options.nodm) {client.users.cache.get(user.id).send(`\`${message.author.username}\` has warned you in \`${message.guild.name}\`. Reason: **${reason}**`);} if (!options.silent && !options.nodm) {client.users.cache.get(user.id).send(`\`${message.author.username}\` has warned you in \`${message.guild.name}\`. Reason: **${reason}**`);}
mh.markModified(`warnings.${user.id}`);
mh.save(); mh.save();
return null; return null;
} }

Loading…
Cancel
Save