JaBa/commands/Moderation/warn.js

97 lines
3.6 KiB
JavaScript
Raw Normal View History

2021-12-10 21:39:54 +05:00
const Command = require("../../base/Command.js"),
Discord = require("discord.js");
class Warn extends Command {
constructor (client) {
super(client, {
name: "warn",
dirname: __dirname,
enabled: true,
guildOnly: true,
aliases: [],
memberPermissions: [ "MANAGE_MESSAGES" ],
botPermissions: [ "SEND_MESSAGES", "EMBED_LINKS" ],
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/warn:MISSING_MEMBER");
if (member.user.bot) return message.error("misc:BOT_USER");
2021-12-10 21:39:54 +05:00
const memberData = await this.client.findOrCreateMember({ id: member.id, guildID: message.guild.id });
2021-12-11 01:11:50 +05:00
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 reason = args.slice(1).join(" ");
2021-12-11 01:11:50 +05:00
if (!reason) return message.error("moderation/warn:MISSING_REASON");
2021-12-10 21:39:54 +05:00
// Gets current member sanctions
const sanctions = memberData.sanctions.filter((s) => s.type === "warn").length;
const banCount = data.guild.plugins.warnsSanctions.ban;
const kickCount = data.guild.plugins.warnsSanctions.kick;
2021-12-11 01:11:50 +05:00
2021-12-10 21:39:54 +05:00
data.guild.casesCount++;
data.guild.save();
const caseInfo = {
channel: message.channel.id,
moderator: message.author.id,
date: Date.now(),
type: "warn",
case: data.guild.casesCount,
reason
};
const embed = new Discord.MessageEmbed()
.addField(message.translate("common:USER"), `\`${member.user.tag}\` (${member.user.toString()})`)
.addField(message.translate("common:MODERATOR"), `\`${message.author.tag}\` (${message.author.toString()}`)
.addField(message.translate("common:REASON"), reason, true);
2021-12-11 01:11:50 +05:00
if (banCount) {
if (sanctions >= banCount) {
member.send(message.translate("moderation/ban:BANNED_DM", { username: member.user, moderator: message.author.tag, server: message.guild.name, reason }));
2021-12-10 21:39:54 +05:00
caseInfo.type = "ban";
2021-12-11 01:11:50 +05:00
embed.setAuthor(message.translate("moderation/ban:CASE", { count: data.guild.casesCount }))
2021-12-10 21:39:54 +05:00
.setColor("#e02316");
message.guild.members.ban(member).catch(() => {});
2021-12-11 01:11:50 +05:00
message.success("moderation/setwarns:AUTO_BAN", { username: member.user.tag, count: banCount });
};
};
if (kickCount) {
if (sanctions >= kickCount) {
member.send(message.translate("moderation/kick:KICKED_DM", { username: member.user, moderator: message.author.tag, server: message.guild.name, reason }));
2021-12-10 21:39:54 +05:00
caseInfo.type = "kick";
2021-12-11 01:11:50 +05:00
embed.setAuthor(message.translate("moderation/kick:CASE", { count: data.guild.casesCount }))
2021-12-10 21:39:54 +05:00
.setColor("#e88709");
member.kick().catch(() => {});
2021-12-11 01:11:50 +05:00
message.success("moderation/setwarns:AUTO_KICK", { username: member.user.tag, count: kickCount });
};
};
member.send(message.translate("moderation/warn:WARNED_DM", { username: member.user.tag, server: message.guild.name, moderator: message.author.tag, reason }));
2021-12-10 21:39:54 +05:00
caseInfo.type = "warn";
2021-12-11 01:11:50 +05:00
embed.setAuthor(message.translate("moderation/warn:CASE", { caseNumber: data.guild.casesCount }))
2021-12-10 21:39:54 +05:00
.setColor("#8c14e2");
2021-12-11 01:11:50 +05:00
message.success("moderation/warn:WARNED", { username: member.user.tag, reason });
2021-12-10 21:39:54 +05:00
memberData.sanctions.push(caseInfo);
memberData.save();
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);
if(!channel) return;
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
};
2021-12-10 21:39:54 +05:00
2021-12-11 01:11:50 +05:00
module.exports = Warn;