import { SlashCommandBuilder, ChannelType, PermissionFlagsBits } from 'discord.js'; import { withConn } from '../db/pool.js'; export const data = new SlashCommandBuilder() .setName('setup') .setDescription('Enable/disable features or set channels for this server') .setDefaultMemberPermissions(PermissionFlagsBits.ManageGuild) .addStringOption(o => o .setName('feature') .setDescription('Feature to configure') .setRequired(true) .addChoices({ name: 'moderation', value: 'moderation' }, { name: 'ai', value: 'ai' }, { name: 'logs', value: 'logs' }, { name: 'qotd', value: 'qotd' }, { name: 'profanity_filter', value: 'profanity_filter' })) .addStringOption(o => o .setName('value') .setDescription('on|off for toggles; for logs: off|channel; for qotd: off|channel') .setRequired(true) .addChoices({ name: 'on', value: 'on' }, { name: 'off', value: 'off' }, { name: 'channel', value: 'channel' })) .addChannelOption(o => o .setName('channel') .setDescription('Target channel when selecting channel mode') .addChannelTypes(ChannelType.GuildText)); export async function execute(interaction) { if (!interaction.guildId) return interaction.reply({ content: 'Guild only command.', ephemeral: true }); const feature = interaction.options.getString('feature', true); const value = interaction.options.getString('value', true); const channel = interaction.options.getChannel('channel'); await withConn(async (conn) => { await conn.query('INSERT IGNORE INTO guild_config (guild_id) VALUES (?)', [interaction.guildId]); switch (feature) { case 'moderation': case 'ai': case 'profanity_filter': { const column = feature === 'moderation' ? 'moderation_enabled' : feature === 'ai' ? 'ai_enabled' : 'profanity_filter_enabled'; const enabled = value === 'on' ? 1 : 0; await conn.query(`UPDATE guild_config SET ${column} = ? WHERE guild_id = ?`, [enabled, interaction.guildId]); await interaction.reply({ content: `${feature} set to ${value}.`, ephemeral: true }); break; } case 'logs': { if (value === 'channel') { if (!channel) return interaction.reply({ content: 'Please provide a text channel.', ephemeral: true }); await conn.query('UPDATE guild_config SET logs_enabled = 1, logs_channel_id = ? WHERE guild_id = ?', [channel.id, interaction.guildId]); await interaction.reply({ content: `Logs enabled in <#${channel.id}>.`, ephemeral: true }); } else { const enabled = value === 'on' ? 1 : 0; await conn.query('UPDATE guild_config SET logs_enabled = ?, logs_channel_id = NULL WHERE guild_id = ?', [enabled, interaction.guildId]); await interaction.reply({ content: `Logs ${value}.`, ephemeral: true }); } break; } case 'qotd': { if (value === 'channel') { if (!channel) return interaction.reply({ content: 'Please provide a text channel.', ephemeral: true }); await conn.query('UPDATE guild_config SET qotd_enabled = 1, qotd_channel_id = ? WHERE guild_id = ?', [channel.id, interaction.guildId]); await interaction.reply({ content: `QOTD enabled in <#${channel.id}>.`, ephemeral: true }); } else { const enabled = value === 'on' ? 1 : 0; await conn.query('UPDATE guild_config SET qotd_enabled = ?, qotd_channel_id = NULL WHERE guild_id = ?', [enabled, interaction.guildId]); await interaction.reply({ content: `QOTD ${value}.`, ephemeral: true }); } break; } default: await interaction.reply({ content: 'Unknown feature.', ephemeral: true }); } }); }