diff options
| author | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2022-06-14 12:47:57 -0400 |
|---|---|---|
| committer | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2022-06-14 12:47:57 -0400 |
| commit | 661e4c9935aeb8760dafc7ced4bbec6cc356a033 (patch) | |
| tree | bb4c12bdef067d203f100e13e05ccb705b299834 /src/lib/extensions | |
| parent | eaf592b72eb5b1d66aa2bde5151a8947570a506c (diff) | |
| download | tanzanite-661e4c9935aeb8760dafc7ced4bbec6cc356a033.tar.gz tanzanite-661e4c9935aeb8760dafc7ced4bbec6cc356a033.tar.bz2 tanzanite-661e4c9935aeb8760dafc7ced4bbec6cc356a033.zip | |
remove the war crimes that I previously committed
- Remove custom typings and replace with declaration merging
- Fix the typings for args
- Replace all discord-api-types imports with discord.js imports
- Fix discord.js breaking changes
Diffstat (limited to 'src/lib/extensions')
64 files changed, 544 insertions, 3084 deletions
diff --git a/src/lib/extensions/discord-akairo/BushArgumentTypeCaster.ts b/src/lib/extensions/discord-akairo/BushArgumentTypeCaster.ts index 7a9a3db..def7ad6 100644 --- a/src/lib/extensions/discord-akairo/BushArgumentTypeCaster.ts +++ b/src/lib/extensions/discord-akairo/BushArgumentTypeCaster.ts @@ -1,3 +1,3 @@ -import { type BushMessage } from '#lib'; +import { type CommandMessage } from '#lib'; -export type BushArgumentTypeCaster<R = unknown> = (message: BushMessage, phrase: string) => R; +export type BushArgumentTypeCaster<R = unknown> = (message: CommandMessage, phrase: string) => R; diff --git a/src/lib/extensions/discord-akairo/BushClient.ts b/src/lib/extensions/discord-akairo/BushClient.ts index db0ad91..2644231 100644 --- a/src/lib/extensions/discord-akairo/BushClient.ts +++ b/src/lib/extensions/discord-akairo/BushClient.ts @@ -10,28 +10,20 @@ import { roleWithDuration, snowflake } from '#args'; -import type { - BushBaseGuildEmojiManager, - BushChannelManager, - BushClientEvents, - BushClientUser, - BushGuildManager, - BushUserManager, - BushUserResolvable, - Config -} from '#lib'; +import type { BushClientEvents, Config } from '#lib'; import { patch, type PatchedElements } from '@notenoughupdates/events-intercept'; import * as Sentry from '@sentry/node'; import { AkairoClient, - ArgumentPromptData, ContextMenuCommandHandler, - OtherwiseContentSupplier, - version as akairoVersion + version as akairoVersion, + type ArgumentPromptData, + type ClientUtil, + type OtherwiseContentSupplier } from 'discord-akairo'; -import { GatewayIntentBits } from 'discord-api-types/v10'; import { ActivityType, + GatewayIntentBits, MessagePayload, Options, Partials, @@ -45,19 +37,21 @@ import { type MessageOptions, type ReplyMessageOptions, type Snowflake, + type UserResolvable, type WebhookEditMessageOptions } from 'discord.js'; -import EventEmitter from 'events'; +import type EventEmitter from 'events'; import { google } from 'googleapis'; import path from 'path'; import readline from 'readline'; import type { Options as SequelizeOptions, Sequelize as SequelizeType } from 'sequelize'; import { fileURLToPath } from 'url'; +import { tinyColor } from '../../../arguments/tinyColor.js'; import UpdateCacheTask from '../../../tasks/updateCache.js'; import UpdateStatsTask from '../../../tasks/updateStats.js'; import { HighlightManager } from '../../common/HighlightManager.js'; import { ActivePunishment } from '../../models/instance/ActivePunishment.js'; -import { Guild as GuildModel } from '../../models/instance/Guild.js'; +import { Guild as GuildDB } from '../../models/instance/Guild.js'; import { Highlight } from '../../models/instance/Highlight.js'; import { Level } from '../../models/instance/Level.js'; import { ModLog } from '../../models/instance/ModLog.js'; @@ -71,26 +65,10 @@ import { AllowedMentions } from '../../utils/AllowedMentions.js'; import { BushCache } from '../../utils/BushCache.js'; 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 { 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'; -import { BushGuildMember } from '../discord.js/BushGuildMember.js'; -import { BushMessage } from '../discord.js/BushMessage.js'; -import { BushMessageReaction } from '../discord.js/BushMessageReaction.js'; -import { BushModalSubmitInteraction } from '../discord.js/BushModalSubmitInteraction.js'; -import { BushNewsChannel } from '../discord.js/BushNewsChannel.js'; -import { BushPresence } from '../discord.js/BushPresence.js'; -import { BushRole } from '../discord.js/BushRole.js'; -import { BushSelectMenuInteraction } from '../discord.js/BushSelectMenuInteraction.js'; -import { BushTextChannel } from '../discord.js/BushTextChannel.js'; -import { BushThreadChannel } from '../discord.js/BushThreadChannel.js'; -import { BushThreadMember } from '../discord.js/BushThreadMember.js'; -import { BushUser } from '../discord.js/BushUser.js'; -import { BushVoiceChannel } from '../discord.js/BushVoiceChannel.js'; -import { BushVoiceState } from '../discord.js/BushVoiceState.js'; +import { ExtendedGuild } from '../discord.js/ExtendedGuild.js'; +import { ExtendedGuildMember } from '../discord.js/ExtendedGuildMember.js'; +import { ExtendedMessage } from '../discord.js/ExtendedMessage.js'; +import { ExtendedUser } from '../discord.js/ExtendedUser.js'; import { BushClientUtil } from './BushClientUtil.js'; import { BushCommandHandler } from './BushCommandHandler.js'; import { BushInhibitorHandler } from './BushInhibitorHandler.js'; @@ -98,11 +76,43 @@ import { BushListenerHandler } from './BushListenerHandler.js'; import { BushTaskHandler } from './BushTaskHandler.js'; const { Sequelize } = (await import('sequelize')).default; -export type BushReplyMessageType = string | MessagePayload | ReplyMessageOptions; -export type BushEditMessageType = string | MessageEditOptions | MessagePayload; -export type BushSlashSendMessageType = string | MessagePayload | InteractionReplyOptions; -export type BushSlashEditMessageType = string | MessagePayload | WebhookEditMessageOptions; -export type BushSendMessageType = string | MessagePayload | MessageOptions; +declare module 'discord.js' { + export interface Client extends EventEmitter { + /** + * The ID of the owner(s). + */ + ownerID: Snowflake | Snowflake[]; + /** + * The ID of the superUser(s). + */ + superUserID: Snowflake | Snowflake[]; + /** + * Utility methods. + */ + util: ClientUtil | BushClientUtil; + on<K extends keyof BushClientEvents>(event: K, listener: (...args: BushClientEvents[K]) => Awaitable<void>): this; + once<K extends keyof BushClientEvents>(event: K, listener: (...args: BushClientEvents[K]) => Awaitable<void>): this; + emit<K extends keyof BushClientEvents>(event: K, ...args: BushClientEvents[K]): boolean; + off<K extends keyof BushClientEvents>(event: K, listener: (...args: BushClientEvents[K]) => Awaitable<void>): this; + removeAllListeners<K extends keyof BushClientEvents>(event?: K): this; + /** + * Checks if a user is the owner of this bot. + * @param user - User to check. + */ + isOwner(user: UserResolvable): boolean; + /** + * Checks if a user is a super user of this bot. + * @param user - User to check. + */ + isSuperUser(user: UserResolvable): boolean; + } +} + +export type ReplyMessageType = string | MessagePayload | ReplyMessageOptions; +export type EditMessageType = string | MessageEditOptions | MessagePayload; +export type SlashSendMessageType = string | MessagePayload | InteractionReplyOptions; +export type SlashEditMessageType = string | MessagePayload | WebhookEditMessageOptions; +export type SendMessageType = string | MessagePayload | MessageOptions; const rl = readline.createInterface({ input: process.stdin, @@ -116,12 +126,9 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url)); * The main hub for interacting with the Discord API. */ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Ready> { - public declare channels: BushChannelManager; - public declare guilds: BushGuildManager; - public declare user: If<Ready, BushClientUser>; - public declare users: BushUserManager; - public declare util: BushClientUtil; public declare ownerID: Snowflake[]; + public declare superUserID: Snowflake[]; + public declare util: BushClientUtil; /** * Whether or not the client is ready. @@ -272,7 +279,7 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re prefix: async ({ guild }: Message) => { if (this.config.isDevelopment) return 'dev '; if (!guild) return this.config.prefix; - const prefix = await (guild as BushGuild).getSetting('prefix'); + const prefix = await guild.getSetting('prefix'); return (prefix ?? this.config.prefix) as string; }, allowMention: true, @@ -296,7 +303,6 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re automateCategories: false, autoRegisterSlashCommands: true, skipBuiltInPostInhibitors: true, - useSlashPermissions: false, aliasReplacement: /-/g }); this.contextMenuCommandHandler = new ContextMenuCommandHandler(this, { @@ -342,26 +348,10 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re * Extends discord.js structures before the client is instantiated. */ public static extendStructures(): void { - Structures.extend('GuildEmoji', () => BushGuildEmoji); - Structures.extend('DMChannel', () => BushDMChannel); - Structures.extend('TextChannel', () => BushTextChannel); - Structures.extend('VoiceChannel', () => BushVoiceChannel); - Structures.extend('CategoryChannel', () => BushCategoryChannel); - Structures.extend('NewsChannel', () => BushNewsChannel); - Structures.extend('ThreadChannel', () => BushThreadChannel); - Structures.extend('GuildMember', () => BushGuildMember); - Structures.extend('ThreadMember', () => BushThreadMember); - Structures.extend('Guild', () => BushGuild); - Structures.extend('Message', () => BushMessage); - Structures.extend('MessageReaction', () => BushMessageReaction); - Structures.extend('Presence', () => BushPresence); - Structures.extend('VoiceState', () => BushVoiceState); - Structures.extend('Role', () => BushRole); - Structures.extend('User', () => BushUser); - Structures.extend('ChatInputCommandInteraction', () => BushChatInputCommandInteraction); - Structures.extend('ButtonInteraction', () => BushButtonInteraction); - Structures.extend('SelectMenuInteraction', () => BushSelectMenuInteraction); - Structures.extend('ModalSubmitInteraction', () => BushModalSubmitInteraction); + Structures.extend('GuildMember', () => ExtendedGuildMember); + Structures.extend('Guild', () => ExtendedGuild); + Structures.extend('Message', () => ExtendedMessage); + Structures.extend('User', () => ExtendedUser); } /** @@ -407,7 +397,8 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re abbreviatedNumber, durationSeconds, globalUser, - messageLink + messageLink, + tinyColor }); this.sentry = Sentry; @@ -448,7 +439,7 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re public async dbPreInit() { try { await this.instanceDB.authenticate(); - GuildModel.initModel(this.instanceDB, this); + GuildDB.initModel(this.instanceDB, this); ModLog.initModel(this.instanceDB); ActivePunishment.initModel(this.instanceDB); Level.initModel(this.instanceDB); @@ -527,33 +518,22 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re } } - public override isOwner(user: BushUserResolvable): boolean { + public override isOwner(user: UserResolvable): boolean { return this.config.owners.includes(this.users.resolveId(user!)!); } - public override isSuperUser(user: BushUserResolvable): boolean { + public override isSuperUser(user: UserResolvable): boolean { const userID = this.users.resolveId(user)!; return client.cache.shared.superUsers.includes(userID) || this.config.owners.includes(userID); } } export interface BushClient<Ready extends boolean = boolean> extends EventEmitter, PatchedElements, AkairoClient<Ready> { - get emojis(): BushBaseGuildEmojiManager; - on<K extends keyof BushClientEvents>(event: K, listener: (...args: BushClientEvents[K]) => Awaitable<void>): this; - // on<S extends string | symbol>(event: Exclude<S, keyof BushClientEvents>, listener: (...args: any[]) => Awaitable<void>): this; - once<K extends keyof BushClientEvents>(event: K, listener: (...args: BushClientEvents[K]) => Awaitable<void>): this; - // once<S extends string | symbol>(event: Exclude<S, keyof BushClientEvents>, listener: (...args: any[]) => Awaitable<void>): this; - emit<K extends keyof BushClientEvents>(event: K, ...args: BushClientEvents[K]): boolean; - // emit<S extends string | symbol>(event: Exclude<S, keyof BushClientEvents>, ...args: unknown[]): boolean; - off<K extends keyof BushClientEvents>(event: K, listener: (...args: BushClientEvents[K]) => Awaitable<void>): this; - // off<S extends string | symbol>(event: Exclude<S, keyof BushClientEvents>, listener: (...args: any[]) => Awaitable<void>): this; - removeAllListeners<K extends keyof BushClientEvents>(event?: K): this; - // removeAllListeners<S extends string | symbol>(event?: Exclude<S, keyof BushClientEvents>): this; } export interface BushStats { diff --git a/src/lib/extensions/discord-akairo/BushClientUtil.ts b/src/lib/extensions/discord-akairo/BushClientUtil.ts index 9fe70fa..19810bd 100644 --- a/src/lib/extensions/discord-akairo/BushClientUtil.ts +++ b/src/lib/extensions/discord-akairo/BushClientUtil.ts @@ -1,41 +1,43 @@ import { Arg, - BaseBushArgumentType, BushConstants, + CommandMessage, Global, Shared, - SharedCache, + type BaseBushArgumentType, type BushClient, type BushInspectOptions, - type BushMessage, - type BushSlashEditMessageType, - type BushSlashMessage, - type BushSlashSendMessageType, - type BushUser, type CodeBlockLang, type GlobalCache, type Pronoun, - type PronounCode + type PronounCode, + type SharedCache, + type SlashEditMessageType, + type SlashMessage, + type SlashSendMessageType } from '#lib'; import { humanizeDuration } from '@notenoughupdates/humanize-duration'; import assert from 'assert'; import { exec } from 'child_process'; import deepLock from 'deep-lock'; import { ClientUtil, Util as AkairoUtil } from 'discord-akairo'; -import { APIEmbed, APIMessage, OAuth2Scopes, Routes } from 'discord-api-types/v10'; import { Constants as DiscordConstants, EmbedBuilder, GuildMember, Message, + OAuth2Scopes, PermissionFlagsBits, PermissionsBitField, - PermissionsString, + Routes, ThreadMember, User, Util as DiscordUtil, + type APIEmbed, + type APIMessage, type CommandInteraction, type InteractionReplyOptions, + type PermissionsString, type Snowflake, type TextChannel, type UserResolvable @@ -377,7 +379,7 @@ export class BushClientUtil extends ClientUtil { */ public async slashRespond( interaction: CommandInteraction, - responseOptions: BushSlashSendMessageType | BushSlashEditMessageType + responseOptions: SlashSendMessageType | SlashEditMessageType ): Promise<Message | APIMessage | undefined> { const newResponseOptions = typeof responseOptions === 'string' ? { content: responseOptions } : responseOptions; if (interaction.replied || interaction.deferred) { @@ -696,17 +698,17 @@ export class BushClientUtil extends ClientUtil { * @param user The user to fetch * @returns Undefined if the user is not found, otherwise the user. */ - public async resolveNonCachedUser(user: UserResolvable | undefined | null): Promise<BushUser | undefined> { + public async resolveNonCachedUser(user: UserResolvable | undefined | null): Promise<User | undefined> { if (user == null) return undefined; const resolvedUser = user instanceof User - ? <BushUser>user + ? user : user instanceof GuildMember - ? <BushUser>user.user + ? user.user : user instanceof ThreadMember - ? <BushUser>user.user + ? user.user : user instanceof Message - ? <BushUser>user.author + ? user.author : undefined; return resolvedUser ?? (await client.users.fetch(user as Snowflake).catch(() => undefined)); @@ -831,9 +833,10 @@ export class BushClientUtil extends ClientUtil { * @returns The missing permissions or null if none are missing. */ public userGuildPermCheck( - message: BushMessage | BushSlashMessage, + message: CommandMessage | SlashMessage, permissions: typeof PermissionFlagsBits[keyof typeof PermissionFlagsBits][] ): PermissionsString[] | null { + if (!message.inGuild()) return null; const missing = message.member?.permissions.missing(permissions) ?? []; return missing.length ? missing : null; @@ -845,7 +848,7 @@ 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: bigint[]): PermissionsString[] | null { + public clientGuildPermCheck(message: CommandMessage | SlashMessage, permissions: bigint[]): PermissionsString[] | null { const missing = message.guild?.members.me?.permissions.missing(permissions) ?? []; return missing.length ? missing : null; @@ -860,7 +863,7 @@ export class BushClientUtil extends ClientUtil { * @returns The missing permissions or null if none are missing. */ public clientSendAndPermCheck( - message: BushMessage | BushSlashMessage, + message: CommandMessage | SlashMessage, permissions: bigint[] = [], checkChannel = false ): PermissionsString[] | null { @@ -868,7 +871,7 @@ export class BushClientUtil extends ClientUtil { const sendPerm = message.channel!.isThread() ? 'SendMessages' : 'SendMessagesInThreads'; if (!message.inGuild()) return null; - if (!message.guild.members.me!.permissionsIn(message.channel.id).has(sendPerm)) missing.push(sendPerm); + if (!message.guild.members.me!.permissionsIn(message.channel!.id).has(sendPerm)) missing.push(sendPerm); missing.push( ...(checkChannel @@ -884,7 +887,7 @@ export class BushClientUtil extends ClientUtil { * @param message The message to get the prefix from. * @returns The prefix. */ |
