diff options
| author | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2022-01-23 18:13:05 -0500 |
|---|---|---|
| committer | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2022-01-23 18:13:05 -0500 |
| commit | a3f8d3884a1deca5eccfb6d990e2a7b42fbbe08a (patch) | |
| tree | 9b0f8ed8a93c22c90512751e3f2f5937e1925760 /src/lib | |
| parent | 5557677f1570eb564a30cfcebb6030235dc84d47 (diff) | |
| download | tanzanite-a3f8d3884a1deca5eccfb6d990e2a7b42fbbe08a.tar.gz tanzanite-a3f8d3884a1deca5eccfb6d990e2a7b42fbbe08a.tar.bz2 tanzanite-a3f8d3884a1deca5eccfb6d990e2a7b42fbbe08a.zip | |
fix discord.js breaking changes, some other stuff
Diffstat (limited to 'src/lib')
45 files changed, 649 insertions, 399 deletions
diff --git a/src/lib/common/AutoMod.ts b/src/lib/common/AutoMod.ts index 7a30820..4de242a 100644 --- a/src/lib/common/AutoMod.ts +++ b/src/lib/common/AutoMod.ts @@ -1,5 +1,14 @@ import { banResponse, Moderation, type BushButtonInteraction, type BushMessage } from '#lib'; -import { GuildMember, MessageActionRow, MessageButton, MessageEmbed, type TextChannel } from 'discord.js'; +import { + ActionRow, + ButtonComponent, + ButtonStyle, + ChannelType, + GuildMember, + MessageEmbed, + Permissions, + type TextChannel +} from 'discord.js'; /** * Handles auto moderation functionality. @@ -28,7 +37,7 @@ export class AutoMod { * Handles the auto moderation */ private async handle() { - if (this.message.channel.type === 'DM' || !this.message.guild) return; + if (this.message.channel.type === ChannelType.DM || !this.message.guild) return; if (!(await this.message.guild.hasFeature('automod'))) return; if (this.message.author.bot) return; if (this.message.author.isOwner()) return; @@ -110,7 +119,10 @@ export class AutoMod { const includes = this.message.content.toLocaleLowerCase().includes; if (!includes('@everyone') && !includes('@here')) return; // It would be bad if we deleted a message that actually pinged @everyone or @here - if (this.message.member?.permissionsIn(this.message.channelId).has('MENTION_EVERYONE') || this.message.mentions.everyone) + if ( + this.message.member?.permissionsIn(this.message.channelId).has(Permissions.FLAGS.MENTION_EVERYONE) || + this.message.mentions.everyone + ) return; if ( @@ -142,9 +154,9 @@ export class AutoMod { components: Severity.TEMP_MUTE >= 2 ? [ - new MessageActionRow().addComponents( - new MessageButton() - .setStyle('DANGER') + new ActionRow().addComponents( + new ButtonComponent() + .setStyle(ButtonStyle.Danger) .setLabel('Ban User') .setCustomId(`automod;ban;${this.message.author.id};everyone mention and scam phrase`) ) @@ -263,9 +275,9 @@ export class AutoMod { components: highestOffence.severity >= 2 ? [ - new MessageActionRow().addComponents( - new MessageButton() - .setStyle('DANGER') + new ActionRow().addComponents( + new ButtonComponent() + .setStyle(ButtonStyle.Danger) .setLabel('Ban User') .setCustomId(`automod;ban;${this.message.author.id};${highestOffence.reason}`) ) @@ -279,7 +291,7 @@ export class AutoMod { * @param interaction The button interaction. */ public static async handleInteraction(interaction: BushButtonInteraction) { - if (!interaction.memberPermissions?.has('BAN_MEMBERS')) + if (!interaction.memberPermissions?.has(Permissions.FLAGS.BAN_MEMBERS)) return interaction.reply({ content: `${util.emojis.error} You are missing the **Ban Members** permission.`, ephemeral: true diff --git a/src/lib/common/ButtonPaginator.ts b/src/lib/common/ButtonPaginator.ts index 83f4219..9e72551 100644 --- a/src/lib/common/ButtonPaginator.ts +++ b/src/lib/common/ButtonPaginator.ts @@ -1,13 +1,15 @@ import { DeleteButton, type BushMessage, type BushSlashMessage } from '#lib'; import { CommandUtil } from 'discord-akairo'; import { - MessageActionRow, - MessageButton, + ActionRow, + ActionRowComponent, + ButtonComponent, + ButtonStyle, + ComponentType, MessageEmbed, type MessageComponentInteraction, type MessageEmbedOptions } from 'discord.js'; -import { MessageButtonStyles } from 'discord.js/typings/enums'; /** * Sends multiple embeds with controls to switch between them @@ -94,9 +96,15 @@ export class ButtonPaginator { })) as BushMessage; const collector = this.sentMessage.createMessageComponentCollector({ - filter: (i) => i.customId.startsWith('paginate_') && i.message?.id === this.sentMessage!.id, - time: 300000 + componentType: ComponentType.Button, + filter: (i) => { + const ret = i.customId.startsWith('paginate_') && i.message.id === this.sentMessage!.id; + console.debug(ret); + return ret; + }, + idle: 300000 }); + console.debug('got here'); collector.on('collect', (i) => void this.collect(i)); collector.on('end', () => void this.end()); @@ -107,8 +115,9 @@ export class ButtonPaginator { * @param interaction The interaction received */ protected async collect(interaction: MessageComponentInteraction) { + console.debug(1); if (interaction.user.id !== this.message.author.id && !client.config.owners.includes(interaction.user.id)) - return await interaction?.deferUpdate().catch(() => null); + return await interaction?.deferUpdate(); /* .catch(() => null); */ switch (interaction.customId) { case 'paginate_beginning': @@ -121,17 +130,16 @@ export class ButtonPaginator { break; case 'paginate_stop': if (this.deleteOnExit) { - await interaction.deferUpdate().catch(() => null); - await this.sentMessage!.delete().catch(() => null); + await interaction.deferUpdate(); /* .catch(() => null); */ + await this.sentMessage!.delete(); /* .catch(() => null); */ break; } else { - await interaction - ?.update({ - content: `${this.text ? `${this.text}\n` : ''}Command closed by user.`, - embeds: [], - components: [] - }) - .catch(() => null); + await interaction?.update({ + content: `${this.text ? `${this.text}\n` : ''}Command closed by user.`, + embeds: [], + components: [] + }); + /* .catch(() => null); */ break; } case 'paginate_next': @@ -150,13 +158,12 @@ export class ButtonPaginator { */ protected async end() { if (this.sentMessage && !CommandUtil.deletedMessages.has(this.sentMessage.id)) - await this.sentMessage - .edit({ - content: this.text, - embeds: [this.embeds[this.curPage]], - components: [this.getPaginationRow(true)] - }) - .catch(() => null); + await this.sentMessage.edit({ + content: this.text, + embeds: [this.embeds[this.curPage]], + components: [this.getPaginationRow(true)] + }); + /* .catch(() => null); */ } /** @@ -164,52 +171,46 @@ export class ButtonPaginator { * @param interaction The interaction received */ protected async edit(interaction: MessageComponentInteraction) { - await interaction - ?.update({ - content: this.text, - embeds: [this.embeds[this.curPage]], - components: [this.getPaginationRow()] - }) - .catch(() => null); + await interaction?.update({ + content: this.text, + embeds: [this.embeds[this.curPage]], + components: [this.getPaginationRow()] + }); + /* .catch(() => null); */ } /** * Generates the pagination row based on the class properties * @param disableAll Whether to disable all buttons - * @returns The generated {@link MessageActionRow} + * @returns The generated {@link ActionRow} */ - protected getPaginationRow(disableAll = false): MessageActionRow { - return new MessageActionRow().addComponents( - new MessageButton({ - style: MessageButtonStyles.PRIMARY, - customId: 'paginate_beginning', - emoji: PaginateEmojis.BEGGING, - disabled: disableAll || this.curPage === 0 - }), - new MessageButton({ - style: MessageButtonStyles.PRIMARY, - customId: 'paginate_back', - emoji: PaginateEmojis.BACK, - disabled: disableAll || this.curPage === 0 - }), - new MessageButton({ - style: MessageButtonStyles.PRIMARY, - customId: 'paginate_stop', - emoji: PaginateEmojis.STOP, - disabled: disableAll - }), - new MessageButton({ - style: MessageButtonStyles.PRIMARY, - customId: 'paginate_next', - emoji: PaginateEmojis.FORWARD, - disabled: disableAll || this.curPage === this.numPages - 1 - }), - new MessageButton({ - style: MessageButtonStyles.PRIMARY, - customId: 'paginate_end', - emoji: PaginateEmojis.END, - disabled: disableAll || this.curPage === this.numPages - 1 - }) + protected getPaginationRow(disableAll = false): ActionRow<ActionRowComponent> { + return new ActionRow().addComponents( + new ButtonComponent() + .setStyle(ButtonStyle.Primary) + .setCustomId('paginate_beginning') + .setEmoji(PaginateEmojis.BEGINNING) + .setDisabled(disableAll || this.curPage === 0), + new ButtonComponent() + .setStyle(ButtonStyle.Primary) + .setCustomId('paginate_back') + .setEmoji(PaginateEmojis.BACK) + .setDisabled(disableAll || this.curPage === 0), + new ButtonComponent() + .setStyle(ButtonStyle.Primary) + .setCustomId('paginate_stop') + .setEmoji(PaginateEmojis.STOP) + .setDisabled(disableAll), + new ButtonComponent() + .setStyle(ButtonStyle.Primary) + .setCustomId('paginate_next') + .setEmoji(PaginateEmojis.FORWARD) + .setDisabled(disableAll || this.curPage === this.embeds.length - 1), + new ButtonComponent() + .setStyle(ButtonStyle.Primary) + .setCustomId('paginate_end') + .setEmoji(PaginateEmojis.END) + .setDisabled(disableAll || this.curPage === this.embeds.length - 1) ); } @@ -235,10 +236,10 @@ export class ButtonPaginator { } } -export const enum PaginateEmojis { - BEGGING = '853667381335162910', - BACK = '853667410203770881', - STOP = '853667471110570034', - FORWARD = '853667492680564747', - END = '853667514915225640' -} +export const PaginateEmojis = { + BEGINNING: { id: '853667381335162910', name: 'w_paginate_beginning', animated: false } as const, + BACK: { id: '853667410203770881', name: 'w_paginate_back', animated: false } as const, + STOP: { id: '853667471110570034', name: 'w_paginate_stop', animated: false } as const, + FORWARD: { id: '853667492680564747', name: 'w_paginate_next', animated: false } as const, + END: { id: '853667514915225640', name: 'w_paginate_end', animated: false } as const +} as const; diff --git a/src/lib/common/ConfirmationPrompt.ts b/src/lib/common/ConfirmationPrompt.ts index a4acf83..97f18b3 100644 --- a/src/lib/common/ConfirmationPrompt.ts +++ b/src/lib/common/ConfirmationPrompt.ts @@ -1,6 +1,5 @@ import { type BushMessage, type BushSlashMessage } from '#lib'; -import { MessageActionRow, MessageButton, type MessageComponentInteraction, type MessageOptions } from 'discord.js'; -import { MessageButtonStyles } from 'discord.js/typings/enums'; +import { ActionRow, ButtonComponent, ButtonStyle, type MessageComponentInteraction, type MessageOptions } from 'discord.js'; /** * Sends a message with buttons for the user to confirm or cancel the action. @@ -30,19 +29,17 @@ export class ConfirmationPrompt { */ protected async send(): Promise<boolean> { this.messageOptions.components = [ - new MessageActionRow().addComponents( - new MessageButton({ - style: MessageButtonStyles.SUCCESS, - customId: 'confirmationPrompt_confirm', - emoji: util.emojis.successFull, - label: 'Yes' - }), - new MessageButton({ - style: MessageButtonStyles.DANGER, - customId: 'confirmationPrompt_deny', - emoji: util.emojis.errorFull, - label: 'No' - }) + new ActionRow().addComponents( + new ButtonComponent() + .setStyle(ButtonStyle.Primary) + .setCustomId('confirmationPrompt_confirm') + .setEmoji({ id: util.emojis.successFull, name: 'successFull', animated: false }) + .setLabel('Yes'), + new ButtonComponent() + .setStyle(ButtonStyle.Danger) + .setCustomId('confirmationPrompt_cancel') + .setEmoji({ id: util.emojis.errorFull, name: 'errorFull', animated: false }) + .setLabel('No') ) ]; diff --git a/src/lib/common/DeleteButton.ts b/src/lib/common/DeleteButton.ts index b666a4f..edc40fe 100644 --- a/src/lib/common/DeleteButton.ts +++ b/src/lib/common/DeleteButton.ts @@ -1,7 +1,6 @@ import { PaginateEmojis, type BushMessage, type BushSlashMessage } from '#lib'; import { CommandUtil } from 'discord-akairo'; -import { MessageActionRow, MessageButton, type MessageComponentInteraction, type MessageOptions } from 'discord.js'; -import { MessageButtonStyles } from 'discord.js/typings/enums'; +import { ActionRow, ButtonComponent, ButtonStyle, MessageComponentInteraction, type MessageOptions } from 'discord.js'; /** * Sends a message with a button for the user to delete it. @@ -59,13 +58,12 @@ export class DeleteButton { */ protected updateComponents(edit = false, disable = false): void { this.messageOptions.components = [ - new MessageActionRow().addComponents( - new MessageButton({ - style: MessageButtonStyles.PRIMARY, - customId: 'paginate__stop', - emoji: PaginateEmojis.STOP, - disabled: disable - }) + new ActionRow().addComponents( + new ButtonComponent() + .setStyle(ButtonStyle.Primary) + .setCustomId('paginate__stop') + .setEmoji(PaginateEmojis.STOP) + .setDisabled(disable) ) ]; if (edit) { diff --git a/src/lib/common/util/Moderation.ts b/src/lib/common/util/Moderation.ts index e5cb872..84d9fbf 100644 --- a/src/lib/common/util/Moderation.ts +++ b/src/lib/common/util/Moderation.ts @@ -10,7 +10,7 @@ import { type BushUserResolvable, type ModLogType } from '#lib'; -import { MessageEmbed, type Snowflake } from 'discord.js'; +import { MessageEmbed, Permissions, type Snowflake } from 'discord.js'; /** * A utility class with moderation-related methods. @@ -70,7 +70,11 @@ export class Moderation { ) { return `${util.emojis.error} You cannot ${type} **${victim.user.tag}** because they have higher or equal role hierarchy as I do.`; } - if (checkModerator && victim.permissions.has('MANAGE_MESSAGES') && !(type.startsWith('un') && moderator.id === victim.id)) { + if ( + checkModerator && + victim.permissions.has(Permissions.FLAGS.MANAGE_MESSAGES) && + !(type.startsWith('un') && moderator.id === victim.id) + ) { if (await moderator.guild.hasFeature('modsCanPunishMods')) { return true; } else { diff --git a/src/lib/extensions/discord-akairo/BushClient.ts b/src/lib/extensions/discord-akairo/BushClient.ts index cb1e50b..01620a8 100644 --- a/src/lib/extensions/discord-akairo/BushClient.ts +++ b/src/lib/extensions/discord-akairo/BushClient.ts @@ -24,6 +24,7 @@ import { patch, type PatchedElements } from '@notenoughupdates/events-intercept' import * as Sentry from '@sentry/node'; import { AkairoClient, ContextMenuCommandHandler, version as akairoVersion } from 'discord-akairo'; import { + ActivityType, Intents, Options, Structures, @@ -61,7 +62,7 @@ import { BushConstants } from '../../utils/BushConstants.js'; import { BushLogger } from '../../utils/BushLogger.js'; import { BushButtonInteraction } from '../discord.js/BushButtonInteraction.js'; import { BushCategoryChannel } from '../discord.js/BushCategoryChannel.js'; -import { BushCommandInteraction } from '../discord.js/BushCommandInteraction.js'; +import { BushChatInputCommandInteraction } from '../discord.js/BushChatInputCommandInteraction.js'; import { BushDMChannel } from '../discord.js/BushDMChannel.js'; import { BushGuild } from '../discord.js/BushGuild.js'; import { BushGuildEmoji } from '../discord.js/BushGuildEmoji.js'; @@ -193,7 +194,7 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re activities: [ { name: 'Beep Boop', - type: 'WATCHING' + type: ActivityType.Watching } ], status: 'online' @@ -252,7 +253,7 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re automateCategories: false, autoRegisterSlashCommands: true, skipBuiltInPostInhibitors: true, - useSlashPermissions: true, + useSlashPermissions: false, aliasReplacement: /-/g }); this.contextMenuCommandHandler = new ContextMenuCommandHandler(this, { @@ -320,7 +321,7 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re Structures.extend('VoiceState', () => BushVoiceState); Structures.extend('Role', () => BushRole); Structures.extend('User', () => BushUser); - Structures.extend('CommandInteraction', () => BushCommandInteraction); + Structures.extend('ChatInputCommandInteraction', () => BushChatInputCommandInteraction); Structures.extend('ButtonInteraction', () => BushButtonInteraction); Structures.extend('SelectMenuInteraction', () => BushSelectMenuInteraction); } @@ -440,13 +441,17 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re */ public async start() { this.intercept('ready', async (arg, done) => { - await this.guilds.fetch(); - const promises = this.guilds.cache.map((guild) => { - return guild.members.fetch(); - }); + console.debug('ready start'); + console.time('ready'); + const promises = this.guilds.cache + .filter((g) => g.large) + .map((guild) => { + return guild.members.fetch(); + }); await Promise.all(promises); this.customReady = true; this.taskHandler.startAll(); + console.timeEnd('ready'); return done(null, `intercepted ${arg}`); }); diff --git a/src/lib/extensions/discord-akairo/BushClientUtil.ts b/src/lib/extensions/discord-akairo/BushClientUtil.ts index 12becd3..79aa4c1 100644 --- a/src/lib/extensions/discord-akairo/BushClientUtil.ts +++ b/src/lib/extensions/discord-akairo/BushClientUtil.ts @@ -26,13 +26,13 @@ import { GuildMember, Message, MessageEmbed, + Permissions, ThreadMember, User, Util as DiscordUtil, type ColorResolvable, type CommandInteraction, type InteractionReplyOptions, - type PermissionResolvable, type Snowflake, type TextChannel, type UserResolvable @@ -43,6 +43,8 @@ import { inspect, promisify } from 'util'; import CommandErrorListener from '../../../listeners/commands/commandError.js'; import { Format } from '../../common/util/Format.js'; +export type StripPrivate<T> = { [K in keyof T]: T[K] extends Record<string, any> ? StripPrivate<T[K]> : T[K] }; + export class BushClientUtil extends ClientUtil { /** * The client. @@ -208,7 +210,7 @@ export class BushClientUtil extends ClientUtil { if (author) embed = embed.setAuthor({ name: author.username, - iconURL: author.displayAvatarURL({ dynamic: true }), + iconURL: author.displayAvatarURL(), url: `https://discord.com/users/${author.id}` }); if (color) embed = embed.setColor(color); @@ -425,7 +427,7 @@ export class BushClientUtil extends ClientUtil { * @returns The combined elements or `ifEmpty`. * * @example - * const permissions = oxford(['ADMINISTRATOR', 'SEND_MESSAGES', 'MANAGE_MESSAGES'], 'and', 'none'); + * const permissions = oxford([Permissions.FLAGS.ADMINISTRATOR, Permissions.FLAGS.SEND_MESSAGES, Permissions.FLAGS.MANAGE_MESSAGES], 'and', 'none'); * console.log(permissions); // ADMINISTRATOR, SEND_MESSAGES and MANAGE_MESSAGES */ public oxford(array: string[], conjunction: string, ifEmpty?: string): string | undefined { @@ -785,10 +787,10 @@ export class BushClientUtil extends ClientUtil { * @param permissions The permissions to check for. * @returns The missing permissions or null if none are missing. */ - public userGuildPermCheck(message: BushMessage | BushSlashMessage, permissions: PermissionResolvable) { + public userGuildPermCheck(message: BushMessage | BushSlashMessage, permissions: bigint[]) { const missing = message.member?.permissions.missing(permissions) ?? []; - return missing.length ? missing : null; + return missing.length ? missing.map((p) => Permissions.FLAGS[p]) : null; } /** @@ -797,10 +799,10 @@ export class BushClientUtil extends ClientUtil { * @param permissions The permissions to check for. * @returns The missing permissions or null if none are missing. */ - public clientGuildPermCheck(message: BushMessage | BushSlashMessage, permissions: PermissionResolvable) { + public clientGuildPermCheck(message: BushMessage | BushSlashMessage, permissions: bigint[]) { const missing = message.guild?.me?.permissions.missing(permissions) ?? []; - return missing.length ? missing : null; + return missing.length ? missing.map((p) => Permissions.FLAGS[p]) : null; } /** @@ -811,19 +813,18 @@ export class BushClientUtil extends ClientUtil { * @param checkChannel Whether to check the channel permissions instead of the guild permissions. * @returns The missing permissions or null if none are missing. */ - public clientSendAndPermCheck( - message: BushMessage | BushSlashMessage, - permissions: PermissionResolvable = [], - checkChannel = false - ) { + public clientSendAndPermCheck(message: BushMessage | BushSlashMessage, permissions: bigint[] = [], checkChannel = false) { const missing = []; - const sendPerm = message.channel!.isThread() ? 'SEND_MESSAGES' : 'SEND_MESSAGES_IN_THREADS'; + const sendPerm = message.channel!.isThread() ? Permissions.FLAGS.SEND_MESSAGES : Permissions.FLAGS.SEND_MESSAGES_IN_THREADS; if (!message.guild!.me!.permissionsIn(message.channel!.id!).has(sendPerm)) missing.push(sendPerm); missing.push( ...(checkChannel - ? message.guild!.me!.permissionsIn(message.channel!.id!).missing(permissions) + ? message + .guild!.me!.permissionsIn(message.channel!.id!) + .missing(permissions) + .map((p) => Permissions.FLAGS[p]) : this.clientGuildPermCheck(message, permissions) ?? []) ); @@ -894,6 +895,12 @@ export class BushClientUtil extends ClientUtil { return Object.fromEntries(values); } + public get invite() { + return `https://discord.com/api/oauth2/authorize?client_id=${client.user!.id}&permissions=${ + Permissions.ALL + }&scope=bot%20applications.commands`; + } + /** * A wrapper for the Argument class that adds custom typings. */ diff --git a/src/lib/extensions/discord-akairo/BushCommand.ts b/src/lib/extensions/discord-akairo/BushCommand.ts index fb488be..0456b80 100644 --- a/src/lib/extensions/discord-akairo/BushCommand.ts +++ b/src/lib/extensions/discord-akairo/BushCommand.ts @@ -315,12 +315,12 @@ export interface BaseBushCommandOptions /** * Permissions required by the client to run this command. */ - clientPermissions: PermissionResolvable | PermissionResolvable[] | BushMissingPermissionSupplier; + clientPermissions: bigint | bigint[] | BushMissingPermissionSupplier; < |
