JaBa/commands/Moderation/mute.js

102 lines
3.2 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 {
constructor (client) {
super(client, {
name: "mute",
dirname: __dirname,
enabled: true,
guildOnly: true,
aliases: [],
memberPermissions: [ "MANAGE_MESSAGES" ],
botPermissions: [ "SEND_MESSAGES", "EMBED_LINKS", "MANAGE_CHANNELS" ],
nsfw: false,
ownerOnly: false,
cooldown: 3000
});
}
async run (message, args, data) {
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;
2021-12-11 01:11:50 +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
const memberData = await this.client.findOrCreateMember({ id: member.id, guildID: message.guild.id });
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) => {
channel.updateOverwrite(member.id, {
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;
memberData.mute.endDate = Date.now()+ms(time);
memberData.mute.case = data.guild.casesCount;
memberData.sanctions.push(caseInfo);
memberData.markModified("sanctions");
memberData.markModified("mute");
await memberData.save();
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()
2021-12-11 01:11:50 +05:00
.setAuthor(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)
.addField(message.translate("common:EXPIRY"), message.printDate(new Date(Date.now()+ms(time))), true)
.setColor("#f44271");
channel.send(embed);
}
}
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;