diff options
Diffstat (limited to 'src/commands/config')
-rw-r--r-- | src/commands/config/features.ts | 5 | ||||
-rw-r--r-- | src/commands/config/settings.ts | 168 |
2 files changed, 115 insertions, 58 deletions
diff --git a/src/commands/config/features.ts b/src/commands/config/features.ts index 31facfc..9a5fa5b 100644 --- a/src/commands/config/features.ts +++ b/src/commands/config/features.ts @@ -1,7 +1,6 @@ import { BushCommand, BushMessage, BushSlashMessage, GuildFeatures, guildFeaturesArr, guildFeaturesObj } from '@lib'; import { Message, MessageActionRow, MessageEmbed, MessageSelectMenu, SelectMenuInteraction } from 'discord.js'; -//todo: fix this so that it doesn't just select one feature but instead toggles it export default class FeaturesCommand extends BushCommand { public constructor() { super('features', { @@ -36,7 +35,7 @@ export default class FeaturesCommand extends BushCommand { }); collector.on('collect', async (interaction: SelectMenuInteraction) => { - if (interaction.user.id == message.author.id || client.config.owners.includes(interaction.user.id)) { + if (interaction.user.id === message.author.id || client.config.owners.includes(interaction.user.id)) { if (!message.guild) throw new Error('message.guild is null'); const [selected]: GuildFeatures[] = interaction.values as GuildFeatures[]; @@ -84,7 +83,7 @@ export default class FeaturesCommand extends BushCommand { .setPlaceholder('Select A Feature to Toggle') .setMaxValues(1) .setMinValues(1) - .setCustomId('featureCommand_selectFeature') + .setCustomId('command_selectFeature') .setDisabled(disable) ); } diff --git a/src/commands/config/settings.ts b/src/commands/config/settings.ts index 0b71629..003e118 100644 --- a/src/commands/config/settings.ts +++ b/src/commands/config/settings.ts @@ -1,56 +1,114 @@ -// import { BushCommand, BushMessage, BushSlashMessage, guildSettings } from '@lib'; +import { BushCommand, BushMessage, BushSlashMessage, guildSettings } from '@lib'; +import { + Message, + MessageActionRow, + MessageButton, + MessageComponentInteraction, + MessageEmbed, + MessageOptions, + MessageSelectMenu +} from 'discord.js'; -// export default class SettingsCommand extends BushCommand { -// public constructor() { -// super('settings', { -// aliases: ['settings', 'settings', 'configure', 'config'], -// category: 'config', -// description: { -// content: 'Configure server options. Hint this is easier to use with the slash command.', -// usage: 'config <\'add\'|\'remove\'|\'toggle\'> <setting>', -// examples: ['template 1 2'] -// }, -// args: [ -// { -// id: 'action', -// customType: ['add', 'remove', 'toggle'], -// prompt: { -// start: 'What action would you like to perform, it can be `add`, `remove`, or `toggle`.', -// retry: '{error} Choose a either `add`, `remove`, or `toggle`.', -// optional: false -// } -// }, -// { -// id: 'setting', -// customType: Object.keys(guildSettings), -// prompt: { -// start: 'What would you like to set your second argument to be?', -// retry: '{error} Pick a valid argument.', -// optional: true -// } -// } -// ], -// slash: true, -// slashOptions: [ -// { -// name: 'required_argument', -// description: 'What would you like to set your first argument to be?', -// type: 'STRING', -// required: true -// }, -// { -// name: 'optional_argument', -// description: 'What would you like to set your second argument to be?', -// type: 'STRING', -// required: false -// } -// ], -// channel: 'guild', -// clientPermissions: ['SEND_MESSAGES'], -// userPermissions: ['SEND_MESSAGES'] -// }); -// } -// public override async exec(message: BushMessage | BushSlashMessage): Promise<unknown> { -// return await message.util.reply(`${util.emojis.error} Do not use the template command.`); -// } -// } +export default class SettingsCommand extends BushCommand { + public constructor() { + super('settings', { + aliases: ['settings', 'setting', 'configure', 'config'], + category: 'config', + description: { + content: 'Configure server options.', + usage: 'settings', + examples: ['settings'] + }, + slash: true, + channel: 'guild', + clientPermissions: ['SEND_MESSAGES'], + userPermissions: ['SEND_MESSAGES', 'MANAGE_GUILD'], + ownerOnly: true + }); + } + + public override async exec(message: BushMessage | BushSlashMessage): Promise<unknown> { + if (!message.guild) return await message.util.reply(`${util.emojis.error} This command can only be used in servers.`); + const messageOptions = await this.generateMessageOptions(message); + const msg = (await message.util.reply(messageOptions)) as Message; + const collector = msg.createMessageComponentCollector({ + channel: message.channel ?? undefined, + guild: message.guild, + message: message as Message, + time: 300_000 + }); + + collector.on('collect', async (interaction: MessageComponentInteraction) => { + if (interaction.user.id === message.author.id || client.config.owners.includes(interaction.user.id)) { + if (!message.guild) throw new Error('message.guild is null'); + switch (interaction.customId) { + case 'command_settingsSel': { + if (!interaction.isSelectMenu()) return; + + return interaction.update( + await this.generateMessageOptions(message, interaction.values[0] as keyof typeof guildSettings) + ); + } + } + } else { + return await interaction?.deferUpdate().catch(() => undefined); + } + }); + } + + public async generateMessageOptions( + message: BushMessage | BushSlashMessage, + feature?: keyof typeof guildSettings + ): Promise<MessageOptions> { + if (!message.guild) throw new Error('message.guild is null'); + const settingsEmbed = new MessageEmbed().setTitle(`${message.guild!.name}'s Settings`).setColor(util.colors.default); + if (!feature) { + const settingsArr = Object.keys(guildSettings) as (keyof typeof guildSettings)[]; + const desc = settingsArr.map((s) => `**${guildSettings[s].name}**`).join('\n'); + settingsEmbed.setDescription(desc); + + const selMenu = new MessageActionRow().addComponents( + new MessageSelectMenu() + .addOptions( + ...settingsArr.map((s) => ({ + label: guildSettings[s].name, + value: s, + description: guildSettings[s].description + })) + ) + .setPlaceholder('Select A Setting to View') + .setMaxValues(1) + .setMinValues(1) + .setCustomId('command_settingsSel') + ); + return { embeds: [settingsEmbed], components: [selMenu] }; + } else { + const components = new MessageActionRow().addComponents( + new MessageButton().setStyle('PRIMARY').setCustomId('command_settingsBack').setLabel('Back') + ); + settingsEmbed.setDescription(guildSettings[feature].description); + switch (guildSettings[feature].type as 'string' | 'channel' | 'channel-array' | 'role' | 'role-array') { + case 'string': { + settingsEmbed.addField(guildSettings[feature].name, (await message.guild.getSetting(feature)).toString()); + settingsEmbed.setFooter( + `Run "${await message.guild.getSetting('prefix')}settings set ${feature} <value>" to set this setting.` + ); + return { embeds: [settingsEmbed], components: [components] }; + } + case 'channel': { + break; + } + case 'channel-array': { + break; + } + case 'role': { + break; + } + case 'role-array': { + break; + } + } + return {}; + } + } +} |