JaBa/commands/Moderation/mute.js

111 lines
3.3 KiB
JavaScript
Raw Normal View History

2021-12-10 21:39:54 +05:00
const Command = require("../../base/Command.js"),
Discord = require("discord.js"),
ms = require("ms");
class Mute extends Command {
2021-12-26 19:29:37 +05:00
constructor(client) {
2021-12-10 21:39:54 +05:00
super(client, {
name: "mute",
dirname: __dirname,
enabled: true,
guildOnly: true,
aliases: ["m"],
2021-12-26 19:29:37 +05:00
memberPermissions: ["MANAGE_MESSAGES"],
botPermissions: ["SEND_MESSAGES", "EMBED_LINKS", "MANAGE_CHANNELS"],
2021-12-10 21:39:54 +05:00
nsfw: false,
ownerOnly: false,
cooldown: 1000
2021-12-10 21:39:54 +05:00
});
}
2021-12-26 19:29:37 +05:00
async run(message, args, data) {
2021-12-10 21:39:54 +05:00
const member = await this.client.resolveMember(args[0], message.guild);
2021-12-11 01:11:50 +05:00
if (!member) return message.error("moderation/mute:MISSING_MEMBER");
if (member.id === message.author.id) return message.error("moderation/ban:YOURSELF");
2021-12-10 21:39:54 +05:00
const memberPosition = member.roles.highest.position;
const moderationPosition = message.member.roles.highest.position;
2022-01-03 23:20:33 +05:00
if (message.member.ownerId !== message.author.id && !(moderationPosition > memberPosition)) return message.error("moderation/ban:SUPERIOR");
2021-12-10 21:39:54 +05:00
2021-12-26 19:29:37 +05:00
const memberData = await this.client.findOrCreateMember({
id: member.id,
guildID: message.guild.id
});
2021-12-10 21:39:54 +05:00
const time = args[1];
2021-12-11 01:11:50 +05:00
if (!time || isNaN(ms(time))) return message.error("misc:INVALID_TIME");
2021-12-10 21:39:54 +05:00
let reason = args.slice(2).join(" ");
2021-12-11 01:11:50 +05:00
if (!reason) reason = message.translate("misc:NO_REASON_PROVIDED");
2021-12-10 21:39:54 +05:00
message.guild.channels.cache.forEach((channel) => {
2022-01-03 23:20:33 +05:00
channel.permissionOverwrites.edit(member.id, {
2021-12-10 21:39:54 +05:00
SEND_MESSAGES: false,
ADD_REACTIONS: false,
CONNECT: false
}).catch(() => {});
});
member.send(message.translate("moderation/mute:MUTED_DM", {
username: member.user.username,
server: message.guild.name,
moderator: message.author.tag,
time,
reason
}));
message.success("moderation/mute:MUTED", {
username: member.user.tag,
server: message.guild.name,
moderator: message.author.tag,
time,
reason
});
data.guild.casesCount++;
const caseInfo = {
channel: message.channel.id,
moderator: message.author.id,
date: Date.now(),
type: "mute",
case: data.guild.casesCount,
reason,
time
};
memberData.mute.muted = true;
2021-12-26 19:29:37 +05:00
memberData.mute.endDate = Date.now() + ms(time);
2021-12-10 21:39:54 +05:00
memberData.mute.case = data.guild.casesCount;
memberData.sanctions.push(caseInfo);
memberData.markModified("sanctions");
memberData.markModified("mute");
2021-12-30 20:03:36 +05:00
await memberData.save();
2021-12-10 21:39:54 +05:00
await data.guild.save();
this.client.databaseCache.mutedUsers.set(`${member.id}${message.guild.id}`, memberData);
2021-12-11 01:11:50 +05:00
if (data.guild.plugins.modlogs) {
2021-12-10 21:39:54 +05:00
const channel = message.guild.channels.cache.get(data.guild.plugins.modlogs);
2021-12-11 01:11:50 +05:00
if (!channel) return;
2021-12-10 21:39:54 +05:00
const embed = new Discord.MessageEmbed()
2022-01-04 00:35:11 +05:00
.setAuthor({
name: message.translate("moderation/mute:CASE", {
count: data.guild.casesCount
})
})
2021-12-10 21:39:54 +05:00
.addField(message.translate("common:USER"), `\`${member.user.tag}\` (${member.user.toString()})`, true)
.addField(message.translate("common:MODERATOR"), `\`${message.author.tag}\` (${message.author.toString()})`, true)
.addField(message.translate("common:REASON"), reason, true)
.addField(message.translate("common:DURATION"), time, true)
2021-12-26 19:29:37 +05:00
.addField(message.translate("common:EXPIRY"), message.printDate(new Date(Date.now() + ms(time))), true)
2021-12-10 21:39:54 +05:00
.setColor("#f44271");
2022-01-04 00:35:11 +05:00
channel.send({
embeds: [embed]
});
2021-12-10 21:39:54 +05:00
}
}
2021-12-11 01:11:50 +05:00
};
2021-12-10 21:39:54 +05:00
2021-12-11 01:11:50 +05:00
module.exports = Mute;