JaBa/commands/Moderation/warn.js

130 lines
3.7 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 {
2021-12-26 19:29:37 +05:00
constructor(client) {
2021-12-10 21:39:54 +05:00
super(client, {
name: "warn",
dirname: __dirname,
enabled: true,
guildOnly: true,
aliases: [],
2021-12-26 19:29:37 +05:00
memberPermissions: ["MANAGE_MESSAGES"],
botPermissions: ["SEND_MESSAGES", "EMBED_LINKS"],
2021-12-10 21:39:54 +05:00
nsfw: false,
ownerOnly: false,
cooldown: 2000
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-26 19:29:37 +05:00
if (!member) return message.error("moderation/warn:MISSING_MEMBER");
2021-12-11 01:11:50 +05:00
if (member.user.bot) return message.error("misc:BOT_USER");
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
2021-12-26 13:57:14 +05:00
if (member.id === message.author.id) return message.error("moderation/warn: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) {
2021-12-26 19:29:37 +05:00
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-26 19:29:37 +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-26 19:29:37 +05:00
message.success("moderation/setwarns:AUTO_BAN", {
username: member.user.tag,
count: banCount
});
2021-12-11 01:11:50 +05:00
};
};
if (kickCount) {
if (sanctions >= kickCount) {
2021-12-26 19:29:37 +05:00
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-26 19:29:37 +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-26 19:29:37 +05:00
message.success("moderation/setwarns:AUTO_KICK", {
username: member.user.tag,
count: kickCount
});
2021-12-11 01:11:50 +05:00
};
};
2021-12-26 19:29:37 +05:00
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-26 19:29:37 +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-26 19:29:37 +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);
2021-12-11 21:08:37 +05:00
if (!channel) return;
2021-12-10 21:39:54 +05:00
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;