diff options
Diffstat (limited to 'src/commands/config')
-rw-r--r-- | src/commands/config/_customAutomodPhrases.ts | 2 | ||||
-rw-r--r-- | src/commands/config/blacklist.ts | 41 | ||||
-rw-r--r-- | src/commands/config/config.ts | 29 | ||||
-rw-r--r-- | src/commands/config/disable.ts | 39 | ||||
-rw-r--r-- | src/commands/config/features.ts | 10 | ||||
-rw-r--r-- | src/commands/config/log.ts | 20 |
6 files changed, 91 insertions, 50 deletions
diff --git a/src/commands/config/_customAutomodPhrases.ts b/src/commands/config/_customAutomodPhrases.ts index 13887ae..d60688c 100644 --- a/src/commands/config/_customAutomodPhrases.ts +++ b/src/commands/config/_customAutomodPhrases.ts @@ -30,7 +30,7 @@ // ], // slash: true, // channel: 'guild', -// clientPermissions: (m) => util.clientSendAndPermCheck(m), +// clientPermissions: (m) => clientSendAndPermCheck(m), // userPermissions: [PermissionFlagsBits.ManageGuild] // }); // } diff --git a/src/commands/config/blacklist.ts b/src/commands/config/blacklist.ts index de457c0..80acd0b 100644 --- a/src/commands/config/blacklist.ts +++ b/src/commands/config/blacklist.ts @@ -1,4 +1,17 @@ -import { AllowedMentions, BushCommand, type ArgType, type CommandMessage, type SlashMessage } from '#lib'; +import { + addOrRemoveFromArray, + AllowedMentions, + Arg, + BushCommand, + clientSendAndPermCheck, + emojis, + format, + getGlobal, + setGlobal, + type ArgType, + type CommandMessage, + type SlashMessage +} from '#lib'; import assert from 'assert'; import { ApplicationCommandOptionType, GuildMember, PermissionFlagsBits, User } from 'discord.js'; @@ -23,7 +36,7 @@ export default class BlacklistCommand extends BushCommand { { id: 'target', description: 'The channel/user to blacklist.', - type: util.arg.union('channel', 'user'), + type: Arg.union('channel', 'user'), readableType: 'channel|user', prompt: 'What channel or user that you would like to blacklist/unblacklist?', retry: '{error} Pick a valid user or channel.', @@ -41,7 +54,7 @@ export default class BlacklistCommand extends BushCommand { } ], slash: true, - clientPermissions: (m) => util.clientSendAndPermCheck(m), + clientPermissions: (m) => clientSendAndPermCheck(m), userPermissions: [PermissionFlagsBits.ManageGuild] }); } @@ -59,26 +72,26 @@ export default class BlacklistCommand extends BushCommand { const global = args.global && message.author.isOwner(); const target = typeof args.target === 'string' - ? (await util.arg.cast('textChannel', message, args.target)) ?? (await util.arg.cast('user', message, args.target)) + ? (await Arg.cast('textChannel', message, args.target)) ?? (await Arg.cast('user', message, args.target)) : args.target; - if (!target) return await message.util.reply(`${util.emojis.error} Choose a valid channel or user.`); + if (!target) return await message.util.reply(`${emojis.error} Choose a valid channel or user.`); const targetID = target.id; if (!message.inGuild() && !global) - return await message.util.reply(`${util.emojis.error} You have to be in a guild to disable commands.`); + return await message.util.reply(`${emojis.error} You have to be in a guild to disable commands.`); if (!global) assert(message.inGuild()); const blacklistedUsers = global - ? util.getGlobal('blacklistedUsers') + ? getGlobal('blacklistedUsers') : (await message.guild!.getSetting('blacklistedChannels')) ?? []; const blacklistedChannels = global - ? util.getGlobal('blacklistedChannels') + ? getGlobal('blacklistedChannels') : (await message.guild!.getSetting('blacklistedUsers')) ?? []; if (action === 'toggle') { action = blacklistedUsers.includes(targetID) || blacklistedChannels.includes(targetID) ? 'unblacklist' : 'blacklist'; } - const newValue = util.addOrRemoveFromArray( + const newValue = addOrRemoveFromArray( action === 'blacklist' ? 'add' : 'remove', target instanceof User ? blacklistedUsers : blacklistedChannels, targetID @@ -87,22 +100,22 @@ export default class BlacklistCommand extends BushCommand { const key = target instanceof User ? 'blacklistedUsers' : 'blacklistedChannels'; const success = await (global - ? util.setGlobal(key, newValue) + ? setGlobal(key, newValue) : message.guild!.setSetting(key, newValue, message.member as GuildMember) ).catch(() => false); if (!success) return await message.util.reply({ - content: `${util.emojis.error} There was an error${global ? ' globally' : ''} ${action}ing ${util.format.input( + content: `${emojis.error} There was an error${global ? ' globally' : ''} ${action}ing ${format.input( target instanceof User ? target.tag : target.name )}.`, allowedMentions: AllowedMentions.none() }); else return await message.util.reply({ - content: `${util.emojis.success} Successfully ${action}ed ${util.format.input( - target instanceof User ? target.tag : target.name - )}${global ? ' globally' : ''}.`, + content: `${emojis.success} Successfully ${action}ed ${format.input(target instanceof User ? target.tag : target.name)}${ + global ? ' globally' : '' + }.`, allowedMentions: AllowedMentions.none() }); } diff --git a/src/commands/config/config.ts b/src/commands/config/config.ts index 689a3af..f0db467 100644 --- a/src/commands/config/config.ts +++ b/src/commands/config/config.ts @@ -1,7 +1,14 @@ import { + addOrRemoveFromArray, BushCommand, + clientSendAndPermCheck, + colors, + emojis, GuildNoArraySetting, guildSettingsObj, + inspectAndRedact, + oxford, + prefix, settingsArr, type ArgType, type CommandMessage, @@ -145,7 +152,7 @@ export default class ConfigCommand extends BushCommand { }; }), channel: 'guild', - clientPermissions: (m) => util.clientSendAndPermCheck(m), + clientPermissions: (m) => clientSendAndPermCheck(m), userPermissions: [PermissionFlagsBits.ManageGuild] }); } @@ -171,11 +178,11 @@ export default class ConfigCommand extends BushCommand { id: 'action', type: actionType, prompt: { - start: `Would you like to ${util.oxford( + start: `Would you like to ${oxford( actionType!.map((a) => `\`${a}\``), 'or' )} the \`${setting}\` setting?`, - retry: `{error} Choose one of the following actions to perform on the ${setting} setting: ${util.oxford( + retry: `{error} Choose one of the following actions to perform on the ${setting} setting: ${oxford( actionType!.map((a) => `\`${a}\``), 'or' )}`, @@ -219,7 +226,7 @@ export default class ConfigCommand extends BushCommand { assert(message.member); if (!message.member.permissions.has(PermissionFlagsBits.ManageGuild) && !message.member?.user.isOwner()) - return await message.util.reply(`${util.emojis.error} You must have the **Manage Server** permission to run this command.`); + return await message.util.reply(`${emojis.error} You must have the **Manage Server** permission to run this command.`); const setting = message.util.isSlash ? (camelCase(args.subcommandGroup)! as GuildSettings) : args.setting!; const action = message.util.isSlash ? args.subcommand! : args.action!; const value = args.value; @@ -238,15 +245,13 @@ export default class ConfigCommand extends BushCommand { }; if (!value && !(['clear', 'delete'] as const).includes(action)) - return await message.util.reply( - `${util.emojis.error} You must choose a value to ${action} ${this.grammar(action, setting)}` - ); + return await message.util.reply(`${emojis.error} You must choose a value to ${action} ${this.grammar(action, setting)}`); switch (action) { case 'add': case 'remove': { const existing = (await message.guild.getSetting(setting)) as string[]; - const updated = util.addOrRemoveFromArray(action, existing, parseVal(value)); + const updated = addOrRemoveFromArray(action, existing, parseVal(value)); await message.guild.setSetting(setting, updated, message.member); const messageOptions = await this.generateMessageOptions(message, setting); msg = (await message.util.reply(messageOptions)) as Message; @@ -311,7 +316,7 @@ export default class ConfigCommand extends BushCommand { ): Promise<MessageOptions & InteractionUpdateOptions> { assert(message.inGuild()); - const settingsEmbed = new EmbedBuilder().setColor(util.colors.default); + const settingsEmbed = new EmbedBuilder().setColor(colors.default); if (!setting) { settingsEmbed.setTitle(`${message.guild.name}'s Settings`); const desc = settingsArr.map((s) => `:wrench: **${guildSettingsObj[s].name}**`).join('\n'); @@ -341,7 +346,7 @@ export default class ConfigCommand extends BushCommand { const func = ((): ((v: string | any) => string) => { switch (type.replace('-array', '') as BaseSettingTypes) { case 'string': - return (v) => util.inspectAndRedact(v); + return (v) => inspectAndRedact(v); case 'channel': return (v) => `<#${v}>`; case 'role': @@ -349,7 +354,7 @@ export default class ConfigCommand extends BushCommand { case 'user': return (v) => `<@${v}>`; case 'custom': - return util.inspectAndRedact; + return inspectAndRedact; default: return (v) => v; } @@ -372,7 +377,7 @@ export default class ConfigCommand extends BushCommand { ); settingsEmbed.setFooter({ - text: `Run "${util.prefix(message)}${message.util.parsed?.alias ?? 'config'} ${ + text: `Run "${prefix(message)}${message.util.parsed?.alias ?? 'config'} ${ message.util.isSlash ? snakeCase(setting) : setting } ${guildSettingsObj[setting].type.includes('-array') ? 'add/remove' : 'set'} <value>" to set this setting.` }); diff --git a/src/commands/config/disable.ts b/src/commands/config/disable.ts index 373b5f6..4f52b7c 100644 --- a/src/commands/config/disable.ts +++ b/src/commands/config/disable.ts @@ -1,4 +1,16 @@ -import { AllowedMentions, BushCommand, type ArgType, type CommandMessage, type SlashMessage } from '#lib'; +import { + addOrRemoveFromArray, + AllowedMentions, + Arg, + BushCommand, + clientSendAndPermCheck, + emojis, + getGlobal, + setGlobal, + type ArgType, + type CommandMessage, + type SlashMessage +} from '#lib'; import assert from 'assert'; import { ApplicationCommandOptionType, AutocompleteInteraction, PermissionFlagsBits } from 'discord.js'; import Fuse from 'fuse.js'; @@ -28,7 +40,7 @@ export default class DisableCommand extends BushCommand { { id: 'command', description: 'The command to disable/enable.', - type: util.arg.union('commandAlias', 'command'), + type: Arg.union('commandAlias', 'command'), readableType: 'command|commandAlias', prompt: 'What command would you like to enable/disable?', retry: '{error} Pick a valid command.', @@ -48,7 +60,7 @@ export default class DisableCommand extends BushCommand { ], slash: true, channel: 'guild', - clientPermissions: (m) => util.clientSendAndPermCheck(m), + clientPermissions: (m) => clientSendAndPermCheck(m), userPermissions: [PermissionFlagsBits.ManageGuild] }); } @@ -62,23 +74,23 @@ export default class DisableCommand extends BushCommand { let action = (args.action ?? message.util?.parsed?.alias ?? 'toggle') as 'disable' | 'enable' | 'toggle'; const global = args.global && message.author.isOwner(); const commandID = - args.command instanceof BushCommand ? args.command.id : (await util.arg.cast('commandAlias', message, args.command))?.id; + args.command instanceof BushCommand ? args.command.id : (await Arg.cast('commandAlias', message, args.command))?.id; - if (!commandID) return await message.util.reply(`${util.emojis.error} Invalid command.`); + if (!commandID) return await message.util.reply(`${emojis.error} Invalid command.`); if (DisableCommand.blacklistedCommands.includes(commandID)) - return message.util.send(`${util.emojis.error} the ${commandID} command cannot be disabled.`); + return message.util.send(`${emojis.error} the ${commandID} command cannot be disabled.`); - const disabledCommands = global ? util.getGlobal('disabledCommands') : await message.guild.getSetting('disabledCommands'); + const disabledCommands = global ? getGlobal('disabledCommands') : await message.guild.getSetting('disabledCommands'); if (action === 'toggle') action = disabledCommands.includes(commandID) ? 'disable' : 'enable'; - const newValue = util.addOrRemoveFromArray(action === 'disable' ? 'add' : 'remove', disabledCommands, commandID); + const newValue = addOrRemoveFromArray(action === 'disable' ? 'add' : 'remove', disabledCommands, commandID); const success = global - ? await util.setGlobal('disabledCommands', newValue).catch(() => false) + ? await setGlobal('disabledCommands', newValue).catch(() => false) : await message.guild.setSetting('disabledCommands', newValue, message.member!).catch(() => false); if (!success) return await message.util.reply({ - content: `${util.emojis.error} There was an error${global ? ' globally' : ''} **${action.substring( + content: `${emojis.error} There was an error${global ? ' globally' : ''} **${action.substring( 0, action.length - 2 )}ing** the **${commandID}** command.`, @@ -86,10 +98,9 @@ export default class DisableCommand extends BushCommand { }); else return await message.util.reply({ - content: `${util.emojis.success} Successfully **${action.substring( - 0, - action.length - 2 - )}ed** the **${commandID}** command${global ? ' globally' : ''}.`, + content: `${emojis.success} Successfully **${action.substring(0, action.length - 2)}ed** the **${commandID}** command${ + global ? ' globally' : '' + }.`, allowedMentions: AllowedMentions.none() }); } diff --git a/src/commands/config/features.ts b/src/commands/config/features.ts index 95ae544..e88f4b7 100644 --- a/src/commands/config/features.ts +++ b/src/commands/config/features.ts @@ -1,5 +1,8 @@ import { BushCommand, + clientSendAndPermCheck, + colors, + emojis, guildFeaturesArr, guildFeaturesObj, type CommandMessage, @@ -27,7 +30,7 @@ export default class FeaturesCommand extends BushCommand { examples: ['features'], slash: true, channel: 'guild', - clientPermissions: (m) => util.clientSendAndPermCheck(m, [PermissionFlagsBits.EmbedLinks], true), + clientPermissions: (m) => clientSendAndPermCheck(m, [PermissionFlagsBits.EmbedLinks], true), userPermissions: [PermissionFlagsBits.ManageGuild] }); } @@ -35,7 +38,7 @@ export default class FeaturesCommand extends BushCommand { public override async exec(message: CommandMessage | SlashMessage) { assert(message.inGuild()); - const featureEmbed = new EmbedBuilder().setTitle(`${message.guild.name}'s Features`).setColor(util.colors.default); + const featureEmbed = new EmbedBuilder().setTitle(`${message.guild.name}'s Features`).setColor(colors.default); const enabledFeatures = await message.guild.getSetting('enabledFeatures'); this.generateDescription(guildFeaturesArr, enabledFeatures, featureEmbed); @@ -76,8 +79,7 @@ export default class FeaturesCommand extends BushCommand { embed.setDescription( allFeatures .map( - (feature) => - `${currentFeatures.includes(feature) ? util.emojis.check : util.emojis.cross} **${guildFeaturesObj[feature].name}**` + (feature) => `${currentFeatures.includes(feature) ? emojis.check : emojis.cross} **${guildFeaturesObj[feature].name}**` ) .join('\n') ); diff --git a/src/commands/config/log.ts b/src/commands/config/log.ts index 7c76bdf..3726105 100644 --- a/src/commands/config/log.ts +++ b/src/commands/config/log.ts @@ -1,4 +1,14 @@ -import { BushCommand, guildLogsArr, type ArgType, type CommandMessage, type GuildLogType, type SlashMessage } from '#lib'; +import { + BushCommand, + clientSendAndPermCheck, + emojis, + guildLogsArr, + oxford, + type ArgType, + type CommandMessage, + type GuildLogType, + type SlashMessage +} from '#lib'; import assert from 'assert'; import { ArgumentGeneratorReturn } from 'discord-akairo'; import { ApplicationCommandOptionType, ChannelType, PermissionFlagsBits } from 'discord.js'; @@ -38,7 +48,7 @@ export default class LogCommand extends BushCommand { } ], channel: 'guild', - clientPermissions: (m) => util.clientSendAndPermCheck(m), + clientPermissions: (m) => clientSendAndPermCheck(m), userPermissions: [PermissionFlagsBits.ManageGuild] }); } @@ -49,7 +59,7 @@ export default class LogCommand extends BushCommand { type: guildLogsArr, prompt: { start: 'What log type would you like to change?', - retry: `{error} Choose either ${util.oxford( + retry: `{error} Choose either ${oxford( guildLogsArr.map((l) => `\`${l}\``), 'or' )}`, @@ -87,8 +97,8 @@ export default class LogCommand extends BushCommand { return await message.util.reply( `${ success - ? `${util.emojis.success} Successfully ${oldChannel ? 'changed' : 'set'}` - : `${util.emojis.error} Unable to ${oldChannel ? 'change' : 'set'}` + ? `${emojis.success} Successfully ${oldChannel ? 'changed' : 'set'}` + : `${emojis.error} Unable to ${oldChannel ? 'change' : 'set'}` } ${ oldChannel ? `the **${args.log_type}** log channel from <#${oldChannel}>` : `the **${args.log_type}** log channel` } to ${args.channel ? `<#${args.channel.id}>` : '`disabled`'}` |