From a3f8d3884a1deca5eccfb6d990e2a7b42fbbe08a Mon Sep 17 00:00:00 2001 From: IRONM00N <64110067+IRONM00N@users.noreply.github.com> Date: Sun, 23 Jan 2022 18:13:05 -0500 Subject: fix discord.js breaking changes, some other stuff --- src/commands/_fake-command/ironmoon.ts | 1 + src/commands/admin/channelPermissions.ts | 14 ++-- src/commands/admin/roleAll.ts | 12 ++-- src/commands/config/_customAutomodPhrases.ts | 7 +- src/commands/config/blacklist.ts | 8 +-- src/commands/config/config.ts | 69 ++++++++++++-------- src/commands/config/disable.ts | 8 +-- src/commands/config/features.ts | 41 +++++++----- src/commands/config/log.ts | 9 +-- src/commands/dev/__template.ts | 5 +- src/commands/dev/debug.ts | 79 +++++++++++++++++++++++ src/commands/dev/dm.ts | 6 +- src/commands/dev/eval.ts | 39 ++++++------ src/commands/dev/javascript.ts | 10 ++- src/commands/dev/reload.ts | 2 +- src/commands/dev/say.ts | 3 +- src/commands/dev/sh.ts | 7 +- src/commands/dev/test.ts | 75 +++++++++------------- src/commands/fun/eightBall.ts | 3 +- src/commands/fun/minesweeper.ts | 11 ++-- src/commands/info/avatar.ts | 6 +- src/commands/info/botInfo.ts | 4 +- src/commands/info/color.ts | 6 +- src/commands/info/guildInfo.ts | 88 ++++++++++++++++---------- src/commands/info/help.ts | 46 ++++++-------- src/commands/info/icon.ts | 5 +- src/commands/info/links.ts | 31 +++------ src/commands/info/ping.ts | 8 +-- src/commands/info/pronouns.ts | 6 +- src/commands/info/snowflake.ts | 60 +++++++----------- src/commands/info/userInfo.ts | 30 ++++----- src/commands/leveling/leaderboard.ts | 6 +- src/commands/leveling/level.ts | 6 +- src/commands/leveling/levelRoles.ts | 9 +-- src/commands/leveling/setLevel.ts | 7 +- src/commands/leveling/setXp.ts | 7 +- src/commands/moderation/_activePunishments.ts | 10 +-- src/commands/moderation/ban.ts | 14 ++-- src/commands/moderation/block.ts | 11 ++-- src/commands/moderation/evidence.ts | 7 +- src/commands/moderation/hideCase.ts | 5 +- src/commands/moderation/kick.ts | 11 ++-- src/commands/moderation/lockdown.ts | 16 ++--- src/commands/moderation/modlog.ts | 8 +-- src/commands/moderation/mute.ts | 11 ++-- src/commands/moderation/purge.ts | 15 +++-- src/commands/moderation/removeReactionEmoji.ts | 11 ++-- src/commands/moderation/role.ts | 19 +++--- src/commands/moderation/slowmode.ts | 17 ++--- src/commands/moderation/timeout.ts | 11 ++-- src/commands/moderation/unban.ts | 12 ++-- src/commands/moderation/unblock.ts | 11 ++-- src/commands/moderation/unlockdown.ts | 13 ++-- src/commands/moderation/unmute.ts | 11 ++-- src/commands/moderation/untimeout.ts | 11 ++-- src/commands/moderation/warn.ts | 9 ++- src/commands/moulberry-bush/capePermissions.ts | 6 +- src/commands/moulberry-bush/capes.ts | 7 +- src/commands/moulberry-bush/giveawayPing.ts | 15 +++-- src/commands/moulberry-bush/moulHammer.ts | 6 +- src/commands/moulberry-bush/report.ts | 11 ++-- src/commands/moulberry-bush/rule.ts | 10 +-- src/commands/moulberry-bush/serverStatus.ts | 5 +- src/commands/utilities/activity.ts | 10 +-- src/commands/utilities/calculator.ts | 6 +- src/commands/utilities/decode.ts | 8 +-- src/commands/utilities/hash.ts | 4 +- src/commands/utilities/price.ts | 9 +-- src/commands/utilities/remind.ts | 3 +- src/commands/utilities/reminders.ts | 5 +- src/commands/utilities/steal.ts | 13 ++-- src/commands/utilities/uuid.ts | 5 +- src/commands/utilities/viewRaw.ts | 16 ++--- src/commands/utilities/whoHasRole.ts | 5 +- src/commands/utilities/wolframAlpha.ts | 8 ++- 75 files changed, 633 insertions(+), 486 deletions(-) create mode 100644 src/commands/dev/debug.ts (limited to 'src/commands') diff --git a/src/commands/_fake-command/ironmoon.ts b/src/commands/_fake-command/ironmoon.ts index 428b554..1f63c06 100644 --- a/src/commands/_fake-command/ironmoon.ts +++ b/src/commands/_fake-command/ironmoon.ts @@ -12,6 +12,7 @@ export default class IronmoonCommand extends BushCommand { userPermissions: [] }); } + public override condition(message: BushMessage): boolean { return false; if (message.content.toLowerCase().includes('ironmoon')) return true; diff --git a/src/commands/admin/channelPermissions.ts b/src/commands/admin/channelPermissions.ts index 026f1a6..f0d2c65 100644 --- a/src/commands/admin/channelPermissions.ts +++ b/src/commands/admin/channelPermissions.ts @@ -1,5 +1,5 @@ import { BushCommand, ButtonPaginator, type ArgType, type BushMessage, type BushSlashMessage } from '#lib'; -import { MessageEmbed } from 'discord.js'; +import { ApplicationCommandOptionType, MessageEmbed, Permissions } from 'discord.js'; export default class ChannelPermissionsCommand extends BushCommand { public constructor() { @@ -18,7 +18,7 @@ export default class ChannelPermissionsCommand extends BushCommand { readableType: 'member|role', prompt: 'What user/role would you like to change?', retry: '{error} Choose a valid user/role to change.', - slashType: 'MENTIONABLE' + slashType: ApplicationCommandOptionType.Mentionable }, { id: 'permission', @@ -26,7 +26,7 @@ export default class ChannelPermissionsCommand extends BushCommand { type: 'permission', prompt: 'What permission would you like to change?', retry: '{error} Choose a valid permission.', - slashType: 'STRING' + slashType: ApplicationCommandOptionType.String }, { id: 'state', @@ -39,7 +39,7 @@ export default class ChannelPermissionsCommand extends BushCommand { readableType: "'enable'|'disable'|'remove'", prompt: 'What should that permission be set to?', retry: '{error} Set the state to either `enable`, `disable`, or `remove`.', - slashType: 'STRING', + slashType: ApplicationCommandOptionType.String, choices: [ { name: 'Enabled', value: 'true' }, { name: 'Disabled', value: 'false' }, @@ -47,8 +47,8 @@ export default class ChannelPermissionsCommand extends BushCommand { ] } ], - clientPermissions: (m) => util.clientSendAndPermCheck(m, ['MANAGE_CHANNELS']), - userPermissions: ['ADMINISTRATOR'], + clientPermissions: (m) => util.clientSendAndPermCheck(m, [Permissions.FLAGS.MANAGE_CHANNELS]), + userPermissions: [Permissions.FLAGS.ADMINISTRATOR], channel: 'guild', slash: true }); @@ -63,7 +63,7 @@ export default class ChannelPermissionsCommand extends BushCommand { } ) { if (!message.inGuild()) return await message.util.reply(`${util.emojis.error} This command can only be run in a server.`); - if (!message.member!.permissions.has('ADMINISTRATOR') && !message.member!.user.isOwner()) + if (!message.member!.permissions.has(Permissions.FLAGS.ADMINISTRATOR) && !message.member!.user.isOwner()) return await message.util.reply(`${util.emojis.error} You must have admin perms to use this command.`); if (message.util.isSlashMessage(message)) await message.interaction.deferReply(); diff --git a/src/commands/admin/roleAll.ts b/src/commands/admin/roleAll.ts index 6e82011..3b438d9 100644 --- a/src/commands/admin/roleAll.ts +++ b/src/commands/admin/roleAll.ts @@ -1,5 +1,5 @@ import { AllowedMentions, BushCommand, type ArgType, type BushMessage, type BushSlashMessage } from '#lib'; -import { type GuildMember } from 'discord.js'; +import { ApplicationCommandOptionType, Permissions, type GuildMember } from 'discord.js'; export default class RoleAllCommand extends BushCommand { public constructor() { @@ -16,7 +16,7 @@ export default class RoleAllCommand extends BushCommand { type: 'role', prompt: 'What role would you like to give to every member on the server?', retry: '{error} Pick a valid role.', - slashType: 'ROLE' + slashType: ApplicationCommandOptionType.Role }, { id: 'bots', @@ -25,13 +25,13 @@ export default class RoleAllCommand extends BushCommand { prompt: 'Would you like to also give roles to bots?', flag: '--bots', default: false, - slashType: 'BOOLEAN', + slashType: ApplicationCommandOptionType.Boolean, optional: true } ], channel: 'guild', - clientPermissions: (m) => util.clientSendAndPermCheck(m, ['MANAGE_ROLES']), - userPermissions: ['ADMINISTRATOR'], + clientPermissions: (m) => util.clientSendAndPermCheck(m, [Permissions.FLAGS.MANAGE_ROLES]), + userPermissions: [Permissions.FLAGS.ADMINISTRATOR], typing: true, slash: true }); @@ -39,7 +39,7 @@ export default class RoleAllCommand extends BushCommand { public override async exec(message: BushMessage | BushSlashMessage, args: { role: ArgType<'role'>; bots: ArgType<'boolean'> }) { if (!message.inGuild()) return await message.util.reply(`${util.emojis.error} This command can only be run in a server.`); - if (!message.member!.permissions.has('ADMINISTRATOR') && !message.member!.user.isOwner()) + if (!message.member!.permissions.has(Permissions.FLAGS.ADMINISTRATOR) && !message.member!.user.isOwner()) return await message.util.reply(`${util.emojis.error} You must have admin perms to use this command.`); if (message.util.isSlashMessage(message)) await message.interaction.deferReply(); diff --git a/src/commands/config/_customAutomodPhrases.ts b/src/commands/config/_customAutomodPhrases.ts index cd59c9a..1c91f28 100644 --- a/src/commands/config/_customAutomodPhrases.ts +++ b/src/commands/config/_customAutomodPhrases.ts @@ -1,4 +1,5 @@ // import { BushCommand, type BushMessage, type BushSlashMessage } from '#lib'; +// import { Permissions } from 'discord.js'; // export default class CustomAutomodPhrasesCommand extends BushCommand { // public constructor() { @@ -15,7 +16,7 @@ // description: 'This is the first argument.', // prompt: 'What would you like to set your first argument to be?', // retry: '{error} Pick a valid argument.', -// slashType: 'STRING' +// slashType: ApplicationCommandOptionType.String // }, // { // id: 'optional_argument', @@ -24,13 +25,13 @@ // prompt: 'What would you like to set your second argument to be?', // retry: '{error} Pick a valid argument.', // optional: true, -// slashType: 'STRING' +// slashType: ApplicationCommandOptionType.String // } // ], // slash: true, // channel: 'guild', // clientPermissions: (m) => util.clientSendAndPermCheck(m), -// userPermissions: ['MANAGE_GUILD'] +// userPermissions: [Permissions.FLAGS.MANAGE_GUILD] // }); // } diff --git a/src/commands/config/blacklist.ts b/src/commands/config/blacklist.ts index d15b8d7..0498b87 100644 --- a/src/commands/config/blacklist.ts +++ b/src/commands/config/blacklist.ts @@ -1,5 +1,5 @@ import { AllowedMentions, BushCommand, type ArgType, type BushMessage, type BushSlashMessage } from '#lib'; -import { User } from 'discord.js'; +import { ApplicationCommandOptionType, Permissions, User } from 'discord.js'; export default class BlacklistCommand extends BushCommand { public constructor() { @@ -15,7 +15,7 @@ export default class BlacklistCommand extends BushCommand { description: 'Whether to blacklist or unblacklist the target.', readableType: "'blacklist'|'unblacklist'", prompt: 'Would you like to add or remove someone or something from/to the blacklist?', - slashType: 'STRING', + slashType: ApplicationCommandOptionType.String, choices: ['blacklist', 'unblacklist'].map((c) => ({ name: c, value: c })), only: 'slash' }, @@ -26,7 +26,7 @@ export default class BlacklistCommand extends BushCommand { readableType: 'channel|user', prompt: 'What channel or user that you would like to blacklist/unblacklist?', retry: '{error} Pick a valid user or channel.', - slashType: 'STRING' + slashType: ApplicationCommandOptionType.String }, { id: 'global', @@ -42,7 +42,7 @@ export default class BlacklistCommand extends BushCommand { slash: true, channel: 'guild', clientPermissions: (m) => util.clientSendAndPermCheck(m), - userPermissions: ['MANAGE_GUILD'] + userPermissions: [Permissions.FLAGS.MANAGE_GUILD] }); } diff --git a/src/commands/config/config.ts b/src/commands/config/config.ts index 6e08cc3..41bdc04 100644 --- a/src/commands/config/config.ts +++ b/src/commands/config/config.ts @@ -9,16 +9,20 @@ import { type GuildSettingType } from '#lib'; import assert from 'assert'; -import { type ArgumentOptions, type Flag } from 'discord-akairo'; +import { SlashOption, type ArgumentOptions, type Flag } from 'discord-akairo'; import { + ActionRow, + ApplicationCommandOptionType, + ButtonComponent, + ButtonStyle, Channel, Formatters, GuildMember, - MessageActionRow, - MessageButton, MessageEmbed, - MessageSelectMenu, + Permissions, Role, + SelectMenuComponent, + SelectMenuOption, User, type Message, type MessageComponentInteraction, @@ -37,33 +41,45 @@ export default class ConfigCommand extends BushCommand { ], examples: ['settings', 'config prefix set -'], slash: true, - slashOptions: settingsArr.map((setting) => { + slashOptions: settingsArr.map((setting): SlashOption => { const obj = guildSettingsObj[setting]; const type = obj.type; const baseTypeUpper = type.replace('-array', '').toUpperCase() as SlashArgType; const isArray = type.includes('-array'); const loweredName = obj.name.toLowerCase(); + const enumType = + baseTypeUpper === 'CHANNEL' + ? ApplicationCommandOptionType.Channel + : baseTypeUpper === 'ROLE' + ? ApplicationCommandOptionType.Role + : baseTypeUpper === 'STRING' + ? ApplicationCommandOptionType.String + : baseTypeUpper === 'USER' + ? ApplicationCommandOptionType.User + : new Error(`Unknown type: ${type}`); + if (enumType instanceof Error) throw enumType; + return { name: _.snakeCase(setting), description: `Manage the server's ${loweredName}`, - type: 'SUB_COMMAND_GROUP', + type: ApplicationCommandOptionType.SubcommandGroup, options: isArray ? [ { name: 'view', description: `View the server's ${loweredName}.`, - type: 'SUB_COMMAND' + type: ApplicationCommandOptionType.Subcommand }, { name: 'add', description: `Add a value to the server's ${loweredName}.`, - type: 'SUB_COMMAND', + type: ApplicationCommandOptionType.Subcommand, options: [ { name: 'value', description: `What would you like to add to the server's ${loweredName}?'`, - type: baseTypeUpper, + type: enumType, channelTypes: baseTypeUpper === 'CHANNEL' && obj.subType ? obj.subType : undefined, required: true } @@ -72,12 +88,12 @@ export default class ConfigCommand extends BushCommand { { name: 'remove', description: `Remove a value from the server's ${loweredName}.`, - type: 'SUB_COMMAND', + type: ApplicationCommandOptionType.Subcommand, options: [ { name: 'value', description: `What would you like to remove from the server's ${loweredName}?'`, - type: baseTypeUpper, + type: enumType, channelTypes: baseTypeUpper === 'CHANNEL' && obj.subType ? obj.subType : undefined, required: true } @@ -88,17 +104,17 @@ export default class ConfigCommand extends BushCommand { { name: 'view', description: `View the server's ${loweredName}.`, - type: 'SUB_COMMAND' + type: ApplicationCommandOptionType.Subcommand }, { name: 'set', description: `Set the server's ${loweredName}.`, - type: 'SUB_COMMAND', + type: ApplicationCommandOptionType.Subcommand, options: [ { name: 'value', description: `What would you like to set the server's ${loweredName} to?'`, - type: baseTypeUpper, + type: enumType, channelTypes: baseTypeUpper === 'CHANNEL' && obj.subType ? obj.subType : undefined, required: true } @@ -109,7 +125,7 @@ export default class ConfigCommand extends BushCommand { }), channel: 'guild', clientPermissions: (m) => util.clientSendAndPermCheck(m), - userPermissions: ['MANAGE_GUILD'] + userPermissions: [Permissions.FLAGS.MANAGE_GUILD] }); } @@ -192,8 +208,8 @@ export default class ConfigCommand extends BushCommand { } ) { if (!message.guild) return await message.util.reply(`${util.emojis.error} This command can only be used in servers.`); - if (!message.member?.permissions.has('MANAGE_GUILD') && !message.member?.user.isOwner()) - return await message.util.reply(`${util.emojis.error} You must have the **MANAGE_GUILD** permission to run this command.`); + if (!message.member?.permissions.has(Permissions.FLAGS.MANAGE_GUILD) && !message.member?.user.isOwner()) + return await message.util.reply(`${util.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; @@ -278,14 +294,15 @@ export default class ConfigCommand extends BushCommand { const desc = settingsArr.map((s) => `:wrench: **${guildSettingsObj[s].name}**`).join('\n'); settingsEmbed.setDescription(desc); - const selMenu = new MessageActionRow().addComponents( - new MessageSelectMenu() + const selMenu = new ActionRow().addComponents( + new SelectMenuComponent() .addOptions( - ...settingsArr.map((s) => ({ - label: guildSettingsObj[s].name, - value: s, - description: guildSettingsObj[s].description - })) + ...settingsArr.map((s) => + new SelectMenuOption() + .setLabel(guildSettingsObj[s].name) + .setValue(s) + .setDescription(guildSettingsObj[s].description) + ) ) .setPlaceholder('Select A Setting to View') .setMaxValues(1) @@ -335,8 +352,8 @@ export default class ConfigCommand extends BushCommand { : '[No Value Set]'; }; - const components = new MessageActionRow().addComponents( - new MessageButton().setStyle('PRIMARY').setCustomId('command_settingsBack').setLabel('Back') + const components = new ActionRow().addComponents( + new ButtonComponent().setStyle(ButtonStyle.Primary).setCustomId('command_settingsBack').setLabel('Back') ); settingsEmbed.setDescription( `${Formatters.italic(guildSettingsObj[setting].description)}\n\n**Type**: ${guildSettingsObj[setting].type}` diff --git a/src/commands/config/disable.ts b/src/commands/config/disable.ts index 564f90f..d59ff55 100644 --- a/src/commands/config/disable.ts +++ b/src/commands/config/disable.ts @@ -1,6 +1,6 @@ import { AllowedMentions, BushCommand, type ArgType, type BushMessage, type BushSlashMessage } from '#lib'; import assert from 'assert'; -import { AutocompleteInteraction } from 'discord.js'; +import { ApplicationCommandOptionType, AutocompleteInteraction, Permissions } from 'discord.js'; import Fuse from 'fuse.js'; assert(Fuse); @@ -20,7 +20,7 @@ export default class DisableCommand extends BushCommand { description: 'Whether to disable or enable the command.', readableType: "'disable'|'enable", prompt: 'Would you like to disable or enable a command?', - slashType: 'STRING', + slashType: ApplicationCommandOptionType.String, choices: ['disable', 'enable'].map((v) => ({ name: v, value: v })), only: 'slash' }, @@ -31,7 +31,7 @@ export default class DisableCommand extends BushCommand { readableType: 'command|commandAlias', prompt: 'What command would you like to enable/disable?', retry: '{error} Pick a valid command.', - slashType: 'STRING', + slashType: ApplicationCommandOptionType.String, autocomplete: true }, { @@ -48,7 +48,7 @@ export default class DisableCommand extends BushCommand { slash: true, channel: 'guild', clientPermissions: (m) => util.clientSendAndPermCheck(m), - userPermissions: ['MANAGE_GUILD'] + userPermissions: [Permissions.FLAGS.MANAGE_GUILD] }); } diff --git a/src/commands/config/features.ts b/src/commands/config/features.ts index 894c90a..fdd6c1e 100644 --- a/src/commands/config/features.ts +++ b/src/commands/config/features.ts @@ -6,7 +6,16 @@ import { type BushSlashMessage, type GuildFeatures } from '#lib'; -import { MessageActionRow, MessageEmbed, MessageSelectMenu, type Message, type SelectMenuInteraction } from 'discord.js'; +import { + ActionRow, + ComponentType, + MessageEmbed, + Permissions, + SelectMenuComponent, + SelectMenuOption, + type Message, + type SelectMenuInteraction +} from 'discord.js'; export default class FeaturesCommand extends BushCommand { public constructor() { @@ -18,8 +27,8 @@ export default class FeaturesCommand extends BushCommand { examples: ['features'], slash: true, channel: 'guild', - clientPermissions: (m) => util.clientSendAndPermCheck(m, ['EMBED_LINKS'], true), - userPermissions: ['MANAGE_GUILD'] + clientPermissions: (m) => util.clientSendAndPermCheck(m, [Permissions.FLAGS.EMBED_LINKS], true), + userPermissions: [Permissions.FLAGS.MANAGE_GUILD] }); } @@ -33,7 +42,7 @@ export default class FeaturesCommand extends BushCommand { const components = this.generateComponents(guildFeaturesArr, false); const msg = (await message.util.reply({ embeds: [featureEmbed], components: [components] })) as Message; const collector = msg.createMessageComponentCollector({ - componentType: 'SELECT_MENU', + componentType: ComponentType.SelectMenu, time: 300_000, filter: (i) => i.guildId === msg.guildId && i.message?.id === msg.id }); @@ -74,19 +83,17 @@ export default class FeaturesCommand extends BushCommand { } public generateComponents(guildFeatures: GuildFeatures[], disable: boolean) { - return new MessageActionRow().addComponents( - new MessageSelectMenu({ - customId: 'command_selectFeature', - disabled: disable, - maxValues: 1, - minValues: 1, - options: guildFeatures.map((f) => ({ - label: guildFeaturesObj[f].name, - value: f, - description: guildFeaturesObj[f].description - })), - placeholder: 'Select A Feature to Toggle' - }) + return new ActionRow().addComponents( + new SelectMenuComponent() + .setCustomId('command_selectFeature') + .setDisabled(disable) + .setMaxValues(1) + .setMinValues(1) + .setOptions( + guildFeatures.map((f) => + new SelectMenuOption().setLabel(guildFeaturesObj[f].name).setValue(f).setDescription(guildFeaturesObj[f].description) + ) + ) ); } } diff --git a/src/commands/config/log.ts b/src/commands/config/log.ts index 3072866..5906623 100644 --- a/src/commands/config/log.ts +++ b/src/commands/config/log.ts @@ -1,5 +1,6 @@ import { BushCommand, guildLogsArr, type ArgType, type BushMessage, type BushSlashMessage, type GuildLogType } from '#lib'; import { type ArgumentOptions, type Flag } from 'discord-akairo'; +import { ApplicationCommandOptionType, Permissions } from 'discord.js'; export default class LogCommand extends BushCommand { public constructor() { @@ -15,7 +16,7 @@ export default class LogCommand extends BushCommand { id: 'log_type', description: 'The log type to change.', prompt: 'What log type would you like to change?', - slashType: 'STRING', + slashType: ApplicationCommandOptionType.String, choices: guildLogsArr.map((log) => ({ name: log, value: log })), only: 'slash' }, @@ -24,14 +25,14 @@ export default class LogCommand extends BushCommand { description: 'The channel to have logs of the selected type to be sent in.', type: 'channel', prompt: 'What channel would you like these logs to be sent in?', - slashType: 'CHANNEL', - channelTypes: ['GUILD_TEXT', 'GUILD_NEWS', 'GUILD_NEWS_THREAD', 'GUILD_PUBLIC_THREAD', 'GUILD_PRIVATE_THREAD'], + slashType: ApplicationCommandOptionType.Channel, + channelTypes: ['GuildText', 'GuildNews', 'GuildNewsThread', 'GuildPublicThread', 'GuildPrivateThread'], only: 'slash' } ], channel: 'guild', clientPermissions: (m) => util.clientSendAndPermCheck(m), - userPermissions: ['MANAGE_GUILD'] + userPermissions: [Permissions.FLAGS.MANAGE_GUILD] }); } diff --git a/src/commands/dev/__template.ts b/src/commands/dev/__template.ts index 6adba08..7ea1784 100644 --- a/src/commands/dev/__template.ts +++ b/src/commands/dev/__template.ts @@ -1,4 +1,5 @@ import { BushCommand, type ArgType, type BushMessage, type BushSlashMessage, type OptionalArgType } from '#lib'; +import { ApplicationCommandOptionType } from 'discord.js'; export default class TemplateCommand extends BushCommand { public constructor() { @@ -15,7 +16,7 @@ export default class TemplateCommand extends BushCommand { type: 'string', prompt: 'What would you like to set your first argument to be?', retry: '{error} Pick a valid argument.', - slashType: 'STRING' + slashType: ApplicationCommandOptionType.String }, { id: 'optional_argument', @@ -24,7 +25,7 @@ export default class TemplateCommand extends BushCommand { prompt: 'What would you like to set your second argument to be?', retry: '{error} Pick a valid argument.', optional: true, - slashType: 'STRING' + slashType: ApplicationCommandOptionType.String } ], slash: false, //set this to true diff --git a/src/commands/dev/debug.ts b/src/commands/dev/debug.ts new file mode 100644 index 0000000..f8c614d --- /dev/null +++ b/src/commands/dev/debug.ts @@ -0,0 +1,79 @@ +// import { BushCommand, type ArgType, type BushMessage, type BushSlashMessage } from '#lib'; +// import { ApplicationCommandOptionType, AutocompleteInteraction, ChatInputCommandInteraction } from 'discord.js'; +// import Fuse from 'fuse.js'; + +// export default class DebugCommand extends BushCommand { +// public constructor() { +// super('debug', { +// aliases: ['debug'], +// category: 'debug', +// description: 'Command description.', +// usage: ['template [optionalArg]'], +// examples: ['template 1 2'], +// args: [ +// { +// id: 'action', +// description: 'Debug action.', +// type: 'string', +// prompt: 'Debug action.', +// retry: '{error} Pick valid action.', +// slashType: ApplicationCommandOptionType.String, +// autocomplete: true +// } +// ], +// slash: true, +// slashGuilds: ['516977525906341928'], +// superUserOnly: true, +// clientPermissions: (m) => util.clientSendAndPermCheck(m), +// userPermissions: [] +// }); +// } + +// public override async exec(message: BushMessage | BushSlashMessage, args: { action: ArgType<'string'> }) { +// if (args.action === 'util.reply') { +// return await message.util.reply(`This is a util.reply`); +// } else if (args.action === 'util.reply-object') { +// return await message.util.reply({ +// content: `This is a util.reply with object parameters`, +// embeds: [{ description: 'And an embed' }] +// }); +// } else if (args.action === 'util.send') { +// return await message.util.send(`This is a util.send`); +// } else if (args.action === 'util.send-object') { +// return await message.util.send({ +// content: `This is a util.send with object parameters`, +// embeds: [{ description: 'And an embed' }] +// }); +// } else if (args.action === 'interaction.reply') { +// return await (message.interaction as ChatInputCommandInteraction).reply(`This is a interaction.reply`); +// } else if (args.action === 'interaction.reply-object') { +// return await (message.interaction as ChatInputCommandInteraction).reply({ +// content: `This is a interaction.reply with object parameters`, +// embeds: [{ description: 'And an embed' }] +// }); +// } else { +// return await message.util.reply(`${util.emojis.error} Invalid action.`); +// } +// } + +// public override autocomplete(interaction: AutocompleteInteraction) { +// const actions = [ +// 'util.reply', +// 'util.reply-object', +// 'util.send', +// 'util.send-object', +// 'interaction.reply', +// 'interaction.reply-object' +// ]; + +// const fuzzy = new Fuse(actions, { +// threshold: 0.5, +// isCaseSensitive: false, +// findAllMatches: true +// }).search(interaction.options.getFocused().toString()); + +// const res = fuzzy.slice(0, fuzzy.length >= 25 ? 25 : undefined).map((v) => ({ name: v.item, value: v.item })); + +// void interaction.respond(res.length ? res : actions.map((v) => ({ name: v, value: v }))); +// } +// } diff --git a/src/commands/dev/dm.ts b/src/commands/dev/dm.ts index d702875..0646f59 100644 --- a/src/commands/dev/dm.ts +++ b/src/commands/dev/dm.ts @@ -1,4 +1,5 @@ import { BushCommand, type ArgType, type BushMessage, type BushSlashMessage } from '#lib'; +import { ApplicationCommandOptionType } from 'discord.js'; export default class DMCommand extends BushCommand { public constructor() { @@ -15,7 +16,7 @@ export default class DMCommand extends BushCommand { description: 'The user to send the dm to.', prompt: 'Who would you like to dm?', retry: '{error} Pick a valid user to send a dm to.', - slashType: 'STRING' + slashType: ApplicationCommandOptionType.String }, { id: 'content', @@ -24,7 +25,7 @@ export default class DMCommand extends BushCommand { description: 'The content to send to the user.', prompt: 'What would you like to send to the user?', retry: '{error} Pick something to send the user.', - slashType: 'STRING' + slashType: ApplicationCommandOptionType.String } ], slash: false, @@ -34,6 +35,7 @@ export default class DMCommand extends BushCommand { userPermissions: [] }); } + public override async exec( message: BushMessage | BushSlashMessage, args: { user: ArgType<'user'>; content: ArgType<'string'> } diff --git a/src/commands/dev/eval.ts b/src/commands/dev/eval.ts index 656eeff..92b1117 100644 --- a/src/commands/dev/eval.ts +++ b/src/commands/dev/eval.ts @@ -12,26 +12,28 @@ import { StickyRole, type ArgType } from '#lib'; +import { Snowflake as Snowflake_ } from '@sapphire/snowflake'; import { Canvas } from 'canvas'; import { exec } from 'child_process'; import { + ActionRow, + ApplicationCommandOptionType, + ButtonComponent, ButtonInteraction, Collection, Collector, CommandInteraction, - ContextMenuInteraction, + ContextMenuCommandInteraction, DMChannel, Emoji, Interaction, InteractionCollector, Message, - MessageActionRow, MessageAttachment, - MessageButton, MessageCollector, MessageEmbed, - MessageSelectMenu, ReactionCollector, + SelectMenuComponent, Util } from 'discord.js'; import ts from 'typescript'; @@ -39,7 +41,8 @@ import { promisify } from 'util'; const { transpile } = ts, emojis = util.emojis, colors = util.colors, - sh = promisify(exec); + sh = promisify(exec), + SnowflakeUtil = new Snowflake_(1420070400000n); /* eslint-enable @typescript-eslint/no-unused-vars */ export default class EvalCommand extends BushCommand { @@ -57,7 +60,7 @@ export default class EvalCommand extends BushCommand { match: 'rest', prompt: 'What would you like to eval?', retry: '{error} Invalid code to eval.', - slashType: 'STRING' + slashType: ApplicationCommandOptionType.String }, { id: 'sel_depth', @@ -67,7 +70,7 @@ export default class EvalCommand extends BushCommand { flag: '--depth', default: 0, prompt: 'How deep would you like to inspect the output?', - slashType: 'INTEGER', + slashType: ApplicationCommandOptionType.Integer, optional: true }, { @@ -76,7 +79,7 @@ export default class EvalCommand extends BushCommand { match: 'flag', flag: '--sudo', prompt: 'Would you like to override checks?', - slashType: 'BOOLEAN', + slashType: ApplicationCommandOptionType.Boolean, optional: true }, { @@ -95,7 +98,7 @@ export default class EvalCommand extends BushCommand { match: 'flag', flag: '--silent', prompt: 'Would you like to make the response silent?', - slashType: 'BOOLEAN', + slashType: ApplicationCommandOptionType.Boolean, optional: true }, { @@ -104,7 +107,7 @@ export default class EvalCommand extends BushCommand { match: 'flag', flag: '--ts', prompt: 'Is this code written in typescript?', - slashType: 'BOOLEAN', + slashType: ApplicationCommandOptionType.Boolean, optional: true }, { @@ -113,7 +116,7 @@ export default class EvalCommand extends BushCommand { match: 'flag', flag: '--hidden', prompt: 'Would you like to show hidden items?', - slashType: 'BOOLEAN', + slashType: ApplicationCommandOptionType.Boolean, optional: true }, { @@ -122,7 +125,7 @@ export default class EvalCommand extends BushCommand { match: 'flag', flag: '--proto', prompt: 'Would you like to show the prototype of the output?', - slashType: 'BOOLEAN', + slashType: ApplicationCommandOptionType.Boolean, optional: true }, { @@ -131,7 +134,7 @@ export default class EvalCommand extends BushCommand { match: 'flag', flag: ['--func', '--function', '--functions', '--meth', '--method', '--methods'], prompt: 'Would you like to inspect the prototype chain to find methods?', - slashType: 'BOOLEAN', + slashType: ApplicationCommandOptionType.Boolean, optional: true }, { @@ -140,7 +143,7 @@ export default class EvalCommand extends BushCommand { match: 'flag', flag: '--async', prompt: 'Would you like to wrap the code in an async function?', - slashType: 'BOOLEAN', + slashType: ApplicationCommandOptionType.Boolean, optional: true }, { @@ -149,7 +152,7 @@ export default class EvalCommand extends BushCommand { match: 'flag', flag: ['--strings', '--string'], prompt: 'Would you like to not inspect strings?', - slashType: 'BOOLEAN', + slashType: ApplicationCommandOptionType.Boolean, optional: true } ], @@ -242,9 +245,7 @@ export default class EvalCommand extends BushCommand { embed.addField('📤 Error', await util.inspectCleanRedactCodeblock(e, 'js')); } - embed - .setTimestamp() - .setFooter({ text: message.author.tag, iconURL: message.author.displayAvatarURL({ dynamic: true }) ?? undefined }); + embed.setTimestamp().setFooter({ text: message.author.tag, iconURL: message.author.displayAvatarURL() ?? undefined }); if (!args.silent || message.util.isSlashMessage(message)) { await message.util.reply({ embeds: [embed] }); @@ -260,4 +261,4 @@ export default class EvalCommand extends BushCommand { } } -/** @typedef {ActivePunishment|Global|Guild|Level|ModLog|StickyRole|ButtonInteraction|Collection|Collector|CommandInteraction|ContextMenuInteraction|DMChannel|Emoji|Interaction|InteractionCollector|Message|MessageActionRow|MessageAttachment|MessageButton|MessageCollector|MessageSelectMenu|ReactionCollector|Util|Canvas|Shared} VSCodePleaseDontRemove */ +/** @typedef {ActivePunishment|Global|Guild|Level|ModLog|StickyRole|ButtonInteraction|Collection|Collector|CommandInteraction|ContextMenuCommandInteraction|DMChannel|Emoji|Interaction|InteractionCollector|Message|ActionRow|MessageAttachment|ButtonComponent|MessageCollector|SelectMenuComponent|ReactionCollector|Util|Canvas|Shared} VSCodePleaseDontRemove */ diff --git a/src/commands/dev/javascript.ts b/src/commands/dev/javascript.ts index c8113aa..9d6a20b 100644 --- a/src/commands/dev/javascript.ts +++ b/src/commands/dev/javascript.ts @@ -1,6 +1,6 @@ import { BushCommand, type ArgType, type BushMessage, type BushSlashMessage } from '#lib'; import assert from 'assert'; -import { MessageEmbed } from 'discord.js'; +import { ApplicationCommandOptionType, MessageEmbed } from 'discord.js'; import { VM } from 'vm2'; assert(VM); @@ -19,7 +19,7 @@ export default class JavascriptCommand extends BushCommand { match: 'rest', prompt: 'What code would you like to run in a sand boxed environment?', retry: '{error} Invalid code to run in a sand boxed environment.', - slashType: 'STRING' + slashType: ApplicationCommandOptionType.String }, { id: 'sel_depth', @@ -29,7 +29,7 @@ export default class JavascriptCommand extends BushCommand { flag: '--depth', default: 0, prompt: 'How deep would you like to inspect the output?', - slashType: 'INTEGER', + slashType: ApplicationCommandOptionType.Integer, optional: true } ], @@ -75,9 +75,7 @@ export default class JavascriptCommand extends BushCommand { embed.addField('📤 Error', await util.inspectCleanRedactCodeblock(e, 'js')); } - embed - .setTimestamp() - .setFooter({ text: message.author.tag, iconURL: message.author.displayAvatarURL({ dynamic: true }) ?? undefined }); + embed.setTimestamp().setFooter({ text: message.author.tag, iconURL: message.author.displayAvatarURL() ?? undefined }); await message.util.reply({ embeds: [embed] }); } diff --git a/src/commands/dev/reload.ts b/src/commands/dev/reload.ts index 6d030b7..d874c83 100644 --- a/src/commands/dev/reload.ts +++ b/src/commands/dev/reload.ts @@ -16,7 +16,7 @@ export default class ReloadCommand extends BushCommand { // flag: '--fast', // prompt: 'Would you like to use esbuild for fast compiling?', // optional: true, - // slashType:'BOOLEAN' + // slashType: ApplicationCommandOptionType.Boolean // } // ], ownerOnly: true, diff --git a/src/commands/dev/say.ts b/src/commands/dev/say.ts index 2c8151f..bbada0c 100644 --- a/src/commands/dev/say.ts +++ b/src/commands/dev/say.ts @@ -1,4 +1,5 @@ import { AllowedMentions, BushCommand, type BushMessage, type BushSlashMessage } from '#lib'; +import { ApplicationCommandOptionType } from 'discord.js'; export default class SayCommand extends BushCommand { public constructor() { @@ -16,7 +17,7 @@ export default class SayCommand extends BushCommand { match: 'rest', prompt: 'What would you like the bot to say?', retry: '{error} Choose something for the bot to send.', - slashType: 'STRING' + slashType: ApplicationCommandOptionType.String } ], ownerOnly: true, diff --git a/src/commands/dev/sh.ts b/src/commands/dev/sh.ts index 9956897..f74dedf 100644 --- a/src/commands/dev/sh.ts +++ b/src/commands/dev/sh.ts @@ -2,8 +2,9 @@ import { BushCommand, type BushMessage, type BushSlashMessage } from '#lib'; import assert from 'assert'; import chalk from 'chalk'; import { exec } from 'child_process'; -import { MessageEmbed, Util } from 'discord.js'; +import { ApplicationCommandOptionType, MessageEmbed, Util } from 'discord.js'; import { promisify } from 'util'; + assert(chalk); const sh = promisify(exec); @@ -30,7 +31,7 @@ export default class ShCommand extends BushCommand { match: 'rest', prompt: 'What would you like run', retry: '{error} Invalid command to run.', - slashType: 'STRING' + slashType: ApplicationCommandOptionType.String } ], ownerOnly: true, @@ -46,7 +47,7 @@ export default class ShCommand extends BushCommand { const embed = new MessageEmbed() .setColor(util.colors.gray) - .setFooter({ text: message.author.tag, iconURL: message.author.avatarURL({ dynamic: true }) ?? undefined }) + .setFooter({ text: message.author.tag, iconURL: message.author.avatarURL() ?? undefined }) .setTimestamp() .setTitle('Shell Command') .addField('📥 Input', await util.codeblock(input, 1024, 'sh', true)) diff --git a/src/commands/dev/test.ts b/src/commands/dev/test.ts index 1ec7f71..63c1112 100644 --- a/src/commands/dev/test.ts +++ b/src/commands/dev/test.ts @@ -1,6 +1,13 @@ import { BushCommand, ButtonPaginator, Shared, type BushMessage } from '#lib'; -import { MessageActionRow, MessageButton, MessageEmbed, type ApplicationCommand, type Collection } from 'discord.js'; -import { MessageButtonStyles } from 'discord.js/typings/enums'; +import { + ActionRow, + ActionRowComponent, + ButtonComponent, + ButtonStyle, + MessageEmbed, + type ApplicationCommand, + type Collection +} from 'discord.js'; import badLinksSecretArray from '../../lib/badlinks-secret.js'; import badLinksArray from '../../lib/badlinks.js'; import badWords from '../../lib/badwords.js'; @@ -44,12 +51,12 @@ export default class TestCommand extends BushCommand { } if (['button', 'buttons'].includes(args?.feature?.toLowerCase())) { - const ButtonRow = new MessageActionRow().addComponents( - new MessageButton({ style: MessageButtonStyles.PRIMARY, customId: 'primaryButton', label: 'Primary' }), - new MessageButton({ style: MessageButtonStyles.SECONDARY, customId: 'secondaryButton', label: 'Secondary' }), - new MessageButton({ style: MessageButtonStyles.SUCCESS, customId: 'success', label: 'Success' }), - new MessageButton({ style: MessageButtonStyles.DANGER, customId: 'danger', label: 'Danger' }), - new MessageButton({ style: MessageButtonStyles.LINK, label: 'Link', url: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ' }) + const ButtonRow = new ActionRow().addComponents( + new ButtonComponent().setStyle(ButtonStyle.Primary).setCustomId('primaryButton').setLabel('Primary'), + new ButtonComponent().setStyle(ButtonStyle.Secondary).setCustomId('secondaryButton').setLabel('Secondary'), + new ButtonComponent().setStyle(ButtonStyle.Success).setCustomId('successButton').setLabel('Success'), + new ButtonComponent().setStyle(ButtonStyle.Danger).setCustomId('dangerButton').setLabel('Danger'), + new ButtonComponent().setStyle(ButtonStyle.Link).setLabel('Link').setURL('https://www.youtube.com/watch?v=dQw4w9WgXcQ') ); return await message.util.reply({ content: 'buttons', components: [ButtonRow] }); } else if (['embed', 'button embed'].includes(args?.feature?.toLowerCase())) { @@ -67,25 +74,17 @@ export default class TestCommand extends BushCommand { ) .setTitle('Title'); - const buttonRow = new MessageActionRow().addComponents( - new MessageButton({ - style: MessageButtonStyles.LINK, - label: 'Link', - url: 'https://www.google.com/' - }) + const buttonRow = new ActionRow().addComponents( + new ButtonComponent().setStyle(ButtonStyle.Link).setLabel('Link').setURL('https://google.com/') ); return await message.util.reply({ content: 'Test', embeds: [embed], components: [buttonRow] }); } else if (['lots of buttons'].includes(args?.feature?.toLowerCase())) { - const ButtonRows: MessageActionRow[] = []; + const ButtonRows: ActionRow[] = []; for (let a = 1; a <= 5; a++) { - const row = new MessageActionRow(); + const row = new ActionRow(); for (let b = 1; b <= 5; b++) { const id = (a + 5 * (b - 1)).toString(); - const button = new MessageButton({ - style: MessageButtonStyles.SECONDARY, - customId: id, - label: id - }); + const button = new ButtonComponent().setStyle(ButtonStyle.Primary).setCustomId(id).setLabel(id); row.addComponents(button); } ButtonRows.push(row); @@ -99,39 +98,25 @@ export default class TestCommand extends BushCommand { return await ButtonPaginator.send(message, embeds); } else if (['lots of embeds'].includes(args?.feature?.toLowerCase())) { const description = 'This is a description.'; - const _avatar = message.author.avatarURL({ dynamic: true }) ?? undefined; + const _avatar = message.author.avatarURL() ?? undefined; const author = { name: 'This is a author', iconURL: _avatar }; const footer = { text: 'This is a footer', iconURL: _avatar }; - const fields = []; - for (let i = 0; i < 25; i++) { - fields.push({ name: `Field ${i}`, value: `Field Value ${i}` }); - } + const fields = Array(25) + .fill(0) + .map((_, i) => ({ name: `Field ${i}`, value: 'Field Value' })); const c = util.colors; const o = { description, author, footer, fields, time: Date.now() }; - const embeds = [ - { ...o, title: 'Embed Title 0', color: c.red }, - { ...o, title: 'Embed Title 1', color: c.orange }, - { ...o, title: 'Embed Title 2', color: c.gold }, - { ...o, title: 'Embed Title 3', color: c.yellow }, - { ...o, title: 'Embed Title 4', color: c.green }, - { ...o, title: 'Embed Title 5', color: c.darkGreen }, - { ...o, title: 'Embed Title 6', color: c.aqua }, - { ...o, title: 'Embed Title 7', color: c.blue }, - { ...o, title: 'Embed Title 8', color: c.purple }, - { ...o, title: 'Embed Title 9', color: c.pink } - ]; + const colors = [c.red, c.orange, c.gold, c.yellow, c.green, c.darkGreen, c.aqua, c.blue, c.purple, c.pink]; + + const embeds = colors.map((c, i) => ({ ...o, title: `Embed Title ${i}`, color: c })); - const ButtonRows: MessageActionRow[] = []; + const ButtonRows: ActionRow[] = []; for (let a = 1; a <= 5; a++) { - const row = new MessageActionRow(); + const row = new ActionRow(); for (let b = 1; b <= 5; b++) { const id = (a + 5 * (b - 1)).toString(); - const button = new MessageButton({ - style: MessageButtonStyles.SECONDARY, - customId: id, - label: id - }); + const button = new ButtonComponent().setStyle(ButtonStyle.Secondary).setCustomId(id).setLabel(id); row.addComponents(button); } ButtonRows.push(row); diff --git a/src/commands/fun/eightBall.ts b/src/commands/fun/eightBall.ts index b4d2fbe..ff06fe5 100644 --- a/src/commands/fun/eightBall.ts +++ b/src/commands/fun/eightBall.ts @@ -1,4 +1,5 @@ import { BushCommand, type BushMessage, type BushSlashMessage } from '#lib'; +import { ApplicationCommandOptionType } from 'discord.js'; export default class EightBallCommand extends BushCommand { public constructor() { @@ -16,7 +17,7 @@ export default class EightBallCommand extends BushCommand { match: 'rest', prompt: 'What question would you like answered?', retry: '{error} Invalid question.', - slashType: 'STRING' + slashType: ApplicationCommandOptionType.String } ], slash: true, diff --git a/src/commands/fun/minesweeper.ts b/src/commands/fun/minesweeper.ts index 6878c05..b9737a3 100644 --- a/src/commands/fun/minesweeper.ts +++ b/src/commands/fun/minesweeper.ts @@ -1,6 +1,7 @@ import { BushCommand, type ArgType, type BushMessage, type BushSlashMessage } from '#lib'; import { Minesweeper } from '@notenoughupdates/discord.js-minesweeper'; import assert from 'assert'; +import { ApplicationCommandOptionType } from 'discord.js'; assert(Minesweeper); export default class MinesweeperCommand extends BushCommand { @@ -20,7 +21,7 @@ export default class MinesweeperCommand extends BushCommand { retry: '{error} Choose a valid number of rows', optional: true, default: 9, - slashType: 'INTEGER' + slashType: ApplicationCommandOptionType.Integer }, { id: 'columns', @@ -30,7 +31,7 @@ export default class MinesweeperCommand extends BushCommand { retry: '{error} Choose a valid number of columns', optional: true, default: 9, - slashType: 'INTEGER' + slashType: ApplicationCommandOptionType.Integer }, { id: 'mines', @@ -40,7 +41,7 @@ export default class MinesweeperCommand extends BushCommand { retry: '{error} Choose a valid number of mines', optional: true, default: 10, - slashType: 'INTEGER' + slashType: ApplicationCommandOptionType.Integer }, { id: 'spaces', @@ -48,7 +49,7 @@ export default class MinesweeperCommand extends BushCommand { match: 'flag', flag: '--spaces', prompt: 'Would you like there to be spaces?', - slashType: 'BOOLEAN', + slashType: ApplicationCommandOptionType.Boolean, optional: true }, { @@ -57,7 +58,7 @@ export default class MinesweeperCommand extends BushCommand { match: 'flag', flag: '--revealFirstCell', prompt: 'Would you like to automatically reveal the first cell?', - slashType: 'BOOLEAN', + slashType: ApplicationCommandOptionType.Boolean, optional: true } ], diff --git a/src/commands/info/avatar.ts b/src/commands/info/avatar.ts index ce2543f..58d8bca 100644 --- a/src/commands/info/avatar.ts +++ b/src/commands/info/avatar.ts @@ -1,5 +1,5 @@ import { BushCommand, type ArgType, type BushMessage, type BushSlashMessage } from '#lib'; -import { GuildMember, MessageEmbed } from 'discord.js'; +import { ApplicationCommandOptionType, GuildMember, MessageEmbed, Permissions } from 'discord.js'; export default class AvatarCommand extends BushCommand { constructor() { @@ -18,10 +18,10 @@ export default class AvatarCommand extends BushCommand { prompt: 'Who would you like to see the avatar of?', retry: '{error} Choose a valid user.', optional: true, - slashType: 'USER' + slashType: ApplicationCommandOptionType.User } ], - clientPermissions: (m) => util.clientSendAndPermCheck(m, ['EMBED_LINKS'], true), + clientPermissions: (m) => util.clientSendAndPermCheck(m, [Permissions.FLAGS.EMBED_LINKS], true), userPermissions: [], slash: true }); diff --git a/src/commands/info/botInfo.ts b/src/commands/info/botInfo.ts index fa572e8..3aea3cd 100644 --- a/src/commands/info/botInfo.ts +++ b/src/commands/info/botInfo.ts @@ -1,6 +1,6 @@ import { BushCommand, type BushMessage, type BushSlashMessage } from '#lib'; import assert from 'assert'; -import { MessageEmbed, version as discordJSVersion } from 'discord.js'; +import { MessageEmbed, Permissions, version as discordJSVersion } from 'discord.js'; import * as os from 'os'; const { default: prettyBytes } = await import('pretty-bytes'); assert(prettyBytes); @@ -15,7 +15,7 @@ export default class BotInfoCommand extends BushCommand { usage: ['bot-info'], examples: ['bot-info'], slash: true, - clientPermissions: (m) => util.clientSendAndPermCheck(m, ['EMBED_LINKS'], true), + clientPermissions: (m) => util.clientSendAndPermCheck(m, [Permissions.FLAGS.EMBED_LINKS], true), userPermissions: [] }); } diff --git a/src/commands/info/color.ts b/src/commands/info/color.ts index 5b2c818..d385c53 100644 --- a/src/commands/info/color.ts +++ b/src/commands/info/color.ts @@ -9,7 +9,7 @@ import { type BushSlashMessage } from '#lib'; import assert from 'assert'; -import { MessageEmbed, Role } from 'discord.js'; +import { ApplicationCommandOptionType, MessageEmbed, Permissions, Role } from 'discord.js'; import tinycolor from 'tinycolor2'; assert(tinycolor); @@ -36,11 +36,11 @@ export default class ColorCommand extends BushCommand { match: 'restContent', prompt: 'What color code, role, or user would you like to find the color of?', retry: '{error} Choose a valid color, role, or member.', - slashType: 'STRING' + slashType: ApplicationCommandOptionType.String } ], channel: 'guild', - clientPermissions: (m) => util.clientSendAndPermCheck(m, ['EMBED_LINKS'], true), + clientPermissions: (m) => util.clientSendAndPermCheck(m, [Permissions.FLAGS.EMBED_LINKS], true), userPermissions: [] }); } diff --git a/src/commands/info/guildInfo.ts b/src/commands/info/guildInfo.ts index 7d3d170..afc5111 100644 --- a/src/commands/info/guildInfo.ts +++ b/src/commands/info/guildInfo.ts @@ -1,9 +1,14 @@ import { BushCommand, type ArgType, type BushMessage, type BushSlashMessage, type OptionalArgType } from '#lib'; import assert from 'assert'; +import { GuildDefaultMessageNotifications, GuildExplicitContentFilter } from 'discord-api-types'; import { - Constants, + ApplicationCommandOptionType, Guild, + GuildMFALevel, + GuildPremiumTier, + GuildVerificationLevel, MessageEmbed, + Permissions, type BaseGuildVoiceChannel, type GuildPreview, type Snowflake, @@ -27,11 +32,11 @@ export default class GuildInfoCommand extends BushCommand { prompt: 'What server would you like to find information about?', retry: '{error} Choose a valid server to find information about.', optional: true, - slashType: 'STRING' + slashType: ApplicationCommandOptionType.String } ], slash: true, - clientPermissions: (m) => util.clientSendAndPermCheck(m, ['EMBED_LINKS'], true), + clientPermissions: (m) => util.clientSendAndPermCheck(m, [Permissions.FLAGS.EMBED_LINKS], true), userPermissions: [] }); } @@ -66,20 +71,20 @@ export default class GuildInfoCommand extends BushCommand { const guildStats: string[] = []; const guildSecurity: string[] = []; const verifiedGuilds = Object.values(client.consts.mappings.guilds); - if (verifiedGuilds.includes(guild.id as typeof verifiedGuilds[number])) emojis.push(otherEmojis.BUSH_VERIFIED); + if (verifiedGuilds.includes(guild.id as typeof verifiedGuilds[number])) emojis.push(otherEmojis.BushVerified); if (!isPreview && guild instanceof Guild) { - if (guild.premiumTier !== 'NONE') emojis.push(otherEmojis[`BOOST_${guild.premiumTier}`]); + if (guild.premiumTier !== 'None') emojis.push(otherEmojis[`Boost${guild.premiumTier}`]); await guild.fetch(); const channels = guild.channels.cache; - const channelTypes = ( - ['GUILD_TEXT', 'GUILD_VOICE', 'GUILD_STAGE_VOICE', 'GUILD_STORE', 'GUILD_CATEGORY', 'THREAD'] as const - ).map((type) => `${otherEmojis[type]} ${channels.filter((channel) => channel.type.includes(type)).size.toLocaleString()}`); + const channelTypes = (['Text', 'Voice', 'News', 'Stage', 'Store', 'Category', 'Thread'] as const).map( + (type) => `${otherEmojis[`Channel${type}`]} ${channels.filter((channel) => channel[`is${type}`]()).size.toLocaleString()}` + ); const guildRegions = [ ...new Set( - guild.channels.cache.filter((c) => c.isVoice()).map((c) => (c as BaseGuildVoiceChannel).rtcRegion ?? 'automatic') + guild.channels.cache.filter((c) => c.isVoiceBased()).map((c) => (c as BaseGuildVoiceChannel).rtcRegion ?? 'automatic') ) ] as RTCRegion[]; @@ -92,48 +97,42 @@ export default class GuildInfoCommand extends BushCommand { `**Regions:** ${guildRegions.map((region) => client.consts.mappings.regions[region] || region).join(', ')}` ); if (guild.premiumSubscriptionCount) - guildAbout.push( - `**Boosts:** Level ${Constants.PremiumTiers[guild.premiumTier]} with ${guild.premiumSubscriptionCount ?? 0} boosts` - ); - if (guild.me?.permissions.has('MANAGE_GUILD') && guild.vanityURLCode) { + guildAbout.push(`**Boosts:** Level ${guild.premiumTier} with ${guild.premiumSubscriptionCount ?? 0} boosts`); + if (guild.me?.permissions.has(Permissions.FLAGS.MANAGE_GUILD) && guild.vanityURLCode) { const vanityInfo: Vanity = await guild.fetchVanityData(); guildAbout.push(`**Vanity URL:** discord.gg/${vanityInfo.code}`, `**Vanity Uses:** ${vanityInfo.uses?.toLocaleString()}`); } - if (guild.icon) guildAbout.push(`**Icon:** [link](${guild.iconURL({ dynamic: true, size: 4096, format: 'png' })})`); + if (guild.icon) guildAbout.push(`**Icon:** [link](${guild.iconURL({ size: 4096, format: 'png' })})`); if (guild.banner) guildAbout.push(`**Banner:** [link](${guild.bannerURL({ size: 4096, format: 'png' })})`); if (guild.splash) guildAbout.push(`**Splash:** [link](${guild.splashURL({ size: 4096, format: 'png' })})`); const EmojiTierMap = { - TIER_3: 500, - TIER_2: 300, - TIER_1: 100, - NONE: 50 + [GuildPremiumTier.Tier3]: 500, + [GuildPremiumTier.Tier2]: 300, + [GuildPremiumTier.Tier1]: 100, + [GuildPremiumTier.None]: 50 } as const; const StickerTierMap = { - TIER_3: 60, - TIER_2: 30, - TIER_1: 15, - NONE: 0 + [GuildPremiumTier.Tier3]: 60, + [GuildPremiumTier.Tier2]: 30, + [GuildPremiumTier.Tier1]: 15, + [GuildPremiumTier.None]: 0 } as const; guildStats.push( `**Channels:** ${guild.channels.cache.size.toLocaleString()} / 500 (${channelTypes.join(', ')})`, // subtract 1 for @everyone role `**Roles:** ${((guild.roles.cache.size ?? 0) - 1).toLocaleString()} / 250`, - `**Emojis:** ${guild.emojis.cache.size?.toLocaleString() ?? 0} / ${EmojiTierMap[guild.premiumTier]}`, - `**Stickers:** ${guild.stickers.cache.size?.toLocaleString() ?? 0} / ${StickerTierMap[guild.premiumTier]}` + `**Emojis:** ${guild.emojis.cache.size?.toLocaleString() ?? 0} / ${(EmojiTierMap)[guild.premiumTier]}`, + `**Stickers:** ${guild.stickers.cache.size?.toLocaleString() ?? 0} / ${(StickerTierMap)[guild.premiumTier]}` ); guildSecurity.push( - `**Verification Level**: ${guild.verificationLevel.toLowerCase().replace(/_/g, ' ')}`, - `**Explicit Content Filter:** ${guild.explicitContentFilter.toLowerCase().replace(/_/g, ' ')}`, - `**Default Message Notifications:** ${ - typeof guild.defaultMessageNotifications === 'string' - ? guild.defaultMessageNotifications.toLowerCase().replace(/_/g, ' ') - : guild.defaultMessageNotifications - }`, - `**2FA Required**: ${guild.mfaLevel === 'ELEVATED' ? 'yes' : 'no'}` + `**Verification Level**: ${(BushGuildVerificationLevel)[guild.verificationLevel]}`, + `**Explicit Content Filter:** ${(BushGuildExplicitContentFilter)[guild.explicitContentFilter]}`, + `**Default Message Notifications:** ${(BushGuildDefaultMessageNotifications)[guild.defaultMessageNotifications]}`, + `**2FA Required**: ${guild.mfaLevel === GuildMFALevel.Elevated ? 'True' : 'False'}` ); } else { guildAbout.push( @@ -142,8 +141,8 @@ export default class GuildInfoCommand extends BushCommand { }, ${util.emojis.offlineCircle} ${( (guild.approximateMemberCount ?? 0) - (guild.approximatePresenceCount ?? 0) ).toLocaleString()})`, - `**Emojis:** ${(guild as GuildPreview).emojis.size?.toLocaleString() ?? 0}` - // `**Stickers:** ${(guild as GuildPreview).stickers.size}` + `**Emojis:** ${(guild as GuildPreview).emojis.size?.toLocaleString() ?? 0}`, + `**Stickers:** ${(guild as GuildPreview).stickers.size}` ); } @@ -174,7 +173,7 @@ export default class GuildInfoCommand extends BushCommand { .setColor(util.colors.default) .addField('» About', guildAbout.join('\n')); if (guildStats.length) guildInfoEmbed.addField('» Stats', guildStats.join('\n')); - const guildIcon = guild.iconURL({ size: 2048, format: 'png', dynamic: true }); + const guildIcon = guild.iconURL({ size: 2048, format: 'png' }); if (guildIcon) { guildInfoEmbed.setThumbnail(guildIcon); } @@ -203,3 +202,22 @@ type RTCRegion = | 'japan' | 'india' | 'automatic'; + +enum BushGuildVerificationLevel { + 'None' = GuildVerificationLevel.None, + 'Low' = GuildVerificationLevel.Low, + 'Medium' = GuildVerificationLevel.Medium, + 'High' = GuildVerificationLevel.High, + 'Very High' = GuildVerificationLevel.VeryHigh +} + +enum BushGuildExplicitContentFilter { + 'Disabled' = GuildExplicitContentFilter.Disabled, + 'Members Without Roles' = GuildExplicitContentFilter.MembersWithoutRoles, + 'All Members' = GuildExplicitContentFilter.AllMembers +} + +enum BushGuildDefaultMessageNotifications { + 'All Messages' = GuildDefaultMessageNotifications.AllMessages, + 'Only Mentions' = GuildDefaultMessageNotifications.OnlyMentions +} diff --git a/src/commands/info/help.ts b/src/commands/info/help.ts index 1ac7b3e..c77b5d2 100644 --- a/src/commands/info/help.ts +++ b/src/commands/info/help.ts @@ -1,8 +1,17 @@ import { BushCommand, type ArgType, type BushMessage, type BushSlashMessage } from '#lib'; import assert from 'assert'; -import { AutocompleteInteraction, MessageActionRow, MessageButton, MessageEmbed } from 'discord.js'; +import { + ActionRow, + ApplicationCommandOptionType, + AutocompleteInteraction, + ButtonComponent, + ButtonStyle, + MessageEmbed, + Permissions +} from 'discord.js'; import Fuse from 'fuse.js'; import packageDotJSON from '../../../package.json' assert { type: 'json' }; + assert(Fuse); assert(packageDotJSON); @@ -22,7 +31,7 @@ export default class HelpCommand extends BushCommand { match: 'content', prompt: 'What command do you need help with?', retry: '{error} Choose a valid command to find help for.', - slashType: 'STRING', + slashType: ApplicationCommandOptionType.String, optional: true, autocomplete: true }, @@ -31,14 +40,14 @@ export default class HelpCommand extends BushCommand { description: 'Whether ot not to show hidden commands as well.', match: 'flag', flag: '--hidden', - slashType: 'BOOLEAN', + slashType: ApplicationCommandOptionType.Boolean, ownerOnly: true, only: 'text', optional: true } ], slash: true, - clientPermissions: (m) => util.clientSendAndPermCheck(m, ['EMBED_LINKS'], true), + clientPermissions: (m) => util.clientSendAndPermCheck(m, [Permissions.FLAGS.EMBED_LINKS], true), userPermissions: [] }); } @@ -117,40 +126,23 @@ export default class HelpCommand extends BushCommand { if (restrictions.length) embed.addField('» Restrictions', restrictions.join('\n')); } - return await message.util.reply({ embeds: [embed], components: row.components.length ? [row] : undefined }); + const params = { embeds: [embed], components: row.components.length ? [row] : undefined }; + return await message.util.reply(params); } private addLinks(message: BushMessage | BushSlashMessage) { - const row = new MessageActionRow(); + const row = new ActionRow(); if (!client.config.isDevelopment && !client.guilds.cache.some((guild) => guild.ownerId === message.author.id)) { - row.addComponents( - new MessageButton({ - style: 'LINK', - label: 'Invite Me', - url: `https://discord.com/api/oauth2/authorize?client_id=${ - client.user!.id - }&permissions=5368709119918&scope=bot%20applications.commands` - }) - ); + row.addComponents(new ButtonComponent().setStyle(ButtonStyle.Link).setLabel('Invite Me').setURL(util.invite)); } if (!client.guilds.cache.get(client.config.supportGuild.id)?.members.cache.has(message.author.id)) { row.addComponents( - new MessageButton({ - style: 'LINK', - label: 'Support Server', - url: client.config.supportGuild.invite - }) + new ButtonComponent().setStyle(ButtonStyle.Link).setLabel('Support Server').setURL(client.config.supportGuild.invite) ); } if (packageDotJSON?.repository) - row.addComponents( - new MessageButton({ - style: 'LINK', - label: 'GitHub', - url: packageDotJSON.repository - }) - ); + row.addComponents(new ButtonComponent().setStyle(ButtonStyle.Link).setLabel('GitHub').setURL(packageDotJSON.repository)); else void message.channel?.send('Error importing package.json, please report this to my developer.'); return row; diff --git a/src/commands/info/icon.ts b/src/commands/info/icon.ts index 42b7fa4..9602d40 100644 --- a/src/commands/info/icon.ts +++ b/src/commands/info/icon.ts @@ -1,5 +1,5 @@ import { BushCommand, type BushMessage, type BushSlashMessage } from '#lib'; -import { MessageEmbed } from 'discord.js'; +import { MessageEmbed, Permissions } from 'discord.js'; export default class IconCommand extends BushCommand { constructor() { @@ -9,7 +9,7 @@ export default class IconCommand extends BushCommand { description: "A command to get the server's icon", usage: ['icon'], examples: ['icon'], - clientPermissions: (m) => util.clientSendAndPermCheck(m, ['EMBED_LINKS'], true), + clientPermissions: (m)