From e78beed6c7e094ef48aad5d18da01b2bbed4536c Mon Sep 17 00:00:00 2001 From: IRONM00N <64110067+IRONM00N@users.noreply.github.com> Date: Sat, 19 Feb 2022 18:52:41 -0500 Subject: fix: a ton of shit --- src/lib/common/AutoMod.ts | 1 + src/lib/extensions/discord-akairo/BushClient.ts | 11 +++- .../extensions/discord-akairo/BushClientUtil.ts | 66 +++++++++++++--------- .../extensions/discord.js/BushCategoryChannel.ts | 11 ++-- .../discord.js/BushCategoryChannelChildManager.ts | 52 +++++++++++++++++ src/lib/extensions/discord.js/other.ts | 2 + src/lib/index.ts | 1 + src/lib/utils/CanvasProgressBar.ts | 2 + 8 files changed, 110 insertions(+), 36 deletions(-) create mode 100644 src/lib/extensions/discord.js/BushCategoryChannelChildManager.ts (limited to 'src/lib') 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 extends AkairoClient [snakeCase(key), jsonTransformer(value)])); +} diff --git a/src/lib/extensions/discord-akairo/BushClientUtil.ts b/src/lib/extensions/discord-akairo/BushClientUtil.ts index 4184723..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, @@ -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!]!; } @@ -923,6 +911,23 @@ export class BushClientUtil extends ClientUtil { } } + public async castDurationContent( + arg: string | ParsedDuration | null, + message: BushMessage | BushSlashMessage + ): Promise { + const res = typeof arg === 'string' ? await util.arg.cast('contentWithDuration', message, arg) : arg; + + return { duration: res?.duration ?? 0, content: res?.content ?? '' }; + } + + public async cast( + 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>; + public declare readonly children: BushCategoryChannelChildManager; public declare guild: BushGuild; - public declare readonly members: Collection; - 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. + * You cannot create a channel of type {@link ChannelType.GuildCategory} inside a CategoryChannel. + * @param name The name of the new channel + * @param options Options for creating the new channel + */ + public create>( + name: string, + options: CategoryCreateChannelOptions & { type: T } + ): Promise; + /** + * Creates a new channel within this category. + * You cannot create a channel of type {@link ChannelType.GuildCategory} inside a CategoryChannel. + * @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; + public create(name: string, options?: CategoryCreateChannelOptions): Promise; +} 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; 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; -- cgit