JaBa/commands/Administration/config.js

259 lines
12 KiB
JavaScript
Raw Permalink Normal View History

const { SlashCommandBuilder, PermissionsBitField, ChannelType } = require("discord.js");
2022-08-08 18:19:56 +05:00
const BaseCommand = require("../../base/BaseCommand");
class Config extends BaseCommand {
/**
*
2023-11-05 16:03:23 +05:00
* @param {import("../../base/Client")} client
2022-08-08 18:19:56 +05:00
*/
constructor(client) {
super({
command: new SlashCommandBuilder()
.setName("config")
.setDescription(client.translate("administration/config:DESCRIPTION"))
.setDescriptionLocalizations({
2023-07-05 00:58:06 +05:00
uk: client.translate("administration/config:DESCRIPTION", null, "uk-UA"),
ru: client.translate("administration/config:DESCRIPTION", null, "ru-RU"),
})
.setDMPermission(false)
2023-07-03 21:13:08 +05:00
.setDefaultMemberPermissions(PermissionsBitField.Flags.ManageGuild)
2023-07-05 00:58:06 +05:00
.addSubcommand(subcommand =>
subcommand
.setName("list")
.setDescription(client.translate("administration/config:LIST"))
.setDescriptionLocalizations({
uk: client.translate("administration/config:LIST", null, "uk-UA"),
ru: client.translate("administration/config:LIST", null, "ru-RU"),
}),
)
2023-07-05 00:58:06 +05:00
.addSubcommand(subcommand =>
subcommand
.setName("set")
.setDescription(client.translate("administration/config:SET"))
.setDescriptionLocalizations({
2023-07-05 00:58:06 +05:00
uk: client.translate("administration/config:SET", null, "uk-UA"),
ru: client.translate("administration/config:SET", null, "ru-RU"),
})
2023-07-05 00:58:06 +05:00
.addStringOption(option =>
option
.setName("setting")
.setDescription(client.translate("administration/config:SETTING"))
.setDescriptionLocalizations({
uk: client.translate("administration/config:SETTING", null, "uk-UA"),
ru: client.translate("administration/config:SETTING", null, "ru-RU"),
})
.setChoices(
{ name: client.translate("administration/config:BIRTHDAYS"), value: "birthdays" },
{ name: client.translate("administration/config:MODLOGS"), value: "modlogs" },
{ name: client.translate("administration/config:REPORTS"), value: "reports" },
{ name: client.translate("administration/config:SUGGESTIONS"), value: "suggestions" },
{ name: client.translate("administration/config:TICKETSCATEGORY"), value: "tickets.ticketsCategory" },
{ name: client.translate("administration/config:TICKETLOGS"), value: "tickets.ticketLogs" },
{ name: client.translate("administration/config:TRANSCRIPTIONLOGS"), value: "tickets.transcriptionLogs" },
2023-07-05 00:58:06 +05:00
{ name: client.translate("administration/config:MESSAGEUPDATE"), value: "monitoring.messageUpdate" },
{ name: client.translate("administration/config:MESSAGEDELETE"), value: "monitoring.messageDelete" },
2023-07-05 00:58:06 +05:00
)
.setRequired(true),
)
2023-07-05 00:58:06 +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"),
})
.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
dirname: __dirname,
ownerOnly: false,
2022-08-08 18:19:56 +05:00
});
}
2022-08-08 18:19:56 +05:00
/**
*
2023-11-05 16:03:23 +05:00
* @param {import("../../base/Client")} client
2022-08-08 18:19:56 +05:00
* @param {import("discord.js").ChatInputCommandInteraction} interaction
*/
2024-02-09 23:26:57 +05:00
async execute(client, interaction) {
const guildData = interaction.data.guild,
command = interaction.options.getSubcommand();
2022-08-08 18:19:56 +05:00
if (command === "list") {
const embed = client.embed({
author: {
name: interaction.guild.name,
iconURL: interaction.guild.iconURL(),
},
fields: [
{
name: interaction.translate("administration/config:WELCOME_TITLE"),
2023-07-05 00:58:06 +05:00
value: guildData.plugins.welcome.enabled
? interaction.translate("administration/config:WELCOME_CONTENT", {
channel: `<#${guildData.plugins.welcome.channel}>`,
withImage: guildData.plugins.welcome.withImage ? interaction.translate("common:YES") : interaction.translate("common:NO"),
}) : interaction.translate("common:DISABLED"),
inline: true,
},
{
name: interaction.translate("administration/config:GOODBYE_TITLE"),
2023-07-05 00:58:06 +05:00
value: guildData.plugins.goodbye.enabled
? interaction.translate("administration/config:GOODBYE_CONTENT", {
channel: `<#${guildData.plugins.goodbye.channel}>`,
withImage: guildData.plugins.goodbye.withImage ? interaction.translate("common:YES") : interaction.translate("common:NO"),
}) : interaction.translate("common:DISABLED"),
inline: true,
},
{
name: interaction.translate("administration/config:AUTOROLE_TITLE"),
2023-07-05 00:58:06 +05:00
value: guildData.plugins.autorole.enabled ? `<@&${guildData.plugins.autorole.role}>` : interaction.translate("common:DISABLED"),
},
{
name: interaction.translate("administration/config:AUTO_SANCTIONS"),
2023-07-05 00:58:06 +05:00
value:
(guildData.plugins.warnsSanctions.kick
? interaction.translate("administration/config:KICK_CONTENT", {
count: guildData.plugins.warnsSanctions.kick,
}) : interaction.translate("administration/config:KICK_NOT_DEFINED")) +
"\n" +
(guildData.plugins.warnsSanctions.ban
? interaction.translate("administration/config:BAN_CONTENT", {
count: guildData.plugins.warnsSanctions.ban,
}) : interaction.translate("administration/config:BAN_NOT_DEFINED")),
},
{
name: interaction.translate("administration/config:AUTOMOD_TITLE"),
2023-07-05 00:58:06 +05:00
value: guildData.plugins.automod.enabled
? interaction.translate("administration/config:AUTOMOD_CONTENT", {
channels: guildData.plugins.automod.ignored.map(ch => ` ${ch}`),
}) : interaction.translate("common:DISABLED"),
},
2023-07-03 19:30:47 +05:00
{
name: interaction.translate("administration/config:MONITORING_CHANNELS"),
value:
`${interaction.translate("administration/config:MESSAGEUPDATE")}: ${guildData.plugins?.monitoring?.messageUpdate ? `<#${guildData.plugins?.monitoring?.messageUpdate}>` : `*${interaction.translate("common:NOT_DEFINED")}*`}\n` +
`${interaction.translate("administration/config:MESSAGEDELETE")}: ${guildData.plugins?.monitoring?.messageDelete ? `<#${guildData.plugins?.monitoring?.messageDelete}>` : `*${interaction.translate("common:NOT_DEFINED")}*`}\n`,
2023-07-03 19:30:47 +05:00
},
{
name: interaction.translate("administration/config:SPECIAL_CHANNELS"),
2023-07-03 19:30:47 +05:00
value:
2023-11-24 22:09:17 +05:00
`${interaction.translate("administration/config:BIRTHDAYS")}: ${guildData.plugins?.birthdays ? `<#${guildData.plugins.birthdays}>` : `*${interaction.translate("common:NOT_DEFINED")}*`}\n` +
`${interaction.translate("administration/config:MODLOGS")}: ${guildData.plugins?.modlogs ? `<#${guildData.plugins.modlogs}>` : `*${interaction.translate("common:NOT_DEFINED")}*`}\n` +
`${interaction.translate("administration/config:REPORTS")}: ${guildData.plugins?.reports ? `<#${guildData.plugins.reports}>` : `*${interaction.translate("common:NOT_DEFINED")}*`}\n` +
`${interaction.translate("administration/config:SUGGESTIONS")}: ${guildData.plugins?.suggestions ? `<#${guildData.plugins.suggestions}>` : `*${interaction.translate("common:NOT_DEFINED")}*`}\n` +
`${interaction.translate("administration/config:TICKETSCATEGORY")}: ${guildData.plugins?.tickets?.ticketsCategory ? `<#${guildData.plugins?.tickets?.ticketsCategory}>` : `*${interaction.translate("common:NOT_DEFINED")}*`}\n` +
`${interaction.translate("administration/config:TICKETLOGS")}: ${guildData.plugins?.tickets?.ticketLogs ? `<#${guildData.plugins?.tickets?.ticketLogs}>` : `*${interaction.translate("common:NOT_DEFINED")}*`}\n` +
`${interaction.translate("administration/config:TRANSCRIPTIONLOGS")}: ${guildData.plugins?.tickets?.transcriptionLogs ? `<#${guildData.plugins?.tickets?.transcriptionLogs}>` : `*${interaction.translate("common:NOT_DEFINED")}*`}\n`,
},
2023-06-26 17:25:17 +05:00
{
name: interaction.translate("administration/config:DASHBOARD_TITLE"),
value: `[${interaction.translate("administration/config:DASHBOARD_CONTENT")}](${client.config.dashboard.domain})`,
},
],
});
2022-08-08 18:19:56 +05:00
interaction.reply({
embeds: [embed],
ephemeral: true,
});
} else {
const setting = interaction.options.getString("setting"),
state = interaction.options.getBoolean("state"),
channel = interaction.options.getChannel("channel");
2024-02-09 23:26:57 +05:00
await changeSetting(interaction, setting, state, channel);
}
}
}
/**
*
* @param {import("discord.js").ChatInputCommandInteraction} interaction
* @param {String} setting
* @param {Boolean} state
* @param {import("discord.js").GuildTextBasedChannel | import("discord.js").CategoryChannel} channel
* @returns
*/
2024-02-09 23:26:57 +05:00
async function changeSetting(interaction, setting, state, channel) {
const settingSplitted = setting.split("."),
data = interaction.data.guild;
2024-01-15 23:19:59 +05:00
if (settingSplitted.length === 2) {
2024-02-09 23:26:57 +05:00
if (data.plugins[settingSplitted[0]] === undefined) data.plugins[settingSplitted[0]] = {};
2024-01-15 23:19:59 +05:00
if (!state) {
2024-02-09 23:26:57 +05:00
data.plugins[settingSplitted[0]][settingSplitted[1]] = null;
2024-02-09 23:26:57 +05:00
data.markModified(`plugins.${settingSplitted[0]}`);
await data.save();
return interaction.reply({
2024-01-15 23:19:59 +05:00
content: `${interaction.translate(`administration/config:${settingSplitted.length === 2 ? settingSplitted[1].toUpperCase() : setting.toUpperCase()}`)}: **${interaction.translate("common:DISABLED")}**`,
ephemeral: true,
});
2024-01-15 23:19:59 +05:00
} else {
if (settingSplitted[1] === "ticketsCategory" && channel.type !== ChannelType.GuildCategory) return interaction.reply({ content: interaction.translate("administration/config:TICKETS_NOT_CATEGORY"), ephemeral: true });
if (channel) {
2024-02-09 23:26:57 +05:00
data.plugins[settingSplitted[0]][settingSplitted[1]] = channel.id;
2024-01-15 23:19:59 +05:00
2024-02-09 23:26:57 +05:00
data.markModified(`plugins.${settingSplitted[0]}`);
await data.save();
2024-01-15 23:19:59 +05:00
return interaction.reply({
content: `${interaction.translate(`administration/config:${settingSplitted.length === 2 ? settingSplitted[1].toUpperCase() : setting.toUpperCase()}`)}: **${interaction.translate("common:ENABLED")}** (${channel.toString()})`,
ephemeral: true,
});
} else
return interaction.reply({
content: `${interaction.translate(`administration/config:${settingSplitted.length === 2 ? settingSplitted[1].toUpperCase() : setting.toUpperCase()}`)}: ${
2024-02-09 23:26:57 +05:00
data.plugins[setting] ? `**${interaction.translate("common:ENABLED")}** (<#${data.plugins[setting]}>)` : `**${interaction.translate("common:DISABLED")}**`
2024-01-15 23:19:59 +05:00
}`,
ephemeral: true,
});
}
} else {
if (!state) {
2024-02-09 23:26:57 +05:00
data.plugins[setting] = null;
2024-01-15 23:19:59 +05:00
2024-02-09 23:26:57 +05:00
data.markModified(`plugins.${setting}`);
await data.save();
2024-01-15 23:19:59 +05:00
2023-07-05 00:58:06 +05:00
return interaction.reply({
2024-01-15 23:19:59 +05:00
content: `${interaction.translate(`administration/config:${setting.toUpperCase()}`)}: **${interaction.translate("common:DISABLED")}**`,
2023-07-05 00:58:06 +05:00
ephemeral: true,
});
2024-01-15 23:19:59 +05:00
} else {
if (channel) {
2024-02-09 23:26:57 +05:00
data.plugins[setting] = channel.id;
2024-01-15 23:19:59 +05:00
2024-02-09 23:26:57 +05:00
data.markModified(`plugins.${setting}`);
await data.save();
2024-01-15 23:19:59 +05:00
return interaction.reply({
content: `${interaction.translate(`administration/config:${setting.toUpperCase()}`)}: **${interaction.translate("common:ENABLED")}** (${channel.toString()})`,
ephemeral: true,
});
} else
return interaction.reply({
content: `${interaction.translate(`administration/config:${setting.toUpperCase()}`)}: ${
2024-02-09 23:26:57 +05:00
data.plugins[setting] ? `**${interaction.translate("common:ENABLED")}** (<#${data.plugins[setting]}>)` : `**${interaction.translate("common:DISABLED")}**`
2024-01-15 23:19:59 +05:00
}`,
ephemeral: true,
});
}
2022-08-08 18:19:56 +05:00
}
}
2023-07-05 00:58:06 +05:00
module.exports = Config;