sparkles-cat-bot/src/commands/settings.ts

91 lines
2.8 KiB
TypeScript
Raw Normal View History

2025-03-31 18:07:57 +00:00
import {
CommandInteraction,
SlashCommandBuilder,
PermissionFlagsBits,
EmbedBuilder,
ChatInputCommandInteraction
} from 'discord.js';
import { guildSettings } from '../utils/guild-settings';
import { getTheme } from '../utils/themes';
// Create the command builder
export const data = new SlashCommandBuilder()
.setName('settings')
.setDescription('Configure bot settings')
.addSubcommand(subcommand =>
subcommand
.setName('response')
.setDescription('Set how often the bot responds to messages')
.addIntegerOption(option =>
option
.setName('chance')
.setDescription('Chance of responding (0-100%)')
.setRequired(true)
.setMinValue(0)
.setMaxValue(100)
)
)
.addSubcommand(subcommand =>
subcommand
.setName('pronoun')
.setDescription('Set which pronoun the bot uses')
.addStringOption(option =>
option
.setName('pronoun')
.setDescription('The pronoun to use (their/his/her/etc)')
.setRequired(true)
)
)
.addSubcommand(subcommand =>
subcommand
.setName('view')
.setDescription('View current settings')
)
.setDefaultMemberPermissions(PermissionFlagsBits.ManageGuild);
// Command execution
export async function execute(interaction: CommandInteraction): Promise<void> {
if (!interaction.guildId) {
await interaction.reply({ content: 'This command can only be used in a server.', ephemeral: true });
return;
}
const subcommand = (interaction as ChatInputCommandInteraction).options.getSubcommand();
if (subcommand === 'response') {
const chance = interaction.options.get('chance')?.value as number;
guildSettings.setResponseChance(interaction.guildId, chance);
await interaction.reply({
content: `Response chance set to ${chance}%`,
ephemeral: false
});
} else if (subcommand === 'pronoun') {
const pronoun = interaction.options.get('pronoun')?.value as string;
guildSettings.setPronoun(interaction.guildId, pronoun);
await interaction.reply({
content: `Pronoun set to "${pronoun}"`,
ephemeral: false
});
} else if (subcommand === 'view') {
const settings = guildSettings.getSettings(interaction.guildId);
const theme = getTheme(settings.themeId);
const embed = new EmbedBuilder()
.setTitle(`${theme.emojiIcon} Bot Settings`)
.setColor('#3498db')
.addFields(
{ name: 'Theme', value: theme.name, inline: true },
{ name: 'Response Chance', value: `${settings.responseChance}%`, inline: true },
{ name: 'Pronoun', value: settings.pronoun, inline: true }
)
.setFooter({ text: 'Use /theme and /settings commands to change these settings' });
await interaction.reply({
embeds: [embed],
ephemeral: false
});
}
}