diff options
Diffstat (limited to 'src/commands/config/features.ts')
-rw-r--r-- | src/commands/config/features.ts | 105 |
1 files changed, 63 insertions, 42 deletions
diff --git a/src/commands/config/features.ts b/src/commands/config/features.ts index cb7f4bc..a694483 100644 --- a/src/commands/config/features.ts +++ b/src/commands/config/features.ts @@ -1,44 +1,65 @@ -// import { BushCommand, BushMessage, BushSlashMessage, guildFeatures } from '@lib'; -// import { MessageEmbed } from 'discord.js'; +import { BushCommand, BushMessage, BushSlashMessage, GuildFeatures, guildFeatures } from '@lib'; +import { Message, MessageActionRow, MessageEmbed, MessageSelectMenu, SelectMenuInteraction } from 'discord.js'; -// export default class FeaturesCommand extends BushCommand { -// public constructor() { -// super('features', { -// aliases: ['features'], -// category: 'config', -// description: { -// content: 'Toggle features the server.', -// usage: 'features', -// examples: ['features'] -// }, -// slash: true, -// channel: 'guild', -// clientPermissions: ['SEND_MESSAGES', 'EMBED_LINKS'], -// 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 featureEmbed = await this.generateEmbed(message); -// return await message.util.reply({ embeds: [featureEmbed] }); -// } +//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', { + aliases: ['features'], + category: 'config', + description: { + content: 'Toggle features the server.', + usage: 'features', + examples: ['features'] + }, + slash: true, + channel: 'guild', + clientPermissions: ['SEND_MESSAGES', 'EMBED_LINKS'], + 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 featureEmbed = new MessageEmbed().setTitle(`${message.guild!.name}'s Features`).setColor(util.colors.default); -// public async handleInteraction(): Promise<void> { - -// } - -// public async generateEmbed(message: BushMessage | BushSlashMessage): Promise<MessageEmbed> { -// const featureEmbed = new MessageEmbed().setTitle(`${message.guild!.name}'s Features`).setColor(util.colors.default); -// const featureList: string[] = []; -// const enabledFeatures = await message.guild!.getSetting('enabledFeatures'); -// guildFeatures.forEach((feature) => { -// featureList.push(`**${feature}:** ${enabledFeatures.includes(feature) ? util.emojis.check : util.emojis.cross}`); -// }); -// return featureEmbed.setDescription(featureList.join('\n')); -// } - -// public async generateButtons(): Promise<void>{ - -// } -// } + const enabledFeatures = await message.guild!.getSetting('enabledFeatures'); + let featureList = guildFeatures.map( + (feature) => `**${feature}:** ${enabledFeatures.includes(feature) ? util.emojis.check : util.emojis.cross}` + ); + featureEmbed.setDescription(featureList.join('\n')); + const components = new MessageActionRow().addComponents( + new MessageSelectMenu() + .addOptions(...guildFeatures.map((f) => ({ label: f, value: f }))) + .setPlaceholder('Select A Feature to Toggle') + .setMaxValues(1) + .setMinValues(1) + .setCustomId('featureCommand_selectFeature') + ); + const x = (await message.util.reply({ embeds: [featureEmbed], components: [components] })) as Message; + const collector = x.createMessageComponentCollector({ + channel: message.channel ?? undefined, + guild: message.guild, + componentType: 'SELECT_MENU', + message: message as Message, + time: 300_000 + }); + collector.on('collect', async (interaction: SelectMenuInteraction) => { + 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] = interaction.values; + if (!guildFeatures.includes(selected)) throw new Error('Invalid guild feature selected'); + await message.guild.toggleFeature(selected as GuildFeatures); + const enabledFeatures = await message.guild!.getSetting('enabledFeatures'); + featureList = guildFeatures.map( + (feature) => `**${feature}:** ${enabledFeatures.includes(feature) ? util.emojis.check : util.emojis.cross}` + ); + featureEmbed.setDescription(featureList.join('\n')); + await interaction.update({ embeds: [featureEmbed] }).catch(() => undefined); + return; + } else { + return await interaction?.deferUpdate().catch(() => undefined); + } + }); + } +} |