aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--package.json1
-rw-r--r--src/commands/config/settings.ts104
-rw-r--r--src/lib/models/Guild.ts6
-rw-r--r--yarn.lock16
4 files changed, 115 insertions, 12 deletions
diff --git a/package.json b/package.json
index 093cc1b..1f822be 100644
--- a/package.json
+++ b/package.json
@@ -45,6 +45,7 @@
"@typescript-eslint/parser": "^4.14.1"
},
"dependencies": {
+ "@discordjs/builders": "^0.6.0",
"@discordjs/voice": "^0.6.0",
"canvas": "^2.8.0",
"chalk": "^4.1.1",
diff --git a/src/commands/config/settings.ts b/src/commands/config/settings.ts
index 003e118..032b4e5 100644
--- a/src/commands/config/settings.ts
+++ b/src/commands/config/settings.ts
@@ -1,4 +1,4 @@
-import { BushCommand, BushMessage, BushSlashMessage, guildSettings } from '@lib';
+import { BushCommand, BushMessage, BushSlashMessage, guildSettingsObj, settingsArr } from '@lib';
import {
Message,
MessageActionRow,
@@ -20,6 +20,89 @@ export default class SettingsCommand extends BushCommand {
examples: ['settings']
},
slash: true,
+ slashOptions: [
+ {
+ name: 'view',
+ description: 'See a all settings or a particular setting',
+ type: 'SUB_COMMAND',
+ options: [
+ {
+ name: 'setting',
+ description: 'What setting would you like to see?',
+ type: 'STRING',
+ required: false,
+ choices: settingsArr.map((s) => ({ name: guildSettingsObj[s].name, value: s }))
+ }
+ ]
+ },
+ {
+ name: 'set',
+ description: 'Set a particular setting.',
+ type: 'SUB_COMMAND',
+ options: [
+ {
+ name: 'setting',
+ description: 'What setting would you like to set?',
+ type: 'STRING',
+ required: true,
+ choices: settingsArr
+ .filter((s) => !guildSettingsObj[s].type.includes('array'))
+ .map((s) => ({ name: guildSettingsObj[s].name, value: s }))
+ },
+ {
+ name: 'value',
+ description: 'What would you like the new value to be?',
+ type: 'STRING',
+ required: true
+ }
+ ]
+ },
+ {
+ name: 'add',
+ description: 'Add a value to a particular setting.',
+ type: 'SUB_COMMAND',
+ options: [
+ {
+ name: 'setting',
+ description: 'What setting would you like to add to?',
+ type: 'STRING',
+ required: true,
+ choices: settingsArr
+ .filter((s) => guildSettingsObj[s].type.includes('array'))
+ .map((s) => ({ name: guildSettingsObj[s].name, value: s }))
+ },
+ {
+ name: 'value',
+ description: 'What would you like the new value to be?',
+ type: 'STRING',
+ required: true
+ }
+ ]
+ },
+ {
+ name: 'remove',
+ description: 'Remove a value to a particular setting.',
+ type: 'SUB_COMMAND',
+ options: [
+ {
+ name: 'setting',
+ description: 'What setting would you like to set?',
+ type: 'STRING',
+ required: true,
+ choices: settingsArr
+ .filter((s) => guildSettingsObj[s].type.includes('array'))
+ .map((s) => ({ name: guildSettingsObj[s].name, value: s }))
+ },
+ {
+ name: 'value',
+ description: 'What would you like the new value to be?',
+ type: 'STRING',
+ required: true
+ }
+ ]
+ }
+ ],
+ slashGuilds: ['516977525906341928'],
channel: 'guild',
clientPermissions: ['SEND_MESSAGES'],
userPermissions: ['SEND_MESSAGES', 'MANAGE_GUILD'],
@@ -27,6 +110,8 @@ export default class SettingsCommand extends BushCommand {
});
}
+ // *args(): any {}
+
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);
@@ -46,7 +131,7 @@ export default class SettingsCommand extends BushCommand {
if (!interaction.isSelectMenu()) return;
return interaction.update(
- await this.generateMessageOptions(message, interaction.values[0] as keyof typeof guildSettings)
+ await this.generateMessageOptions(message, interaction.values[0] as keyof typeof guildSettingsObj)
);
}
}
@@ -58,22 +143,21 @@ export default class SettingsCommand extends BushCommand {
public async generateMessageOptions(
message: BushMessage | BushSlashMessage,
- feature?: keyof typeof guildSettings
+ feature?: keyof typeof guildSettingsObj
): 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');
+ const desc = settingsArr.map((s) => `**${guildSettingsObj[s].name}**`).join('\n');
settingsEmbed.setDescription(desc);
const selMenu = new MessageActionRow().addComponents(
new MessageSelectMenu()
.addOptions(
...settingsArr.map((s) => ({
- label: guildSettings[s].name,
+ label: guildSettingsObj[s].name,
value: s,
- description: guildSettings[s].description
+ description: guildSettingsObj[s].description
}))
)
.setPlaceholder('Select A Setting to View')
@@ -86,10 +170,10 @@ export default class SettingsCommand extends BushCommand {
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') {
+ settingsEmbed.setDescription(guildSettingsObj[feature].description);
+ switch (guildSettingsObj[feature].type as 'string' | 'channel' | 'channel-array' | 'role' | 'role-array') {
case 'string': {
- settingsEmbed.addField(guildSettings[feature].name, (await message.guild.getSetting(feature)).toString());
+ settingsEmbed.addField(guildSettingsObj[feature].name, (await message.guild.getSetting(feature)).toString());
settingsEmbed.setFooter(
`Run "${await message.guild.getSetting('prefix')}settings set ${feature} <value>" to set this setting.`
);
diff --git a/src/lib/models/Guild.ts b/src/lib/models/Guild.ts
index 66deddb..4a5ede4 100644
--- a/src/lib/models/Guild.ts
+++ b/src/lib/models/Guild.ts
@@ -38,7 +38,7 @@ export interface GuildModelCreationAttributes {
automodLogChannel?: Snowflake;
}
-export const guildSettings = {
+export const guildSettingsObj = {
prefix: {
name: 'Prefix',
description: 'description goes here',
@@ -88,6 +88,10 @@ export const guildSettings = {
configurable: true
}
};
+export type GuildSettings = keyof typeof guildSettingsObj;
+export const settingsArr = Object.keys(guildSettingsObj).filter(
+ (s) => guildSettingsObj[s as GuildSettings].configurable
+) as GuildSettings[];
export const guildFeaturesObj = {
automod: {
diff --git a/yarn.lock b/yarn.lock
index 096d823..04458fc 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -54,6 +54,19 @@ __metadata:
languageName: node
linkType: hard
+"@discordjs/builders@npm:^0.6.0":
+ version: 0.6.0
+ resolution: "@discordjs/builders@npm:0.6.0"
+ dependencies:
+ "@sindresorhus/is": ^4.0.1
+ discord-api-types: ^0.22.0
+ ow: ^0.27.0
+ ts-mixer: ^6.0.0
+ tslib: ^2.3.1
+ checksum: a6f1517bc9c55a4156eaea8de25b0f8a064923ba93a366c6ba4ae8724a16b35918121759cb4d9097c76457f2d9f2cc583c39809f5ef5d69e11d607bb0fd1bb39
+ languageName: node
+ linkType: hard
+
"@discordjs/collection@npm:^0.2.1":
version: 0.2.1
resolution: "@discordjs/collection@npm:0.2.1"
@@ -744,6 +757,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "bush-bot@workspace:."
dependencies:
+ "@discordjs/builders": ^0.6.0
"@discordjs/voice": ^0.6.0
"@types/common-tags": ^1.8.0
"@types/express": ^4.17.12
@@ -3165,7 +3179,7 @@ discord.js@NotEnoughUpdates/discord.js:
languageName: node
linkType: hard
-"tslib@npm:^2.3.0":
+"tslib@npm:^2.3.0, tslib@npm:^2.3.1":
version: 2.3.1
resolution: "tslib@npm:2.3.1"
checksum: de17a98d4614481f7fcb5cd53ffc1aaf8654313be0291e1bfaee4b4bb31a20494b7d218ff2e15017883e8ea9626599b3b0e0229c18383ba9dce89da2adf15cb9