From 840cca672d681c36f980a06fb79a4e2c01bd69ac Mon Sep 17 00:00:00 2001 From: IRONM00N <64110067+IRONM00N@users.noreply.github.com> Date: Tue, 25 Jan 2022 23:47:40 -0500 Subject: I love breaking changes!!!! --- src/lib/common/AutoMod.ts | 12 ++-- src/lib/common/ButtonPaginator.ts | 81 +++++++++------------- src/lib/common/DeleteButton.ts | 12 +++- src/lib/common/util/Moderation.ts | 4 +- src/lib/extensions/discord-akairo/BushClient.ts | 1 + .../extensions/discord-akairo/BushClientUtil.ts | 25 +------ .../extensions/discord.js/BushButtonInteraction.ts | 2 +- .../discord.js/BushChatInputCommandInteraction.ts | 2 +- src/lib/extensions/discord.js/BushGuild.ts | 4 +- .../discord.js/BushSelectMenuInteraction.ts | 2 +- src/lib/models/Guild.ts | 32 +++++++-- src/lib/utils/BushConstants.ts | 44 ++++++------ src/lib/utils/BushLogger.ts | 12 ++-- 13 files changed, 112 insertions(+), 121 deletions(-) (limited to 'src/lib') diff --git a/src/lib/common/AutoMod.ts b/src/lib/common/AutoMod.ts index 4de242a..c57d581 100644 --- a/src/lib/common/AutoMod.ts +++ b/src/lib/common/AutoMod.ts @@ -4,8 +4,8 @@ import { ButtonComponent, ButtonStyle, ChannelType, + Embed, GuildMember, - MessageEmbed, Permissions, type TextChannel } from 'discord.js'; @@ -142,12 +142,12 @@ export class AutoMod { const color = this.punish({ severity: Severity.TEMP_MUTE, reason: 'everyone mention and scam phrase' } as BadWordDetails); void this.message.guild!.sendLogChannel('automod', { embeds: [ - new MessageEmbed() + new Embed() .setTitle(`[Severity ${Severity.TEMP_MUTE}] Mention Scam Deleted`) .setDescription( `**User:** ${this.message.author} (${this.message.author.tag})\n**Sent From**: <#${this.message.channel.id}> [Jump to context](${this.message.url})` ) - .addField('Message Content', `${await util.codeblock(this.message.content, 1024)}`) + .addField({ name: 'Message Content', value: `${await util.codeblock(this.message.content, 1024)}` }) .setColor(color) .setTimestamp() ], @@ -250,7 +250,7 @@ export class AutoMod { * @param color The color that the log embed should be (based on the severity) * @param offences The other offences that were also matched in the message */ - private async log(highestOffence: BadWordDetails, color: `#${string}`, offences: BadWordDetails[]) { + private async log(highestOffence: BadWordDetails, color: number, offences: BadWordDetails[]) { void client.console.info( 'autoMod', `Severity <<${highestOffence.severity}>> action performed on <<${this.message.author.tag}>> (<<${ @@ -260,14 +260,14 @@ export class AutoMod { await this.message.guild!.sendLogChannel('automod', { embeds: [ - new MessageEmbed() + new Embed() .setTitle(`[Severity ${highestOffence.severity}] Automod Action Performed`) .setDescription( `**User:** ${this.message.author} (${this.message.author.tag})\n**Sent From**: <#${ this.message.channel.id }> [Jump to context](${this.message.url})\n**Blacklisted Words:** ${offences.map((o) => `\`${o.match}\``).join(', ')}` ) - .addField('Message Content', `${await util.codeblock(this.message.content, 1024)}`) + .addField({ name: 'Message Content', value: `${await util.codeblock(this.message.content, 1024)}` }) .setColor(color) .setTimestamp() .setAuthor({ name: this.message.author.tag, url: this.message.author.displayAvatarURL() }) diff --git a/src/lib/common/ButtonPaginator.ts b/src/lib/common/ButtonPaginator.ts index 9e72551..0c18119 100644 --- a/src/lib/common/ButtonPaginator.ts +++ b/src/lib/common/ButtonPaginator.ts @@ -1,15 +1,7 @@ import { DeleteButton, type BushMessage, type BushSlashMessage } from '#lib'; import { CommandUtil } from 'discord-akairo'; -import { - ActionRow, - ActionRowComponent, - ButtonComponent, - ButtonStyle, - ComponentType, - MessageEmbed, - type MessageComponentInteraction, - type MessageEmbedOptions -} from 'discord.js'; +import { APIEmbed } from 'discord-api-types'; +import { ActionRow, ActionRowComponent, ButtonComponent, ButtonStyle, Embed, type MessageComponentInteraction } from 'discord.js'; /** * Sends multiple embeds with controls to switch between them @@ -23,7 +15,7 @@ export class ButtonPaginator { /** * The embeds to paginate */ - protected embeds: MessageEmbed[] | MessageEmbedOptions[]; + protected embeds: Embed[] | APIEmbed[]; /** * The optional text to send with the paginator @@ -54,7 +46,7 @@ export class ButtonPaginator { */ protected constructor( message: BushMessage | BushSlashMessage, - embeds: MessageEmbed[] | MessageEmbedOptions[], + embeds: Embed[] | APIEmbed[], text: string | null, deleteOnExit: boolean, startOn: number @@ -68,10 +60,10 @@ export class ButtonPaginator { // add footers for (let i = 0; i < embeds.length; i++) { - if (embeds[i] instanceof MessageEmbed) { - (embeds[i] as MessageEmbed).setFooter({ text: `Page ${(i + 1).toLocaleString()}/${embeds.length.toLocaleString()}` }); + if (embeds[i] instanceof Embed) { + (embeds[i] as Embed).setFooter({ text: `Page ${(i + 1).toLocaleString()}/${embeds.length.toLocaleString()}` }); } else { - (embeds[i] as MessageEmbedOptions).footer = { + (embeds[i] as APIEmbed).footer = { text: `Page ${(i + 1).toLocaleString()}/${embeds.length.toLocaleString()}` }; } @@ -96,16 +88,9 @@ export class ButtonPaginator { })) as BushMessage; const collector = this.sentMessage.createMessageComponentCollector({ - componentType: ComponentType.Button, - filter: (i) => { - const ret = i.customId.startsWith('paginate_') && i.message.id === this.sentMessage!.id; - console.debug(ret); - return ret; - }, - idle: 300000 + filter: (i) => i.customId.startsWith('paginate_'), + time: 300_000 }); - console.debug('got here'); - collector.on('collect', (i) => void this.collect(i)); collector.on('end', () => void this.end()); } @@ -115,9 +100,8 @@ 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': @@ -130,16 +114,17 @@ 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': @@ -158,12 +143,13 @@ 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); } /** @@ -171,12 +157,13 @@ 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); } /** @@ -224,7 +211,7 @@ export class ButtonPaginator { */ public static async send( message: BushMessage | BushSlashMessage, - embeds: MessageEmbed[] | MessageEmbedOptions[], + embeds: (Embed | APIEmbed)[], text: string | null = null, deleteOnExit = true, startOn = 1 diff --git a/src/lib/common/DeleteButton.ts b/src/lib/common/DeleteButton.ts index edc40fe..cf3b416 100644 --- a/src/lib/common/DeleteButton.ts +++ b/src/lib/common/DeleteButton.ts @@ -1,6 +1,14 @@ import { PaginateEmojis, type BushMessage, type BushSlashMessage } from '#lib'; import { CommandUtil } from 'discord-akairo'; -import { ActionRow, ButtonComponent, ButtonStyle, MessageComponentInteraction, type MessageOptions } from 'discord.js'; +import { + ActionRow, + ButtonComponent, + ButtonStyle, + MessageComponentInteraction, + MessageEditOptions, + MessagePayload, + type MessageOptions +} from 'discord.js'; /** * Sends a message with a button for the user to delete it. @@ -47,7 +55,7 @@ export class DeleteButton { collector.on('end', async () => { this.updateComponents(true, true); - await msg.edit(this.messageOptions).catch(() => undefined); + await msg.edit(this.messageOptions).catch(() => undefined); }); } diff --git a/src/lib/common/util/Moderation.ts b/src/lib/common/util/Moderation.ts index 84d9fbf..62dbc90 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, Permissions, type Snowflake } from 'discord.js'; +import { Embed, Permissions, type Snowflake } from 'discord.js'; /** * A utility class with moderation-related methods. @@ -208,7 +208,7 @@ export class Moderation { const ending = await options.guild.getSetting('punishmentEnding'); const dmEmbed = ending && ending.length && options.sendFooter - ? new MessageEmbed().setDescription(ending).setColor(util.colors.newBlurple) + ? new Embed().setDescription(ending).setColor(util.colors.newBlurple) : undefined; const dmSuccess = await client.users diff --git a/src/lib/extensions/discord-akairo/BushClient.ts b/src/lib/extensions/discord-akairo/BushClient.ts index 01620a8..712d610 100644 --- a/src/lib/extensions/discord-akairo/BushClient.ts +++ b/src/lib/extensions/discord-akairo/BushClient.ts @@ -190,6 +190,7 @@ export class BushClient extends AkairoClient acc | p, 0), + partials: ['USER', 'CHANNEL', 'GUILD_MEMBER', 'MESSAGE', 'REACTION', 'GUILD_SCHEDULED_EVENT'], presence: { activities: [ { diff --git a/src/lib/extensions/discord-akairo/BushClientUtil.ts b/src/lib/extensions/discord-akairo/BushClientUtil.ts index 79aa4c1..968a805 100644 --- a/src/lib/extensions/discord-akairo/BushClientUtil.ts +++ b/src/lib/extensions/discord-akairo/BushClientUtil.ts @@ -16,21 +16,19 @@ import { type Pronoun, type PronounCode } from '#lib'; -import type { APIMessage } from '@discordjs/builders/node_modules/discord-api-types'; import { humanizeDuration } from '@notenoughupdates/humanize-duration'; import { exec } from 'child_process'; import deepLock from 'deep-lock'; import { ClientUtil, Util as AkairoUtil } from 'discord-akairo'; +import type { APIMessage } from 'discord-api-types'; import { Constants as DiscordConstants, GuildMember, Message, - MessageEmbed, Permissions, ThreadMember, User, Util as DiscordUtil, - type ColorResolvable, type CommandInteraction, type InteractionReplyOptions, type Snowflake, @@ -196,27 +194,6 @@ export class BushClientUtil extends ClientUtil { return client.consts.emojis; } - /** - * A simple utility to create and embed with the needed style for the bot. - * @param color The color to set the embed to. - * @param author The author to set the embed to. - * @returns The generated embed. - */ - public createEmbed(color?: ColorResolvable, author?: User | GuildMember): MessageEmbed { - if (author instanceof GuildMember) { - author = author.user; // Convert to User if GuildMember - } - let embed = new MessageEmbed().setTimestamp(); - if (author) - embed = embed.setAuthor({ - name: author.username, - iconURL: author.displayAvatarURL(), - url: `https://discord.com/users/${author.id}` - }); - if (color) embed = embed.setColor(color); - return embed; - } - /** * Fetches a user's uuid from the mojang api. * @param username The username to get the uuid of. diff --git a/src/lib/extensions/discord.js/BushButtonInteraction.ts b/src/lib/extensions/discord.js/BushButtonInteraction.ts index 191ad5c..b7ad77c 100644 --- a/src/lib/extensions/discord.js/BushButtonInteraction.ts +++ b/src/lib/extensions/discord.js/BushButtonInteraction.ts @@ -1,5 +1,5 @@ import type { BushClient, BushGuild, BushGuildMember, BushGuildTextBasedChannel, BushTextBasedChannel, BushUser } from '#lib'; -import type { APIInteractionGuildMember } from '@discordjs/builders/node_modules/discord-api-types/payloads/v9/_interactions/base'; +import type { APIInteractionGuildMember } from 'discord-api-types'; import { ButtonInteraction, type CacheType, type CacheTypeReducer } from 'discord.js'; import type { RawMessageButtonInteractionData } from 'discord.js/typings/rawDataTypes'; diff --git a/src/lib/extensions/discord.js/BushChatInputCommandInteraction.ts b/src/lib/extensions/discord.js/BushChatInputCommandInteraction.ts index 56bef21..4d68f79 100644 --- a/src/lib/extensions/discord.js/BushChatInputCommandInteraction.ts +++ b/src/lib/extensions/discord.js/BushChatInputCommandInteraction.ts @@ -10,7 +10,7 @@ import type { BushTextBasedChannel, BushUser } from '#lib'; -import type { APIInteractionGuildMember } from '@discordjs/builders/node_modules/discord-api-types'; +import type { APIInteractionGuildMember } from 'discord-api-types'; import { ChatInputCommandInteraction, type CacheType, type CacheTypeReducer, type Invite, type Snowflake } from 'discord.js'; import type { RawCommandInteractionData } from 'discord.js/typings/rawDataTypes'; diff --git a/src/lib/extensions/discord.js/BushGuild.ts b/src/lib/extensions/discord.js/BushGuild.ts index 9f114b6..bbef953 100644 --- a/src/lib/extensions/discord.js/BushGuild.ts +++ b/src/lib/extensions/discord.js/BushGuild.ts @@ -367,11 +367,11 @@ export class BushGuild extends Guild { await channel.send({ embeds: [ { - author: { name: moderator.user.tag, iconURL: moderator.displayAvatarURL() }, + author: { name: moderator.user.tag, icon_url: moderator.displayAvatarURL() }, title: `This channel has been ${options.unlock ? 'un' : ''}locked`, description: options.reason ?? 'No reason provided', color: options.unlock ? util.colors.discord.GREEN : util.colors.discord.RED, - timestamp: Date.now() + timestamp: new Date().toISOString() } ] }); diff --git a/src/lib/extensions/discord.js/BushSelectMenuInteraction.ts b/src/lib/extensions/discord.js/BushSelectMenuInteraction.ts index 23e2453..2c7c329 100644 --- a/src/lib/extensions/discord.js/BushSelectMenuInteraction.ts +++ b/src/lib/extensions/discord.js/BushSelectMenuInteraction.ts @@ -1,5 +1,5 @@ import type { BushClient, BushGuild, BushGuildMember, BushGuildTextBasedChannel, BushTextBasedChannel, BushUser } from '#lib'; -import type { APIInteractionGuildMember } from '@discordjs/builders/node_modules/discord-api-types'; +import type { APIInteractionGuildMember } from 'discord-api-types'; import { SelectMenuInteraction, type CacheType, type CacheTypeReducer } from 'discord.js'; import type { RawMessageSelectMenuInteractionData } from 'discord.js/typings/rawDataTypes'; diff --git a/src/lib/models/Guild.ts b/src/lib/models/Guild.ts index fd90dbf..7e67e21 100644 --- a/src/lib/models/Guild.ts +++ b/src/lib/models/Guild.ts @@ -182,7 +182,7 @@ export interface GuildSetting { name: string; description: string; type: GuildSettingType; - subType: (keyof typeof ChannelType)[] | undefined; + subType: ChannelType[] | undefined; configurable: boolean; } const asGuildSetting = (et: { [K in keyof T]: GuildSetting }) => et; @@ -199,14 +199,20 @@ export const guildSettingsObj = asGuildSetting({ name: 'Auto Publish Channels', description: 'Channels were every message is automatically published.', type: 'channel-array', - subType: ['GuildNews'], + subType: [ChannelType.GuildNews], configurable: true }, welcomeChannel: { name: 'Welcome Channel', description: 'The channel where the bot will send join and leave message.', type: 'channel', - subType: ['GuildText', 'GuildNews', 'GuildNewsThread', 'GuildPublicThread', 'GuildPrivateThread'], + subType: [ + ChannelType.GuildText, + ChannelType.GuildNews, + ChannelType.GuildNewsThread, + ChannelType.GuildPublicThread, + ChannelType.GuildPrivateThread + ], configurable: true }, muteRole: { @@ -227,7 +233,7 @@ export const guildSettingsObj = asGuildSetting({ name: 'Lockdown Channels', description: 'Channels that are locked down when a mass lockdown is specified.', type: 'channel-array', - subType: ['GuildText'], + subType: [ChannelType.GuildText], configurable: true }, joinRoles: { @@ -248,7 +254,7 @@ export const guildSettingsObj = asGuildSetting({ name: 'Log Channels', description: 'The channel were logs are sent.', type: 'custom', - subType: ['GuildText'], + subType: [ChannelType.GuildText], configurable: false }, autoModPhases: { @@ -262,7 +268,13 @@ export const guildSettingsObj = asGuildSetting({ name: 'No Xp Channels', description: 'Channels where users will not earn xp for leveling.', type: 'channel-array', - subType: ['GuildText', 'GuildNews', 'GuildNewsThread', 'GuildPublicThread', 'GuildPrivateThread'], + subType: [ + ChannelType.GuildText, + ChannelType.GuildNews, + ChannelType.GuildNewsThread, + ChannelType.GuildPublicThread, + ChannelType.GuildPrivateThread + ], configurable: true }, levelRoles: { @@ -276,7 +288,13 @@ export const guildSettingsObj = asGuildSetting({ name: 'Level Up Channel', description: 'The channel to send level up messages in instead of last channel.', type: 'channel', - subType: ['GuildText', 'GuildNews', 'GuildNewsThread', 'GuildPublicThread', 'GuildPrivateThread'], + subType: [ + ChannelType.GuildText, + ChannelType.GuildNews, + ChannelType.GuildNewsThread, + ChannelType.GuildPublicThread, + ChannelType.GuildPrivateThread + ], configurable: true } }); diff --git a/src/lib/utils/BushConstants.ts b/src/lib/utils/BushConstants.ts index e8366a1..4e73672 100644 --- a/src/lib/utils/BushConstants.ts +++ b/src/lib/utils/BushConstants.ts @@ -23,28 +23,28 @@ export class BushConstants { } as const); public static colors = BushClientUtil.deepFreeze({ - default: '#1FD8F1', - error: '#EF4947', - warn: '#FEBA12', - success: '#3BB681', - info: '#3B78FF', - red: '#ff0000', - blue: '#0055ff', - aqua: '#00bbff', - purple: '#8400ff', - blurple: '#5440cd', - newBlurple: '#5865f2', - pink: '#ff00e6', - green: '#00ff1e', - darkGreen: '#008f11', - gold: '#b59400', - yellow: '#ffff00', - white: '#ffffff', - gray: '#a6a6a6', - lightGray: '#cfcfcf', - darkGray: '#7a7a7a', - black: '#000000', - orange: '#E86100', + default: 0x1fd8f1, + error: 0xef4947, + warn: 0xfeba12, + success: 0x3bb681, + info: 0x3b78ff, + red: 0xff0000, + blue: 0x0055ff, + aqua: 0x00bbff, + purple: 0x8400ff, + blurple: 0x5440cd, + newBlurple: 0x5865f2, + pink: 0xff00e6, + green: 0x00ff1e, + darkGreen: 0x008f11, + gold: 0xb59400, + yellow: 0xffff00, + white: 0xffffff, + gray: 0xa6a6a6, + lightGray: 0xcfcfcf, + darkGray: 0x7a7a7a, + black: 0x000000, + orange: 0xe86100, discord: Object.assign({}, Constants.Colors) } as const); diff --git a/src/lib/utils/BushLogger.ts b/src/lib/utils/BushLogger.ts index 476a86d..341fb7e 100644 --- a/src/lib/utils/BushLogger.ts +++ b/src/lib/utils/BushLogger.ts @@ -1,6 +1,6 @@ import chalk from 'chalk'; // eslint-disable-next-line @typescript-eslint/no-unused-vars -import { MessageEmbed, Util, type Message, type PartialTextBasedChannelFields } from 'discord.js'; +import { Embed, Util, type Message, type PartialTextBasedChannelFields } from 'discord.js'; import { inspect } from 'util'; import { type BushSendMessageType } from '../extensions/discord-akairo/BushClient'; @@ -152,7 +152,7 @@ export class BushLogger { `${chalk.bgGrey(this.#getTimeStamp())} ${chalk.grey(`[${header}]`)} ${this.#parseFormatting(newContent, 'blackBright')}` ); if (!sendChannel) return; - const embed = new MessageEmbed() + const embed = new Embed() .setDescription(`**[${header}]** ${this.#parseFormatting(this.#stripColor(newContent), '', true)}`) .setColor(util.colors.gray) .setTimestamp(); @@ -197,7 +197,7 @@ export class BushLogger { `${chalk.bgCyan(this.#getTimeStamp())} ${chalk.cyan(`[${header}]`)} ${this.#parseFormatting(newContent, 'blueBright')}` ); if (!sendChannel) return; - const embed = new MessageEmbed() + const embed = new Embed() .setDescription(`**[${header}]** ${this.#parseFormatting(this.#stripColor(newContent), '', true)}`) .setColor(util.colors.info) .setTimestamp(); @@ -221,7 +221,7 @@ export class BushLogger { ); if (!sendChannel) return; - const embed = new MessageEmbed() + const embed = new Embed() .setDescription(`**[${header}]** ${this.#parseFormatting(this.#stripColor(newContent), '', true)}`) .setColor(util.colors.warn) .setTimestamp(); @@ -244,7 +244,7 @@ export class BushLogger { )}` ); if (!sendChannel) return; - const embed = new MessageEmbed() + const embed = new Embed() .setDescription(`**[${header}]** ${this.#parseFormatting(this.#stripColor(newContent), '', true)}`) .setColor(util.colors.error) .setTimestamp(); @@ -268,7 +268,7 @@ export class BushLogger { )}` ); if (!sendChannel) return; - const embed = new MessageEmbed() + const embed = new Embed() .setDescription(`**[${header}]** ${this.#parseFormatting(this.#stripColor(newContent), '', true)}`) .setColor(util.colors.success) .setTimestamp(); -- cgit