diff options
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/common/AutoMod.ts | 1 | ||||
-rw-r--r-- | src/lib/extensions/discord-akairo/BushClient.ts | 11 | ||||
-rw-r--r-- | src/lib/extensions/discord-akairo/BushClientUtil.ts | 76 | ||||
-rw-r--r-- | src/lib/extensions/discord.js/BushCategoryChannel.ts | 11 | ||||
-rw-r--r-- | src/lib/extensions/discord.js/BushCategoryChannelChildManager.ts | 52 | ||||
-rw-r--r-- | src/lib/extensions/discord.js/other.ts | 2 | ||||
-rw-r--r-- | src/lib/index.ts | 1 | ||||
-rw-r--r-- | src/lib/utils/CanvasProgressBar.ts | 2 |
8 files changed, 115 insertions, 41 deletions
diff --git a/src/lib/common/AutoMod.ts b/src/lib/common/AutoMod.ts index fc5532b..3b22935 100644 --- a/src/lib/common/AutoMod.ts +++ b/src/lib/common/AutoMod.ts @@ -178,6 +178,7 @@ export class AutoMod { } private async checkPerspectiveApi() { + return; if (!client.config.isDevelopment) return; if (!this.message.content) return; diff --git a/src/lib/extensions/discord-akairo/BushClient.ts b/src/lib/extensions/discord-akairo/BushClient.ts index 43ae139..e46e701 100644 --- a/src/lib/extensions/discord-akairo/BushClient.ts +++ b/src/lib/extensions/discord-akairo/BushClient.ts @@ -42,6 +42,7 @@ import { } from 'discord.js'; import EventEmitter from 'events'; import { google } from 'googleapis'; +import snakeCase from 'lodash.snakecase'; import path from 'path'; import readline from 'readline'; import type { Options as SequelizeOptions, Sequelize as SequelizeType } from 'sequelize'; @@ -213,7 +214,9 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re allowedMentions: AllowedMentions.users(), // No everyone or role mentions by default makeCache: Options.cacheWithLimits({}), failIfNotExists: false, - rest: { api: 'https://canary.discord.com/api' } + rest: { api: 'https://canary.discord.com/api' }, + // todo: remove this when https://github.com/discordjs/discord.js/pull/7497 is merged + jsonTransformer }); patch(this); @@ -542,3 +545,9 @@ enum GatewayIntentBits { DirectMessageTyping = 16384, GuildScheduledEvents = 65536 } + +function jsonTransformer(obj: any): any { + if (typeof obj !== 'object' || !obj) return obj; + if (Array.isArray(obj)) return obj.map(jsonTransformer); + return Object.fromEntries(Object.entries(obj).map(([key, value]) => [snakeCase(key), jsonTransformer(value)])); +} diff --git a/src/lib/extensions/discord-akairo/BushClientUtil.ts b/src/lib/extensions/discord-akairo/BushClientUtil.ts index bf4dfaf..ecfa360 100644 --- a/src/lib/extensions/discord-akairo/BushClientUtil.ts +++ b/src/lib/extensions/discord-akairo/BushClientUtil.ts @@ -1,5 +1,6 @@ import { Arg, + BaseBushArgumentType, BushConstants, Global, Shared, @@ -21,7 +22,7 @@ import assert from 'assert'; 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/v9'; +import { APIMessage, OAuth2Scopes } from 'discord-api-types/v9'; import { Constants as DiscordConstants, GuildMember, @@ -266,31 +267,18 @@ export class BushClientUtil extends ClientUtil { * @returns The default options combined with the specified options. */ #getDefaultInspectOptions(options?: BushInspectOptions): BushInspectOptions { - const { - showHidden = false, - depth = 2, - colors = false, - customInspect = true, - showProxy = false, - maxArrayLength = Infinity, - maxStringLength = Infinity, - breakLength = 80, - compact = 3, - sorted = false, - getters = true - } = options ?? {}; return { - showHidden, - depth, - colors, - customInspect, - showProxy, - maxArrayLength, - maxStringLength, - breakLength, - compact, - sorted, - getters + showHidden: options?.showHidden ?? false, + depth: options?.depth ?? 2, + colors: options?.colors ?? false, + customInspect: options?.customInspect ?? true, + showProxy: options?.showProxy ?? false, + maxArrayLength: options?.maxArrayLength ?? Infinity, + maxStringLength: options?.maxStringLength ?? Infinity, + breakLength: options?.breakLength ?? 80, + compact: options?.compact ?? 3, + sorted: options?.sorted ?? false, + getters: options?.getters ?? true }; } @@ -556,7 +544,7 @@ export class BushClientUtil extends ClientUtil { * @returns The {@link ParsedDuration}. */ public parseDuration(content: string, remove = true): ParsedDuration { - if (!content) return { duration: 0, contentWithoutTime: null }; + if (!content) return { duration: 0, content: null }; // eslint-disable-next-line prefer-const let duration: number | null = null; @@ -574,7 +562,7 @@ export class BushClientUtil extends ClientUtil { } // remove the space added earlier if (contentWithoutTime.startsWith(' ')) contentWithoutTime.replace(' ', ''); - return { duration, contentWithoutTime }; + return { duration, content: contentWithoutTime }; } /** @@ -716,7 +704,7 @@ export class BushClientUtil extends ClientUtil { .catch(() => undefined)) as { pronouns: PronounCode } | undefined; if (!apiRes) return undefined; - if (!apiRes.pronouns) throw new Error('apiRes.pronouns is undefined'); + assert(apiRes.pronouns); return client.constants.pronounMapping[apiRes.pronouns!]!; } @@ -911,10 +899,10 @@ export class BushClientUtil extends ClientUtil { * The link to invite the bot with all permissions. */ public get invite() { - return `https://discord.com/api/oauth2/authorize?client_id=${Buffer.from( - client.token!.split('.')[0], - 'base64' - ).toString()}&permissions=${PermissionsBitField.All}&scope=bot%20applications.commands`; + return client.generateInvite({ + permissions: PermissionsBitField.All, + scopes: [OAuth2Scopes.Bot, OAuth2Scopes.ApplicationsCommands] + }); } public assertAll(...args: any[]): void { @@ -923,6 +911,23 @@ export class BushClientUtil extends ClientUtil { } } + public async castDurationContent( + arg: string | ParsedDuration | null, + message: BushMessage | BushSlashMessage + ): Promise<ParsedDurationRes> { + const res = typeof arg === 'string' ? await util.arg.cast('contentWithDuration', message, arg) : arg; + + return { duration: res?.duration ?? 0, content: res?.content ?? '' }; + } + + public async cast<T extends keyof BaseBushArgumentType>( + type: T, + arg: BaseBushArgumentType[T] | string, + message: BushMessage | BushSlashMessage + ) { + return typeof arg === 'string' ? await util.arg.cast(type, message, arg) : arg; + } + /** * A wrapper for the Argument class that adds custom typings. */ @@ -989,5 +994,10 @@ export interface HasteResults { export interface ParsedDuration { duration: number | null; - contentWithoutTime: string | null; + content: string | null; +} + +export interface ParsedDurationRes { + duration: number; + content: string; } diff --git a/src/lib/extensions/discord.js/BushCategoryChannel.ts b/src/lib/extensions/discord.js/BushCategoryChannel.ts index ac82bf0..3868b54 100644 --- a/src/lib/extensions/discord.js/BushCategoryChannel.ts +++ b/src/lib/extensions/discord.js/BushCategoryChannel.ts @@ -2,7 +2,6 @@ import { BushDMChannel, BushGuildBasedChannel, BushNewsChannel, - BushNonThreadGuildBasedChannel, BushStageChannel, BushStoreChannel, BushTextBasedChannel, @@ -10,11 +9,11 @@ import { BushThreadChannel, BushVoiceBasedChannel, BushVoiceChannel, + type BushCategoryChannelChildManager, type BushClient, - type BushGuild, - type BushGuildMember + type BushGuild } from '#lib'; -import { CategoryChannel, type Collection, type Snowflake } from 'discord.js'; +import { CategoryChannel } from 'discord.js'; import { type RawGuildChannelData } from 'discord.js/typings/rawDataTypes'; /** @@ -22,10 +21,8 @@ import { type RawGuildChannelData } from 'discord.js/typings/rawDataTypes'; */ export class BushCategoryChannel extends CategoryChannel { public declare readonly client: BushClient; - public declare readonly children: Collection<Snowflake, Exclude<BushNonThreadGuildBasedChannel, BushCategoryChannel>>; + public declare readonly children: BushCategoryChannelChildManager; public declare guild: BushGuild; - public declare readonly members: Collection<Snowflake, BushGuildMember>; - public declare readonly parent: CategoryChannel | null; public constructor(guild: BushGuild, data?: RawGuildChannelData, client?: BushClient, immediatePatch?: boolean) { super(guild, data, client, immediatePatch); diff --git a/src/lib/extensions/discord.js/BushCategoryChannelChildManager.ts b/src/lib/extensions/discord.js/BushCategoryChannelChildManager.ts new file mode 100644 index 0000000..b9a7ac7 --- /dev/null +++ b/src/lib/extensions/discord.js/BushCategoryChannelChildManager.ts @@ -0,0 +1,52 @@ +/* eslint-disable deprecation/deprecation */ +import type { + BushCategoryChannel, + BushGuild, + BushGuildChannelResolvable, + BushMappedChannelCategoryTypes, + BushNonCategoryGuildBasedChannel, + BushStoreChannel, + BushTextChannel +} from '#lib'; +import type { CategoryChannelType, CategoryCreateChannelOptions, ChannelType, DataManager, Snowflake } from 'discord.js'; + +export declare class BushCategoryChannelChildManager extends DataManager< + Snowflake, + BushNonCategoryGuildBasedChannel, + BushGuildChannelResolvable +> { + private constructor(channel: BushCategoryChannel); + + /** + * The category channel this manager belongs to + */ + public channel: BushCategoryChannel; + + /** + * The guild this manager belongs to + */ + public readonly guild: BushGuild; + + /** + * Creates a new channel within this category. + * <info>You cannot create a channel of type {@link ChannelType.GuildCategory} inside a CategoryChannel.</info> + * @param name The name of the new channel + * @param options Options for creating the new channel + */ + public create<T extends Exclude<CategoryChannelType, ChannelType.GuildStore>>( + name: string, + options: CategoryCreateChannelOptions & { type: T } + ): Promise<BushMappedChannelCategoryTypes[T]>; + /** + * Creates a new channel within this category. + * <info>You cannot create a channel of type {@link ChannelType.GuildCategory} inside a CategoryChannel.</info> + * @param name The name of the new channel + * @param options Options for creating the new channel + * @deprecated See [Self-serve Game Selling Deprecation](https://support-dev.discord.com/hc/en-us/articles/4414590563479) for more information + */ + public create( + name: string, + options: CategoryCreateChannelOptions & { type: ChannelType.GuildStore } + ): Promise<BushStoreChannel>; + public create(name: string, options?: CategoryCreateChannelOptions): Promise<BushTextChannel>; +} diff --git a/src/lib/extensions/discord.js/other.ts b/src/lib/extensions/discord.js/other.ts index 784442d..e4bc10b 100644 --- a/src/lib/extensions/discord.js/other.ts +++ b/src/lib/extensions/discord.js/other.ts @@ -161,3 +161,5 @@ export enum BushInteractionType { MessageComponent = 3, ApplicationCommandAutocomplete = 4 } + +export type BushNonCategoryGuildBasedChannel = Exclude<BushGuildBasedChannel, BushCategoryChannel>; diff --git a/src/lib/index.ts b/src/lib/index.ts index 7a9ab5f..45d76b7 100644 --- a/src/lib/index.ts +++ b/src/lib/index.ts @@ -28,6 +28,7 @@ export type { BushBaseGuildEmojiManager } from './extensions/discord.js/BushBase export type { BushBaseGuildVoiceChannel } from './extensions/discord.js/BushBaseGuildVoiceChannel.js'; export * from './extensions/discord.js/BushButtonInteraction.js'; export * from './extensions/discord.js/BushCategoryChannel.js'; +export type { BushCategoryChannelChildManager } from './extensions/discord.js/BushCategoryChannelChildManager.js'; export type { BushChannel } from './extensions/discord.js/BushChannel.js'; export type { BushChannelManager } from './extensions/discord.js/BushChannelManager.js'; export * from './extensions/discord.js/BushChatInputCommandInteraction.js'; diff --git a/src/lib/utils/CanvasProgressBar.ts b/src/lib/utils/CanvasProgressBar.ts index 1ba0e8b..21c4e22 100644 --- a/src/lib/utils/CanvasProgressBar.ts +++ b/src/lib/utils/CanvasProgressBar.ts @@ -1,3 +1,5 @@ +import { CanvasRenderingContext2D } from 'canvas'; + // I just copy pasted this code from stackoverflow don't yell at me if there is issues for it export class CanvasProgressBar { private readonly x: number; |