diff options
author | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-10-21 00:05:53 -0400 |
---|---|---|
committer | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-10-21 00:05:53 -0400 |
commit | 166d7fdf24440db71311c2cda95697c06e7b8b36 (patch) | |
tree | 23b0400362b5f3035b156200eb634d202aa54741 /src/commands/config | |
parent | 08f33f7d450c8920afc3b9fb8886729547065313 (diff) | |
download | tanzanite-166d7fdf24440db71311c2cda95697c06e7b8b36.tar.gz tanzanite-166d7fdf24440db71311c2cda95697c06e7b8b36.tar.bz2 tanzanite-166d7fdf24440db71311c2cda95697c06e7b8b36.zip |
Refactoring, rewrote ButtonPaginator, better permission handling + support for send messages in threads, optimizations, another scam link
Diffstat (limited to 'src/commands/config')
-rw-r--r-- | src/commands/config/blacklist.ts | 4 | ||||
-rw-r--r-- | src/commands/config/config.ts | 61 | ||||
-rw-r--r-- | src/commands/config/customAutomodPhrases.ts | 4 | ||||
-rw-r--r-- | src/commands/config/disable.ts | 11 | ||||
-rw-r--r-- | src/commands/config/features.ts | 4 | ||||
-rw-r--r-- | src/commands/config/levelRoles.ts | 126 | ||||
-rw-r--r-- | src/commands/config/log.ts | 4 |
7 files changed, 102 insertions, 112 deletions
diff --git a/src/commands/config/blacklist.ts b/src/commands/config/blacklist.ts index 5dea36a..9f3737d 100644 --- a/src/commands/config/blacklist.ts +++ b/src/commands/config/blacklist.ts @@ -54,8 +54,8 @@ export default class BlacklistCommand extends BushCommand { } ], channel: 'guild', - clientPermissions: ['SEND_MESSAGES'], - userPermissions: ['SEND_MESSAGES', 'MANAGE_GUILD'] + clientPermissions: (m) => util.clientSendAndPermCheck(m), + userPermissions: ['MANAGE_GUILD'] }); } diff --git a/src/commands/config/config.ts b/src/commands/config/config.ts index 2075531..72ba566 100644 --- a/src/commands/config/config.ts +++ b/src/commands/config/config.ts @@ -12,6 +12,7 @@ import { MessageOptions, MessageSelectMenu, Role, + Snowflake, User } from 'discord.js'; import _ from 'lodash'; @@ -51,11 +52,7 @@ export default class SettingsCommand extends BushCommand { description: `What would you like to add to the server's ${guildSettingsObj[ setting ].name.toLowerCase()}?'`, - type: guildSettingsObj[setting].type.replace('-array', '').toUpperCase() as - | 'ROLE' - | 'STRING' - | 'CHANNEL' - | 'USER', + type: guildSettingsObj[setting].type.replace('-array', '').toUpperCase() as SlashArgType, required: true } ] @@ -70,11 +67,7 @@ export default class SettingsCommand extends BushCommand { description: `What would you like to remove from the server's ${guildSettingsObj[ setting ].name.toLowerCase()}?'`, - type: guildSettingsObj[setting].type.replace('-array', '').toUpperCase() as - | 'ROLE' - | 'STRING' - | 'CHANNEL' - | 'USER', + type: guildSettingsObj[setting].type.replace('-array', '').toUpperCase() as SlashArgType, required: true } ] @@ -96,7 +89,7 @@ export default class SettingsCommand extends BushCommand { description: `What would you like to set the server's ${guildSettingsObj[ setting ].name.toLowerCase()} to?'`, - type: guildSettingsObj[setting].type.toUpperCase() as 'ROLE' | 'STRING' | 'CHANNEL' | 'USER', + type: guildSettingsObj[setting].type.toUpperCase() as SlashArgType, required: true } ] @@ -105,13 +98,13 @@ export default class SettingsCommand extends BushCommand { }; }), channel: 'guild', - clientPermissions: ['SEND_MESSAGES'], - userPermissions: ['SEND_MESSAGES', 'MANAGE_GUILD'] + clientPermissions: (m) => util.clientSendAndPermCheck(m), + userPermissions: ['MANAGE_GUILD'] }); } // I make very readable code :) - override *args(message: BushMessage): IterableIterator<ArgumentOptions | Flag> { + override *args(message: BushMessage): Generator<ArgumentOptions | Flag> { const optional = message.util.parsed!.alias === 'settings'; const setting = yield { id: 'setting', @@ -126,7 +119,7 @@ export default class SettingsCommand extends BushCommand { }; const actionType = setting - ? guildSettingsObj[setting as unknown as GuildSettings]?.type.includes('-array') + ? guildSettingsObj[setting as GuildSettings]?.type.includes('-array') ? ['view', 'add', 'remove'] : ['view', 'set'] : undefined; @@ -151,13 +144,13 @@ export default class SettingsCommand extends BushCommand { const valueType = setting && action && action !== 'view' - ? (guildSettingsObj[setting as unknown as GuildSettings].type.replace('-array', '') as 'string' | 'channel' | 'role') + ? (guildSettingsObj[setting as GuildSettings].type.replace('-array', '') as 'string' | 'channel' | 'role') : undefined; const grammar = setting && action && action !== 'view' - ? (action as unknown as 'add' | 'remove' | 'set') === 'add' + ? (action as 'add' | 'remove' | 'set') === 'add' ? `to the ${setting} setting` - : (action as unknown as 'remove' | 'set') === 'remove' + : (action as 'remove' | 'set') === 'remove' ? `from the ${setting} setting` : `the ${setting} setting to` : undefined; @@ -184,8 +177,8 @@ export default class SettingsCommand extends BushCommand { args: { setting?: GuildSettings; subcommandGroup?: GuildSettings; - action?: 'view' | 'add' | 'remove' | 'set'; - subcommand?: 'view' | 'add' | 'remove' | 'set'; + action?: Action; + subcommand?: Action; value: string | Channel | Role; } ): Promise<unknown> { @@ -214,9 +207,9 @@ export default class SettingsCommand extends BushCommand { if (!value) return await message.util.reply( `${util.emojis.error} You must choose a value to ${action} ${ - (action as unknown as 'add' | 'remove' | 'set') === 'add' + action === 'add' ? `to the ${setting} setting` - : (action as unknown as 'remove' | 'set') === 'remove' + : action === 'remove' ? `from the ${setting} setting` : `the ${setting} setting to` }` @@ -295,12 +288,10 @@ export default class SettingsCommand extends BushCommand { return { embeds: [settingsEmbed], components: [selMenu] }; } else { settingsEmbed.setTitle(guildSettingsObj[setting].name); - const generateCurrentValue = async ( - type: 'string' | 'channel' | 'channel-array' | 'role' | 'role-array' | 'user' | 'user-array' | 'custom' - ): Promise<string> => { + const generateCurrentValue = async (type: SettingTypes): Promise<string> => { const feat = await message.guild!.getSetting(setting); - switch (type.replace('-array', '') as 'string' | 'channel' | 'role' | 'user' | 'custom') { + switch (type.replace('-array', '') as BaseSettingTypes) { case 'string': { return Array.isArray(feat) ? feat.length @@ -315,21 +306,21 @@ export default class SettingsCommand extends BushCommand { ? feat.length ? feat.map((feat) => `<#${feat}>`).join('\n') : '[Empty Array]' - : `<#${feat as string}>`; + : `<#${feat as Snowflake}>`; } case 'role': { return Array.isArray(feat) ? feat.length ? feat.map((feat) => `<@&${feat}>`).join('\n') : '[Empty Array]' - : `<@&${feat as string}>`; + : `<@&${feat as Snowflake}>`; } case 'user': { return Array.isArray(feat) ? feat.length ? feat.map((feat) => `<@${feat}>`).join('\n') : '[Empty Array]' - : `<@${feat as string}>`; + : `<@${feat as Snowflake}>`; } case 'custom': { return util.inspectAndRedact(feat); @@ -355,13 +346,13 @@ export default class SettingsCommand extends BushCommand { guildSettingsObj[setting].type.includes('-array') ? 'add/remove' : 'set' } <value>" to set this setting.` ); - settingsEmbed.addField( - 'value', - (await generateCurrentValue( - guildSettingsObj[setting].type as 'string' | 'channel' | 'channel-array' | 'role' | 'role-array' - )) || '[No Value Set]' - ); + settingsEmbed.addField('value', (await generateCurrentValue(guildSettingsObj[setting].type)) || '[No Value Set]'); return { embeds: [settingsEmbed], components: [components] }; } } } + +type SlashArgType = 'ROLE' | 'STRING' | 'CHANNEL' | 'USER'; +type BaseSettingTypes = 'string' | 'channel' | 'role' | 'user' | 'custom'; +type SettingTypes = 'string' | 'channel' | 'channel-array' | 'role' | 'role-array' | 'user' | 'user-array' | 'custom'; +type Action = 'view' | 'add' | 'remove' | 'set'; diff --git a/src/commands/config/customAutomodPhrases.ts b/src/commands/config/customAutomodPhrases.ts index 2cbe874..51e219a 100644 --- a/src/commands/config/customAutomodPhrases.ts +++ b/src/commands/config/customAutomodPhrases.ts @@ -49,8 +49,8 @@ // ownerOnly: true, // channel: 'guild', // hidden: true, -// clientPermissions: ['SEND_MESSAGES'], -// userPermissions: ['SEND_MESSAGES'] +// clientPermissions: (m) => util.clientSendAndPermCheck(m), +// userPermissions: [] // }); // } diff --git a/src/commands/config/disable.ts b/src/commands/config/disable.ts index db4909a..bca1207 100644 --- a/src/commands/config/disable.ts +++ b/src/commands/config/disable.ts @@ -52,8 +52,8 @@ export default class DisableCommand extends BushCommand { } ], channel: 'guild', - clientPermissions: ['SEND_MESSAGES'], - userPermissions: ['SEND_MESSAGES', 'MANAGE_GUILD'] + clientPermissions: (m) => util.clientSendAndPermCheck(m), + userPermissions: ['MANAGE_GUILD'] }); } @@ -63,13 +63,12 @@ export default class DisableCommand extends BushCommand { message: BushMessage | BushSlashMessage, args: { action: 'enable' | 'disable'; command: BushCommand | string; global: boolean } ): Promise<unknown> { - let action: 'disable' | 'enable' | 'toggle' = - args.action ?? (message?.util?.parsed?.alias as 'disable' | 'enable') ?? 'toggle'; + let action = (args.action ?? message?.util?.parsed?.alias ?? 'toggle') as 'disable' | 'enable' | 'toggle'; const global = args.global && message.author.isOwner(); const commandID = (args.command as BushCommand).id; if (global) { - if ((action as 'disable' | 'enable' | 'toggle') === 'toggle') { + if (action === 'toggle') { const disabledCommands = ( (await Global.findByPk(client.config.environment)) ?? (await Global.create({ environment: client.config.environment })) @@ -99,7 +98,7 @@ export default class DisableCommand extends BushCommand { // guild disable } else { const disabledCommands = await message.guild!.getSetting('disabledCommands'); - if ((action as 'disable' | 'enable' | 'toggle') === 'toggle') { + if (action === 'toggle') { action = disabledCommands.includes(commandID) ? 'disable' : 'enable'; } const newValue = util.addOrRemoveFromArray(action === 'disable' ? 'remove' : 'add', disabledCommands, commandID); diff --git a/src/commands/config/features.ts b/src/commands/config/features.ts index 076d469..3c3075c 100644 --- a/src/commands/config/features.ts +++ b/src/commands/config/features.ts @@ -13,8 +13,8 @@ export default class FeaturesCommand extends BushCommand { }, slash: true, channel: 'guild', - clientPermissions: ['SEND_MESSAGES', 'EMBED_LINKS'], - userPermissions: ['SEND_MESSAGES', 'MANAGE_GUILD'] + clientPermissions: (m) => util.clientSendAndPermCheck(m, ['EMBED_LINKS'], true), + userPermissions: ['MANAGE_GUILD'] }); } diff --git a/src/commands/config/levelRoles.ts b/src/commands/config/levelRoles.ts index 36dc50c..ee5f255 100644 --- a/src/commands/config/levelRoles.ts +++ b/src/commands/config/levelRoles.ts @@ -1,65 +1,65 @@ -import { BushCommand, BushMessage, BushSlashMessage } from '@lib'; +// import { BushCommand, BushMessage, BushSlashMessage } from '@lib'; -export default class LevelRolesCommand extends BushCommand { - public constructor() { - super('levelRole', { - aliases: ['level-role', 'level-roles', 'lr'], - category: 'config', - description: { - content: 'Configure roles to be assigned to users upon reaching certain levels.', - usage: ['level-role add <level> <role>', 'level-role remove <level>'], - examples: ['level-role 1 2'] - }, - args: [ - { - id: 'action', - customType: ['add', 'remove'] - }, - { - id: 'role', - type: 'role', - prompt: { - start: 'What would you like to set your first argument to be?', - retry: '{error} Pick a valid argument.', - optional: false - } - }, - { - id: 'level', - type: 'integer', - prompt: { - start: 'What would you like to set your second argument to be?', - retry: '{error} Pick a valid argument.', - optional: false - } - } - ], - slash: true, - slashOptions: [ - { - name: 'role', - description: 'What would you like to set your first argument to be?', - type: 'STRING', - required: true - }, - { - name: 'level', - description: 'What would you like to set your second argument to be?', - type: 'STRING', - required: true - } - ], - channel: 'guild', - clientPermissions: ['SEND_MESSAGES'], - userPermissions: ['SEND_MESSAGES', 'MANAGE_GUILD', 'MANAGE_ROLES'] - }); - } +// export default class LevelRolesCommand extends BushCommand { +// public constructor() { +// super('levelRole', { +// aliases: ['level-role', 'level-roles', 'lr'], +// category: 'config', +// description: { +// content: 'Configure roles to be assigned to users upon reaching certain levels.', +// usage: ['level-role add <level> <role>', 'level-role remove <level>'], +// examples: ['level-role 1 2'] +// }, +// args: [ +// { +// id: 'action', +// customType: ['add', 'remove'] +// }, +// { +// id: 'role', +// type: 'role', +// prompt: { +// start: 'What would you like to set your first argument to be?', +// retry: '{error} Pick a valid argument.', +// optional: false +// } +// }, +// { +// id: 'level', +// type: 'integer', +// prompt: { +// start: 'What would you like to set your second argument to be?', +// retry: '{error} Pick a valid argument.', +// optional: false +// } +// } +// ], +// slash: true, +// slashOptions: [ +// { +// name: 'role', +// description: 'What would you like to set your first argument to be?', +// type: 'STRING', +// required: true +// }, +// { +// name: 'level', +// description: 'What would you like to set your second argument to be?', +// type: 'STRING', +// required: true +// } +// ], +// channel: 'guild', +// clientPermissions: (m) => util.clientSendAndPermCheck(m), +// userPermissions: ['MANAGE_GUILD', 'MANAGE_ROLES'] +// }); +// } - public override async exec( - message: BushMessage | BushSlashMessage, - args: { required_argument: string; optional_argument: string } - ): Promise<unknown> { - return await message.util.reply(`${util.emojis.error} Do not use the template command.`); - args; - } -} +// public override async exec( +// message: BushMessage | BushSlashMessage, +// args: { required_argument: string; optional_argument: string } +// ): Promise<unknown> { +// return await message.util.reply(`${util.emojis.error} Do not use the template command.`); +// args; +// } +// } diff --git a/src/commands/config/log.ts b/src/commands/config/log.ts index 03e3582..363620a 100644 --- a/src/commands/config/log.ts +++ b/src/commands/config/log.ts @@ -29,8 +29,8 @@ export default class LogCommand extends BushCommand { } ], channel: 'guild', - clientPermissions: ['SEND_MESSAGES'], - userPermissions: ['SEND_MESSAGES', 'MANAGE_GUILD'] + clientPermissions: (m) => util.clientSendAndPermCheck(m), + userPermissions: ['MANAGE_GUILD'] }); } |