64 lines
2.3 KiB
TypeScript
64 lines
2.3 KiB
TypeScript
import { SlashCommandBuilder, ChatInputCommandInteraction, PermissionFlagsBits, EmbedBuilder } from 'discord.js';
|
|
import { prisma } from '../database';
|
|
import { t, resolveLocale } from '../i18n';
|
|
|
|
export default {
|
|
data: new SlashCommandBuilder()
|
|
.setName('config')
|
|
.setDescription('Configure bot features')
|
|
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator)
|
|
.addBooleanOption(opt => opt.setName('mimic').setDescription('Enable or disable Mimic feature'))
|
|
.addBooleanOption(opt => opt.setName('emoji').setDescription('Enable or disable Big Emoji feature')),
|
|
|
|
async execute(interaction: ChatInputCommandInteraction) {
|
|
if (!interaction.guildId) return;
|
|
|
|
const mimic = interaction.options.getBoolean('mimic');
|
|
const emoji = interaction.options.getBoolean('emoji');
|
|
|
|
// Resolve proper supported locale
|
|
const locale = resolveLocale({
|
|
discordLocale: interaction.locale,
|
|
guildLocale: interaction.guildLocale?.toString(),
|
|
});
|
|
|
|
if (mimic === null && emoji === null) {
|
|
return interaction.reply({
|
|
content: t(locale, 'commands.config.noOptions'),
|
|
ephemeral: true
|
|
});
|
|
}
|
|
|
|
const updateData: any = {};
|
|
if (mimic !== null) updateData.mimicEnabled = mimic;
|
|
if (emoji !== null) updateData.bigEmojiEnabled = emoji;
|
|
|
|
await prisma.guildConfig.upsert({
|
|
where: { guildId: interaction.guildId },
|
|
update: updateData,
|
|
create: {
|
|
guildId: interaction.guildId,
|
|
mimicEnabled: mimic ?? false,
|
|
bigEmojiEnabled: emoji ?? false,
|
|
},
|
|
});
|
|
|
|
const results: string[] = [];
|
|
if (mimic !== null) {
|
|
const state = mimic ? t(locale, 'commands.config.mimic.enabled') : t(locale, 'commands.config.mimic.disabled');
|
|
results.push(`${t(locale, 'commands.config.mimic.label')}: **${state}**`);
|
|
}
|
|
if (emoji !== null) {
|
|
const state = emoji ? t(locale, 'commands.config.emoji.enabled') : t(locale, 'commands.config.emoji.disabled');
|
|
results.push(`${t(locale, 'commands.config.emoji.label')}: **${state}**`);
|
|
}
|
|
|
|
const embed = new EmbedBuilder()
|
|
.setColor(0x00AE86)
|
|
.setTitle(t(locale, 'commands.config.title'))
|
|
.setDescription(results.join('\n'));
|
|
|
|
await interaction.reply({ embeds: [embed], ephemeral: true });
|
|
},
|
|
};
|