JaBa/commands/Administration/automod.js

88 lines
2.6 KiB
JavaScript
Raw Normal View History

2023-07-03 21:13:08 +05:00
const { SlashCommandBuilder, PermissionsBitField, ChannelType } = require("discord.js");
2022-08-08 18:19:56 +05:00
const BaseCommand = require("../../base/BaseCommand");
class Automod extends BaseCommand {
/**
*
* @param {import("../../base/JaBa")} client
*/
constructor(client) {
super({
command: new SlashCommandBuilder()
.setName("automod")
.setDescription(client.translate("administration/automod:DESCRIPTION"))
.setDescriptionLocalizations({
"uk": client.translate("administration/automod:DESCRIPTION", null, "uk-UA"),
"ru": client.translate("administration/automod:DESCRIPTION", null, "ru-RU"),
})
.setDMPermission(false)
2023-07-03 21:13:08 +05:00
.setDefaultMemberPermissions(PermissionsBitField.Flags.ManageGuild)
2022-08-08 18:19:56 +05:00
.addBooleanOption(option => option.setName("state")
.setDescription(client.translate("common:STATE"))
.setDescriptionLocalizations({
"uk": client.translate("common:STATE", null, "uk-UA"),
"ru": client.translate("common:STATE", null, "ru-RU"),
})
2022-08-08 18:19:56 +05:00
.setRequired(true))
.addChannelOption(option => option.setName("channel")
.setDescription(client.translate("common:CHANNEL"))
.setDescriptionLocalizations({
"uk": client.translate("common:CHANNEL", null, "uk-UA"),
"ru": client.translate("common:CHANNEL", null, "ru-RU"),
})
2022-08-08 18:19:56 +05:00
.addChannelTypes(ChannelType.GuildText)),
aliases: [],
dirname: __dirname,
ownerOnly: false,
2022-08-08 18:19:56 +05:00
});
}
/**
*
* @param {import("../../base/JaBa")} client
*/
async onLoad() {
//...
}
/**
*
* @param {import("../../base/JaBa")} client
* @param {import("discord.js").ChatInputCommandInteraction} interaction
2022-08-09 23:48:33 +05:00
* @param {Object} data
2022-08-08 18:19:56 +05:00
*/
async execute(client, interaction, data) {
const state = interaction.options.getBoolean("state"),
channel = interaction.options.getChannel("channel");
2022-08-08 18:19:56 +05:00
if (state) {
data.guildData.plugins.automod = {
enabled: true,
ignored: [],
2022-08-08 18:19:56 +05:00
};
data.guildData.markModified("plugins.automod");
await data.guildData.save();
2022-08-08 18:19:56 +05:00
return interaction.success("administration/automod:ENABLED");
} else {
if (channel) {
2023-06-26 17:25:17 +05:00
data.guildData.plugins.automod.ignored.push(channel.id);
2022-08-08 18:19:56 +05:00
data.guildData.markModified("plugins.automod");
await data.guildData.save();
2022-08-08 18:19:56 +05:00
interaction.success("administration/automod:DISABLED_CHANNEL", {
channel: channel.toString(),
2022-08-08 18:19:56 +05:00
});
} else {
data.guildData.plugins.automod = {
enabled: false,
ignored: [],
2022-08-08 18:19:56 +05:00
};
data.guildData.markModified("plugins.automod");
await data.guildData.save();
2022-08-08 18:19:56 +05:00
interaction.success("administration/automod:DISABLED");
}
}
}
}
module.exports = Automod;