2022-08-08 18:19:56 +05:00
|
|
|
const { ContextMenuCommandBuilder, ModalBuilder, EmbedBuilder, ActionRowBuilder, TextInputBuilder, ApplicationCommandType, PermissionFlagsBits, TextInputStyle } = require("discord.js");
|
2022-07-31 18:52:16 +05:00
|
|
|
const BaseCommand = require("../../base/BaseCommand");
|
|
|
|
|
|
|
|
class Warn extends BaseCommand {
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {import("../../base/JaBa")} client
|
|
|
|
*/
|
|
|
|
constructor() {
|
|
|
|
super({
|
|
|
|
command: new ContextMenuCommandBuilder()
|
|
|
|
.setName("warn")
|
|
|
|
.setType(ApplicationCommandType.User)
|
2022-10-13 00:05:36 +05:00
|
|
|
.setDMPermission(false)
|
2022-07-31 18:52:16 +05:00
|
|
|
.setDefaultMemberPermissions(PermissionFlagsBits.ModerateMembers && PermissionFlagsBits.ManageMessages),
|
|
|
|
aliases: [],
|
|
|
|
dirname: __dirname,
|
2022-12-15 21:02:38 +05:00
|
|
|
ownerOnly: false,
|
2022-07-31 18:52:16 +05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {import("../../base/JaBa")} client
|
|
|
|
*/
|
|
|
|
async onLoad() {
|
|
|
|
//...
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {import("../../base/JaBa")} client
|
|
|
|
* @param {import("discord.js").UserContextMenuCommandInteraction} interaction
|
2022-08-09 23:48:33 +05:00
|
|
|
* @param {Object} data
|
2022-07-31 18:52:16 +05:00
|
|
|
*/
|
|
|
|
async execute(client, interaction, data) {
|
2023-01-09 01:39:13 +05:00
|
|
|
const member = interaction.targetMember,
|
|
|
|
memberPosition = member.roles.highest.position,
|
|
|
|
moderationPosition = interaction.member.roles.highest.position;
|
|
|
|
|
2022-12-07 18:43:20 +05:00
|
|
|
if (member.user.bot) return interaction.error("misc:BOT_USER", null, { ephemeral: true });
|
|
|
|
if (member.id === interaction.member.id) return interaction.error("moderation/warn:YOURSELF", null, { ephemeral: true });
|
|
|
|
if (interaction.guild.ownerId !== interaction.member.id && !(moderationPosition > memberPosition)) return interaction.error("moderation/ban:SUPERIOR", null, { ephemeral: true });
|
2022-07-31 18:52:16 +05:00
|
|
|
|
|
|
|
const memberData = await client.findOrCreateMember({
|
|
|
|
id: member.id,
|
2022-12-15 21:02:38 +05:00
|
|
|
guildId: interaction.guildId,
|
2022-07-31 18:52:16 +05:00
|
|
|
});
|
|
|
|
|
|
|
|
const modal = new ModalBuilder()
|
|
|
|
.setCustomId("warn_modal")
|
2023-06-07 23:59:38 +05:00
|
|
|
.setTitle(interaction.translate("moderation/warn:MODAL_TITLE", { nickname: member.user.discriminator === "0" ? member.user.username : member.user.tag }).normalize("NFKD"));
|
2022-07-31 18:52:16 +05:00
|
|
|
|
|
|
|
const reasonInput = new TextInputBuilder()
|
2022-08-06 20:47:47 +05:00
|
|
|
.setCustomId("warn_reason")
|
2022-08-08 18:19:56 +05:00
|
|
|
.setLabel(interaction.translate("moderation/warn:MODAL_REASON"))
|
2023-01-09 01:39:13 +05:00
|
|
|
.setMinLength(5)
|
|
|
|
.setMaxLength(200)
|
|
|
|
.setRequired(true)
|
2022-07-31 18:52:16 +05:00
|
|
|
.setStyle(TextInputStyle.Short);
|
|
|
|
|
2022-08-06 20:47:47 +05:00
|
|
|
modal.addComponents(new ActionRowBuilder().addComponents(reasonInput));
|
2022-07-31 18:52:16 +05:00
|
|
|
|
|
|
|
await interaction.showModal(modal);
|
|
|
|
|
|
|
|
const submitted = await interaction.awaitModalSubmit({
|
2023-01-09 01:39:13 +05:00
|
|
|
time: (2 * 60 * 1000),
|
2022-08-08 18:19:56 +05:00
|
|
|
filter: i => i.user.id === interaction.member.id && i.customId === "warn_modal",
|
2023-01-09 01:39:13 +05:00
|
|
|
}).catch(() => {
|
|
|
|
interaction.followUp({
|
|
|
|
content: interaction.translate("misc:TIMED_OUT"),
|
|
|
|
ephemeral: true,
|
|
|
|
});
|
2022-07-31 18:52:16 +05:00
|
|
|
});
|
|
|
|
|
2022-08-08 18:19:56 +05:00
|
|
|
if (submitted) {
|
2022-08-06 20:47:47 +05:00
|
|
|
const reason = submitted.fields.getTextInputValue("warn_reason");
|
2022-07-31 18:52:16 +05:00
|
|
|
|
2023-01-09 01:39:13 +05:00
|
|
|
const sanctions = memberData.sanctions.filter(s => s.type === "warn").length;
|
2022-07-31 18:52:16 +05:00
|
|
|
const banCount = data.guildData.plugins.warnsSanctions.ban;
|
|
|
|
const kickCount = data.guildData.plugins.warnsSanctions.kick;
|
|
|
|
|
|
|
|
const caseInfo = {
|
2022-08-02 17:18:47 +05:00
|
|
|
moderator: interaction.member.id,
|
2022-07-31 18:52:16 +05:00
|
|
|
date: Date.now(),
|
|
|
|
type: "warn",
|
2022-12-15 21:02:38 +05:00
|
|
|
reason,
|
2022-07-31 18:52:16 +05:00
|
|
|
};
|
|
|
|
|
|
|
|
const embed = new EmbedBuilder()
|
|
|
|
.addFields([
|
|
|
|
{
|
|
|
|
name: interaction.translate("common:USER"),
|
2023-06-07 23:59:38 +05:00
|
|
|
value: `\`${member.user.discriminator === "0" ? member.user.username : member.user.tag}\` (${member.user.toString()})`,
|
2022-07-31 18:52:16 +05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: interaction.translate("common:MODERATOR"),
|
2023-06-07 23:59:38 +05:00
|
|
|
value: `\`${interaction.user.discriminator === "0" ? interaction.user.username : interaction.user.tag}\` (${interaction.user.toString()})`,
|
2022-07-31 18:52:16 +05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: interaction.translate("common:REASON"),
|
|
|
|
value: reason,
|
2022-12-15 21:02:38 +05:00
|
|
|
inline: true,
|
|
|
|
},
|
2022-07-31 18:52:16 +05:00
|
|
|
]);
|
|
|
|
|
|
|
|
if (banCount) {
|
|
|
|
if (sanctions >= banCount) {
|
|
|
|
member.send({
|
|
|
|
content: interaction.translate("moderation/ban:BANNED_DM", {
|
2023-03-26 18:31:19 +05:00
|
|
|
user: member.user,
|
2023-06-07 23:59:38 +05:00
|
|
|
moderator: interaction.user.discriminator === "0" ? interaction.user.username : interaction.user.tag,
|
2022-07-31 18:52:16 +05:00
|
|
|
server: interaction.guild.name,
|
2022-12-15 21:02:38 +05:00
|
|
|
reason,
|
|
|
|
}),
|
2022-07-31 18:52:16 +05:00
|
|
|
});
|
2022-12-17 13:33:33 +05:00
|
|
|
|
2022-07-31 18:52:16 +05:00
|
|
|
caseInfo.type = "ban";
|
2022-12-17 13:33:33 +05:00
|
|
|
|
|
|
|
embed
|
|
|
|
.setAuthor({
|
|
|
|
name: interaction.translate("moderation/warn:BAN"),
|
|
|
|
})
|
2022-12-07 18:43:20 +05:00
|
|
|
.setColor(client.config.embed.color);
|
2022-12-17 13:33:33 +05:00
|
|
|
|
|
|
|
interaction.guild.members.ban(member).catch(() => {});
|
2023-01-09 01:39:13 +05:00
|
|
|
interaction.followUp({
|
|
|
|
content: interaction.translate("moderation/setwarns:AUTO_BAN", {
|
2023-06-07 23:59:38 +05:00
|
|
|
user: member.user.discriminator === "0" ? member.user.username : member.user.tag,
|
2023-04-20 11:47:47 +05:00
|
|
|
count: `${banCount} ${client.functions.getNoun(banCount, interaction.translate("misc:NOUNS:WARNS:1"), interaction.translate("misc:NOUNS:WARNS:2"), interaction.translate("misc:NOUNS:WARNS:5"))}`,
|
2023-01-09 01:39:13 +05:00
|
|
|
}),
|
2022-07-31 18:52:16 +05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kickCount) {
|
|
|
|
if (sanctions >= kickCount) {
|
|
|
|
member.send({
|
|
|
|
content: interaction.translate("moderation/kick:KICKED_DM", {
|
2023-03-26 18:31:19 +05:00
|
|
|
user: member.user,
|
2023-06-07 23:59:38 +05:00
|
|
|
moderator: interaction.user.discriminator === "0" ? interaction.user.username : interaction.user.tag,
|
2022-07-31 18:52:16 +05:00
|
|
|
server: interaction.guild.name,
|
2022-12-15 21:02:38 +05:00
|
|
|
reason,
|
|
|
|
}),
|
2022-07-31 18:52:16 +05:00
|
|
|
});
|
2022-12-17 13:33:33 +05:00
|
|
|
|
2022-07-31 18:52:16 +05:00
|
|
|
caseInfo.type = "kick";
|
2022-12-17 13:33:33 +05:00
|
|
|
|
|
|
|
embed
|
|
|
|
.setAuthor({
|
|
|
|
name: interaction.translate("moderation/warn:KICK"),
|
|
|
|
})
|
2022-12-07 18:43:20 +05:00
|
|
|
.setColor(client.config.embed.color);
|
2022-12-17 13:33:33 +05:00
|
|
|
|
2022-07-31 18:52:16 +05:00
|
|
|
member.kick().catch(() => {});
|
2023-01-09 01:39:13 +05:00
|
|
|
interaction.followUp({
|
|
|
|
content: interaction.translate("moderation/setwarns:AUTO_KICK", {
|
2023-06-07 23:59:38 +05:00
|
|
|
user: member.user.discriminator === "0" ? member.user.username : member.user.tag,
|
2023-04-20 11:47:47 +05:00
|
|
|
count: `${kickCount} ${client.functions.getNoun(kickCount, interaction.translate("misc:NOUNS:WARNS:1"), interaction.translate("misc:NOUNS:WARNS:2"), interaction.translate("misc:NOUNS:WARNS:5"))}`,
|
2023-01-09 01:39:13 +05:00
|
|
|
}),
|
2022-07-31 18:52:16 +05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
member.send({
|
|
|
|
content: interaction.translate("moderation/warn:WARNED_DM", {
|
2023-06-07 23:59:38 +05:00
|
|
|
user: member.user.discriminator === "0" ? member.user.username : member.user.tag,
|
2022-07-31 18:52:16 +05:00
|
|
|
server: interaction.guild.name,
|
2023-06-07 23:59:38 +05:00
|
|
|
moderator: interaction.user.discriminator === "0" ? interaction.user.username : interaction.user.tag,
|
2022-12-15 21:02:38 +05:00
|
|
|
reason,
|
|
|
|
}),
|
2022-07-31 18:52:16 +05:00
|
|
|
});
|
|
|
|
|
2022-12-17 13:33:33 +05:00
|
|
|
embed
|
|
|
|
.setAuthor({
|
|
|
|
name: interaction.translate("moderation/warn:WARN"),
|
|
|
|
})
|
|
|
|
.setColor(client.config.embed.color);
|
2022-07-31 18:52:16 +05:00
|
|
|
|
|
|
|
memberData.sanctions.push(caseInfo);
|
|
|
|
memberData.save();
|
|
|
|
|
|
|
|
if (data.guildData.plugins.modlogs) {
|
|
|
|
const channel = interaction.guild.channels.cache.get(data.guildData.plugins.modlogs);
|
|
|
|
if (!channel) return;
|
2022-12-17 13:33:33 +05:00
|
|
|
|
2022-07-31 18:52:16 +05:00
|
|
|
channel.send({
|
2022-12-15 21:02:38 +05:00
|
|
|
embeds: [embed],
|
2022-07-31 18:52:16 +05:00
|
|
|
});
|
|
|
|
}
|
2023-01-09 01:39:13 +05:00
|
|
|
|
|
|
|
return submitted.reply({
|
|
|
|
content: interaction.translate("moderation/warn:WARNED", {
|
|
|
|
user: member.toString(),
|
|
|
|
reason,
|
|
|
|
}),
|
|
|
|
});
|
2022-07-31 18:52:16 +05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = Warn;
|