aboutsummaryrefslogtreecommitdiff
path: root/src/commands
diff options
context:
space:
mode:
Diffstat (limited to 'src/commands')
-rw-r--r--src/commands/config/features.ts5
-rw-r--r--src/commands/config/settings.ts168
-rw-r--r--src/commands/dev/__template.ts7
-rw-r--r--src/commands/dev/setLevel.ts6
4 files changed, 125 insertions, 61 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 {};
+ }
+ }
+}
diff --git a/src/commands/dev/__template.ts b/src/commands/dev/__template.ts
index be4f7a7..4cf407c 100644
--- a/src/commands/dev/__template.ts
+++ b/src/commands/dev/__template.ts
@@ -53,7 +53,12 @@ export default class TemplateCommand extends BushCommand {
userPermissions: ['SEND_MESSAGES']
});
}
- public override async exec(message: BushMessage | BushSlashMessage): Promise<unknown> {
+
+ public override async exec(
+ message: BushMessage | BushSlashMessage,
+ args: { required_argument: string; optional_argumen: string }
+ ): Promise<unknown> {
return await message.util.reply(`${util.emojis.error} Do not use the template command.`);
+ args;
}
}
diff --git a/src/commands/dev/setLevel.ts b/src/commands/dev/setLevel.ts
index e69b9df..777ef60 100644
--- a/src/commands/dev/setLevel.ts
+++ b/src/commands/dev/setLevel.ts
@@ -55,15 +55,17 @@ export default class SetLevelCommand extends BushCommand {
): Promise<unknown> {
if (!message.author.isOwner())
return await message.util.reply(`${util.emojis.error} Only my developers can run this command.`);
+ if (!message.guild) return await message.util.reply(`${util.emojis.error} This command can only be run in a guild.`);
+ if (!user.id) throw new Error('user.id is null');
const [levelEntry] = await Level.findOrBuild({
where: {
user: user.id,
- guild: message.guild!.id
+ guild: message.guild.id
},
defaults: {
user: user.id,
- guild: message.guild!.id
+ guild: message.guild.id
}
});
await levelEntry.update({ xp: Level.convertLevelToXp(level) });