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 --- package.json | 20 +- src/arguments/messageLink.ts | 2 +- 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 +- src/context-menu-commands/message/viewRaw.ts | 6 +- src/context-menu-commands/user/userInfo.ts | 6 +- src/lib/common/AutoMod.ts | 32 +- src/lib/common/ButtonPaginator.ts | 139 ++++---- src/lib/common/ConfirmationPrompt.ts | 27 +- src/lib/common/DeleteButton.ts | 16 +- src/lib/common/util/Moderation.ts | 8 +- src/lib/extensions/discord-akairo/BushClient.ts | 21 +- .../extensions/discord-akairo/BushClientUtil.ts | 35 +- src/lib/extensions/discord-akairo/BushCommand.ts | 4 +- .../extensions/discord-akairo/BushSlashMessage.ts | 12 +- .../discord.js/BushApplicationCommandManager.d.ts | 146 -------- .../discord.js/BushApplicationCommandManager.ts | 151 +++++++++ .../BushApplicationCommandPermissionsManager.d.ts | 184 ---------- .../BushApplicationCommandPermissionsManager.ts | 184 ++++++++++ .../discord.js/BushBaseGuildEmojiManager.d.ts | 16 - .../discord.js/BushBaseGuildEmojiManager.ts | 19 ++ .../discord.js/BushBaseGuildVoiceChannel.d.ts | 13 - .../discord.js/BushBaseGuildVoiceChannel.ts | 13 + .../extensions/discord.js/BushCategoryChannel.ts | 31 +- src/lib/extensions/discord.js/BushChannel.d.ts | 24 -- src/lib/extensions/discord.js/BushChannel.ts | 41 +++ .../extensions/discord.js/BushChannelManager.d.ts | 22 -- .../extensions/discord.js/BushChannelManager.ts | 25 ++ .../discord.js/BushChatInputCommandInteraction.ts | 46 +++ .../extensions/discord.js/BushClientEvents.d.ts | 326 ------------------ src/lib/extensions/discord.js/BushClientEvents.ts | 281 ++++++++++++++++ src/lib/extensions/discord.js/BushClientUser.d.ts | 98 ------ src/lib/extensions/discord.js/BushClientUser.ts | 98 ++++++ .../discord.js/BushCommandInteraction.ts | 46 --- src/lib/extensions/discord.js/BushDMChannel.ts | 28 +- src/lib/extensions/discord.js/BushGuild.ts | 42 ++- .../BushGuildApplicationCommandManager.d.ts | 110 ------ .../BushGuildApplicationCommandManager.ts | 114 +++++++ src/lib/extensions/discord.js/BushGuildBan.d.ts | 15 - src/lib/extensions/discord.js/BushGuildBan.ts | 15 + src/lib/extensions/discord.js/BushGuildChannel.ts | 30 +- .../discord.js/BushGuildChannelManager.d.ts | 123 ------- .../discord.js/BushGuildChannelManager.ts | 123 +++++++ .../discord.js/BushGuildEmojiRoleManager.d.ts | 52 --- .../discord.js/BushGuildEmojiRoleManager.ts | 55 +++ .../extensions/discord.js/BushGuildManager.d.ts | 34 -- src/lib/extensions/discord.js/BushGuildManager.ts | 35 ++ src/lib/extensions/discord.js/BushGuildMember.ts | 65 ++-- .../discord.js/BushGuildMemberManager.d.ts | 169 ---------- .../discord.js/BushGuildMemberManager.ts | 173 ++++++++++ src/lib/extensions/discord.js/BushMessage.ts | 4 +- .../extensions/discord.js/BushMessageManager.d.ts | 105 ------ .../extensions/discord.js/BushMessageManager.ts | 109 ++++++ src/lib/extensions/discord.js/BushStoreChannel.ts | 31 +- src/lib/extensions/discord.js/BushTextChannel.ts | 30 +- src/lib/extensions/discord.js/BushThreadChannel.ts | 22 +- .../extensions/discord.js/BushThreadManager.d.ts | 82 ----- src/lib/extensions/discord.js/BushThreadManager.ts | 86 +++++ .../discord.js/BushThreadMemberManager.d.ts | 43 --- .../discord.js/BushThreadMemberManager.ts | 55 +++ src/lib/extensions/discord.js/BushUserManager.d.ts | 59 ---- src/lib/extensions/discord.js/BushUserManager.ts | 60 ++++ src/lib/extensions/discord.js/BushVoiceChannel.ts | 30 +- src/lib/extensions/discord.js/other.ts | 54 +-- src/lib/extensions/global.d.ts | 22 -- src/lib/extensions/global.ts | 22 ++ src/lib/index.ts | 2 +- src/lib/models/Guild.ts | 17 +- src/lib/utils/AllowedMentions.ts | 6 + src/lib/utils/BushConstants.ts | 82 +++-- src/listeners/bush/joinAutoBan.ts | 2 +- src/listeners/bush/userUpdateAutoBan.ts | 2 +- src/listeners/client/interactionCreate.ts | 6 +- src/listeners/client/rateLimit.ts | 15 + src/listeners/commands/commandError.ts | 12 +- .../commands/commandMissingPermissions.ts | 2 +- src/listeners/commands/commandStarted.ts | 14 +- src/listeners/commands/slashCommandError.ts | 1 + src/listeners/commands/slashStarted.ts | 4 +- src/listeners/member-custom/bushBan.ts | 2 +- src/listeners/member-custom/bushBlock.ts | 2 +- src/listeners/member-custom/bushKick.ts | 2 +- src/listeners/member-custom/bushMute.ts | 2 +- src/listeners/member-custom/bushPunishRole.ts | 2 +- .../member-custom/bushPunishRoleRemove.ts | 2 +- src/listeners/member-custom/bushPurge.ts | 2 +- src/listeners/member-custom/bushRemoveTimeout.ts | 2 +- src/listeners/member-custom/bushTimeout.ts | 2 +- src/listeners/member-custom/bushUnban.ts | 2 +- src/listeners/member-custom/bushUnblock.ts | 2 +- src/listeners/member-custom/bushUnmute.ts | 2 +- src/listeners/member-custom/bushUpdateModlog.ts | 2 +- src/listeners/member-custom/bushUpdateSettings.ts | 2 +- src/listeners/member-custom/bushWarn.ts | 2 +- src/listeners/message/autoPublisher.ts | 2 +- src/listeners/message/autoThread.ts | 7 +- src/listeners/message/blacklistedFile.ts | 5 +- src/listeners/message/boosterMessage.ts | 3 +- src/listeners/message/directMessage.ts | 8 +- src/listeners/message/level.ts | 6 +- src/listeners/message/verbose.ts | 3 +- src/listeners/other/consoleListener.ts | 6 +- .../track-manual-punishments/modlogSyncBan.ts | 9 +- .../track-manual-punishments/modlogSyncKick.ts | 9 +- .../track-manual-punishments/modlogSyncTimeout.ts | 8 +- .../track-manual-punishments/modlogSyncUnban.ts | 8 +- yarn.lock | 374 ++++++++++----------- 180 files changed, 3128 insertions(+), 2723 deletions(-) create mode 100644 src/commands/dev/debug.ts delete mode 100644 src/lib/extensions/discord.js/BushApplicationCommandManager.d.ts create mode 100644 src/lib/extensions/discord.js/BushApplicationCommandManager.ts delete mode 100644 src/lib/extensions/discord.js/BushApplicationCommandPermissionsManager.d.ts create mode 100644 src/lib/extensions/discord.js/BushApplicationCommandPermissionsManager.ts delete mode 100644 src/lib/extensions/discord.js/BushBaseGuildEmojiManager.d.ts create mode 100644 src/lib/extensions/discord.js/BushBaseGuildEmojiManager.ts delete mode 100644 src/lib/extensions/discord.js/BushBaseGuildVoiceChannel.d.ts create mode 100644 src/lib/extensions/discord.js/BushBaseGuildVoiceChannel.ts delete mode 100644 src/lib/extensions/discord.js/BushChannel.d.ts create mode 100644 src/lib/extensions/discord.js/BushChannel.ts delete mode 100644 src/lib/extensions/discord.js/BushChannelManager.d.ts create mode 100644 src/lib/extensions/discord.js/BushChannelManager.ts create mode 100644 src/lib/extensions/discord.js/BushChatInputCommandInteraction.ts delete mode 100644 src/lib/extensions/discord.js/BushClientEvents.d.ts create mode 100644 src/lib/extensions/discord.js/BushClientEvents.ts delete mode 100644 src/lib/extensions/discord.js/BushClientUser.d.ts create mode 100644 src/lib/extensions/discord.js/BushClientUser.ts delete mode 100644 src/lib/extensions/discord.js/BushCommandInteraction.ts delete mode 100644 src/lib/extensions/discord.js/BushGuildApplicationCommandManager.d.ts create mode 100644 src/lib/extensions/discord.js/BushGuildApplicationCommandManager.ts delete mode 100644 src/lib/extensions/discord.js/BushGuildBan.d.ts create mode 100644 src/lib/extensions/discord.js/BushGuildBan.ts delete mode 100644 src/lib/extensions/discord.js/BushGuildChannelManager.d.ts create mode 100644 src/lib/extensions/discord.js/BushGuildChannelManager.ts delete mode 100644 src/lib/extensions/discord.js/BushGuildEmojiRoleManager.d.ts create mode 100644 src/lib/extensions/discord.js/BushGuildEmojiRoleManager.ts delete mode 100644 src/lib/extensions/discord.js/BushGuildManager.d.ts create mode 100644 src/lib/extensions/discord.js/BushGuildManager.ts delete mode 100644 src/lib/extensions/discord.js/BushGuildMemberManager.d.ts create mode 100644 src/lib/extensions/discord.js/BushGuildMemberManager.ts delete mode 100644 src/lib/extensions/discord.js/BushMessageManager.d.ts create mode 100644 src/lib/extensions/discord.js/BushMessageManager.ts delete mode 100644 src/lib/extensions/discord.js/BushThreadManager.d.ts create mode 100644 src/lib/extensions/discord.js/BushThreadManager.ts delete mode 100644 src/lib/extensions/discord.js/BushThreadMemberManager.d.ts create mode 100644 src/lib/extensions/discord.js/BushThreadMemberManager.ts delete mode 100644 src/lib/extensions/discord.js/BushUserManager.d.ts create mode 100644 src/lib/extensions/discord.js/BushUserManager.ts delete mode 100644 src/lib/extensions/global.d.ts create mode 100644 src/lib/extensions/global.ts create mode 100644 src/listeners/client/rateLimit.ts diff --git a/package.json b/package.json index 18a87e9..3efef1f 100644 --- a/package.json +++ b/package.json @@ -60,25 +60,25 @@ "@sentry/integrations": "^6.16.1", "@sentry/node": "^6.16.1", "@sentry/tracing": "^6.16.1", - "canvas": "^2.8.0", + "canvas": "^2.9.0", "chalk": "^5.0.0", "deep-lock": "^1.0.0", "discord-akairo": "npm:@notenoughupdates/discord-akairo@dev", "discord.js": "npm:@notenoughupdates/discord.js@dev", "fuse.js": "^6.5.3", - "got": "^12.0.0", + "got": "^12.0.1", "lodash": "^4.17.21", - "mathjs": "^10.0.2", + "mathjs": "^10.1.0", "moment": "^2.29.1", - "nanoid": "^3.1.30", - "node-os-utils": "^1.3.5", + "nanoid": "^3.2.0", + "node-os-utils": "^1.3.6", "numeral": "^2.0.6", "pg": "^8.7.1", "pg-hstore": "^2.3.4", "prettier": "^2.5.1", "pretty-bytes": "^5.6.0", "rimraf": "^3.0.2", - "sequelize": "^6.12.5", + "sequelize": "^6.13.0", "source-map-support": "^0.5.21", "tinycolor2": "^1.4.2", "tslib": "^2.3.1", @@ -89,7 +89,7 @@ "@types/eslint": "^8", "@types/express": "^4.17.13", "@types/lodash": "^4.14.178", - "@types/node": "^17.0.8", + "@types/node": "^17.0.10", "@types/node-os-utils": "^1.2.0", "@types/numeral": "^2.0.2", "@types/pg": "^8", @@ -98,10 +98,10 @@ "@types/source-map-support": "^0", "@types/tinycolor2": "^1.4.3", "@types/validator": "^13.7.1", - "@typescript-eslint/eslint-plugin": "^5.9.0", - "@typescript-eslint/parser": "^5.9.0", + "@typescript-eslint/eslint-plugin": "^5.10.0", + "@typescript-eslint/parser": "^5.10.0", "discord-api-types": "0.26.0", - "eslint": "^8.6.0", + "eslint": "^8.7.0", "eslint-config-prettier": "^8.3.0", "eslint-plugin-deprecation": "^1.3.2" }, diff --git a/src/arguments/messageLink.ts b/src/arguments/messageLink.ts index 2a9800c..565fab1 100644 --- a/src/arguments/messageLink.ts +++ b/src/arguments/messageLink.ts @@ -13,7 +13,7 @@ export const messageLink: BushArgumentTypeCaster> = asyn if (!guild) return null; const channel = guild.channels.cache.get(channel_id); - if (!channel || (!channel.isText() && !channel.isThread())) return null; + if (!channel || (!channel.isTextBased() && !channel.isThread())) return null; const message = await channel.messages.fetch(message_id).catch(() => null); return message; 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