From 37d723b93287b7c1e4e73f47593d57cf42955b14 Mon Sep 17 00:00:00 2001 From: WubzyGD Date: Fri, 11 Jun 2021 15:44:45 -0600 Subject: [PATCH] muting --- commands/moderation/mute.js | 6 ++-- commands/moderation/unmute.js | 54 +++++++++++++++++++++++++++++++++++ events/guildMemberRemove.js | 14 +++++---- events/ready.js | 4 +-- 4 files changed, 68 insertions(+), 10 deletions(-) create mode 100644 commands/moderation/unmute.js diff --git a/commands/moderation/mute.js b/commands/moderation/mute.js index ae44420..64875a7 100644 --- a/commands/moderation/mute.js +++ b/commands/moderation/mute.js @@ -2,7 +2,7 @@ const Discord = require('discord.js'); const Mute = require('../../models/mute'); -const muted = '834613812271251476'; +const muted = '816560107616731137'; module.exports = { name: "mute", @@ -47,9 +47,9 @@ module.exports = { if (args[2]) {args.shift(); args.shift(); reason = args.join(" ").trim();} try { - person.roles.add("834613812271251476") + person.roles.add("816560107616731137") .then(() => message.channel.send("I've muted that member!") - .then(() => message.guild.channels.cache.get('834611202377515018').send(new Discord.MessageEmbed() + .then(() => message.guild.channels.cache.get('807471984806985729').send(new Discord.MessageEmbed() .setAuthor(message.member.displayName, message.author.avatarURL()) .setTitle("Member Muted!") .setDescription(`<@${person.id}> was muted!`) diff --git a/commands/moderation/unmute.js b/commands/moderation/unmute.js new file mode 100644 index 0000000..33ed80f --- /dev/null +++ b/commands/moderation/unmute.js @@ -0,0 +1,54 @@ +const Discord = require('discord.js'); + +const Mute = require('../../models/mute'); + +const muted = '816560107616731137'; + +module.exports = { + name: "unmute", + aliases: ['um'], + meta: { + category: 'Moderation', + description: "End a user's mute", + syntax: '`unmute <@user|userID>`', + extra: null, + guildOnly: true + }, + help: new Discord.MessageEmbed() + .setTitle("Help -> Unmuting") + .setDescription("Unmutes a user") + .addField("Permissions", "You must have Manage Messages in your server in order to unmute members.") + .addField("Syntax", "`unmute <@user|userID>`"), + async execute(message, msg, args, cmd, prefix, mention, client) { + if (!args.length) {return message.channel.send(`Syntax: \`${prefix}unmute <@user|userID>\``);} + if (!message.member.permissions.has("MANAGE_MESSAGES")) {return message.reply("You need to have Manage Messages permissions in this server to be able to do that.");} + if (!message.guild.me.permissions.has("MANAGE_ROLES")) {return message.reply("I don't have permissions to manage roles in this server, which I need to have in order to unmute members.");} + const person = message.mentions.members.first() || message.guild.members.cache.get(args[0]); + if (!person) {return message.channel.send("I can't find that member!");} + if (message.guild.me.roles.highest.position <= person.roles.highest.position) {return message.reply("I don't have permissions to unmute that member, as their highest role is equal to or above mine.");} + + if (person.roles.highest.positon >= message.guild.roles.cache.get(muted)) {return message.reply("You can't unmute that member as their highest role is higher than the muted role (in other words they are a moderator or admin of the server)");} + + let tm = await Mute.findOne({uid: person.id}); + if (!tm) {if (client.misc.cache.mute.has(person.id)) {client.misc.cache.mute.delete(person.id);} return message.channel.send("That person isn't muted!");} + + try { + person.roles.remove("816560107616731137") + .then(() => message.channel.send("I've unmuted that member!") + .then(() => message.guild.channels.cache.get('807471984806985729').send(new Discord.MessageEmbed() + .setAuthor(message.member.displayName, message.author.avatarURL()) + .setTitle("Member Unmuted!") + .setDescription(`<@${person.id}> was muted!`) + .addField("Reason for mute", tm.reason.length ? tm.reason : "No reason provided", true) + .setColor('c77dff') + .setFooter("Luno", client.user.avatarURL()) + .setTimestamp() + )) + ).catch(() => message.channel.send("There was an error while trying to mute that member. I may not have the correct permissions, or something else went wrong.")); + } catch {} + + await Mute.deleteOne({uid: person.id}); + + return client.misc.cache.mute.delete(person.id); + } +} \ No newline at end of file diff --git a/events/guildMemberRemove.js b/events/guildMemberRemove.js index f51bfd2..40729ee 100644 --- a/events/guildMemberRemove.js +++ b/events/guildMemberRemove.js @@ -1,6 +1,9 @@ const GuildData = require('../models/guild'); const Responses = require('../models/responses'); const sendResponse = require('../util/response/sendresponse'); +const Mute = require('../models/mute'); +const chalk = require('chalk'); +const Discord = require('discord.js'); module.exports = async (client, member) => { let tg = await GuildData.findOne({gid: member.guild.id}); @@ -14,26 +17,27 @@ module.exports = async (client, member) => { try {member.guild.channels.cache.get(tg.lch).send(await sendResponse(member, member.guild.channels.cache.get(tg.lch), 'xdlol', client, tr.responses.get(tr.bindings.get('leave'))));} catch {} } - let cm = Mute.findOne({uid: member.id}); + let cm = await Mute.findOne({uid: member.id}); if (cm) { member.guild.members.ban(member.id) - .then(() => message.guild.channels.cache.get('834611202377515018').send("<@&828000073203974166>", new Discord.MessageEmbed() + //client.users.cache.get(client.developers[0]).send(`Attempted to ban ${member.displayName}`) + .then(() => member.guild.channels.cache.get('807471984806985729').send("<@330547934951112705>", new Discord.MessageEmbed() .setAuthor(member.displayName, client.users.cache.get(member.id).avatarURL()) .setTitle("Mute Evasion Detected!") .setDescription(`<@${member.id}> has evaded their mute, and I've automatically banned them!`) .addField("Original Mod", `<@${cm.id}>`) .setColor('c77dff') - .setFooter("Kit", client.user.avatarURL()) + .setFooter("Luno", client.user.avatarURL()) .setTimestamp() )).catch(e => { console.error(`\n${chalk.red('[ERROR]')} >> ${chalk.yellow(`At [${date}] | Occurred while trying to ban a member for mute evasion`)}`, e); - message.guild.channels.cache.get('834611202377515018').send("<@&828000073203974166> **Failed automatic mute evasion ban!**", new Discord.MessageEmbed() + member.guild.channels.cache.get('807471984806985729').send("<@&807643404904562738> **Failed automatic mute evasion ban!**", new Discord.MessageEmbed() .setAuthor(member.displayName, client.users.cache.get(member.id).avatarURL()) .setTitle("Mute Evasion Detected!") .setDescription(`<@${member.id}> has evaded their mute, but I was not able to automatically ban them! Their user ID is \`${member.id}\`.`) .addField("Original Mod", `<@${cm.id}>`) .setColor('c77dff') - .setFooter("Kit", client.user.avatarURL()) + .setFooter("Luno", client.user.avatarURL()) .setTimestamp() ); }); diff --git a/events/ready.js b/events/ready.js index ada79da..979a876 100644 --- a/events/ready.js +++ b/events/ready.js @@ -50,10 +50,10 @@ module.exports = async client => { if (ct >= client.misc.cache.mute.get(mute)) { if (client.guilds.cache.get(client.misc.neptune).members.cache.has(mute)) { let mutedata = await Mute.findOne({uid: mute}); - client.guilds.cache.get(client.misc.neptune).members.cache.get(mute).roles.remove('834613812271251476') + client.guilds.cache.get(client.misc.neptune).members.cache.get(mute).roles.remove('816560107616731137') .then(() => { let muten = client.guilds.cache.get(client.misc.neptune).members.cache.get(mute).displayName; - client.guilds.cache.get(client.misc.neptune).channels.cache.get('834611202377515018').send(new Discord.MessageEmbed() + client.guilds.cache.get(client.misc.neptune).channels.cache.get('807471984806985729').send(new Discord.MessageEmbed() .setTitle("Member Automatically Unmuted") .setDescription(`<@${mute}>${muten.endsWith('s') ? "'" : "'s"} mute time has ended, and I've unmuted them.`) .addField("Muting Moderator", `<@${mutedata.mutedBy}>`, true)