From 32452911219a1045598f04af75f4d3f4baca71a5 Mon Sep 17 00:00:00 2001 From: MARCROCK22 Date: Sun, 15 Sep 2024 19:02:13 +0000 Subject: [PATCH] fix: actually using biome --- .changeset/config.json | 32 ++--- biome.json | 116 +++++++---------- commitlint.config.js | 2 +- src/api/Routes/guilds.ts | 4 +- src/api/api.ts | 6 +- src/builders/Attachment.ts | 8 +- src/cache/adapters/default.ts | 6 +- src/cache/adapters/limited.ts | 8 +- src/cache/adapters/workeradapter.ts | 6 +- src/cache/index.ts | 80 +++++++----- src/client/base.ts | 28 ++-- src/client/client.ts | 38 +++--- src/client/transformers.ts | 159 +++++++++-------------- src/client/workerclient.ts | 84 ++++++------ src/commands/applications/chat.ts | 56 ++++---- src/commands/applications/chatcontext.ts | 20 +-- src/commands/applications/options.ts | 10 +- src/commands/applications/shared.ts | 8 +- src/commands/decorators.ts | 22 ++-- src/commands/handle.ts | 80 +++++++----- src/commands/handler.ts | 71 +++++----- src/common/it/formatter.ts | 80 ++++++------ src/common/it/logger.ts | 6 +- src/common/it/utils.ts | 19 ++- src/common/shorters/bans.ts | 6 +- src/common/shorters/channels.ts | 26 ++-- src/common/shorters/emojis.ts | 8 +- src/common/shorters/guilds.ts | 14 +- src/common/shorters/members.ts | 12 +- src/common/shorters/webhook.ts | 17 +-- src/common/types/options.ts | 4 +- src/common/types/util.ts | 2 +- src/components/handler.ts | 6 +- src/components/index.ts | 3 +- src/deps/mixer.ts | 2 +- src/index.ts | 8 +- src/langs/router.ts | 2 +- src/structures/Interaction.ts | 42 +++--- src/structures/channels.ts | 87 +++++++------ src/structures/extra/BitField.ts | 3 +- src/types/payloads/user.ts | 1 - src/types/utils/index.ts | 1 - src/websocket/constants/index.ts | 5 - src/websocket/discord/shard.ts | 53 +++++--- src/websocket/discord/sharder.ts | 18 ++- src/websocket/discord/shared.ts | 4 +- src/websocket/discord/socket/custom.ts | 30 +++-- src/websocket/discord/worker.ts | 2 +- src/websocket/discord/workermanager.ts | 11 +- 49 files changed, 673 insertions(+), 643 deletions(-) diff --git a/.changeset/config.json b/.changeset/config.json index e888473..ae6f067 100644 --- a/.changeset/config.json +++ b/.changeset/config.json @@ -1,16 +1,16 @@ -{ - "$schema": "https://unpkg.com/@changesets/config@2.3.1/schema.json", - "changelog": [ - "@changesets/changelog-github", - { - "repo": "tiramisulabs/seyfert" - } - ], - "commit": false, - "fixed": [], - "linked": [], - "access": "restricted", - "baseBranch": "main", - "updateInternalDependencies": "patch", - "ignore": [] -} \ No newline at end of file +{ + "$schema": "https://unpkg.com/@changesets/config@2.3.1/schema.json", + "changelog": [ + "@changesets/changelog-github", + { + "repo": "tiramisulabs/seyfert" + } + ], + "commit": false, + "fixed": [], + "linked": [], + "access": "restricted", + "baseBranch": "main", + "updateInternalDependencies": "patch", + "ignore": [] +} diff --git a/biome.json b/biome.json index f284022..4ac270d 100644 --- a/biome.json +++ b/biome.json @@ -1,8 +1,30 @@ { - "$schema": "https://biomejs.dev/schemas/1.8.1/schema.json", + "$schema": "https://biomejs.dev/schemas/1.9.0/schema.json", + "vcs": { + "enabled": true, + "clientKind": "git", + "useIgnoreFile": true, + "defaultBranch": "main" + }, + "files": { + "ignoreUnknown": true, + "ignore": ["node_modules/", "build", "lib", "__test__", "package.json", "tsconfig.json", ".vscode"] + }, + "formatter": { + "enabled": true, + "indentStyle": "tab", + "indentWidth": 2, + "lineWidth": 120, + "lineEnding": "crlf", + "formatWithErrors": true + }, + "organizeImports": { + "enabled": true + }, "linter": { "enabled": true, "rules": { + "recommended": false, "all": true, "security": { "noGlobalEval": "off" @@ -10,92 +32,52 @@ "suspicious": { "noExplicitAny": "off", "noAssignInExpressions": "off", + "useAwait": "off", + "noConfusingVoidType": "off", + "noAsyncPromiseExecutor": "off", "noUnsafeDeclarationMerging": "off", "noEmptyInterface": "off", - "noConfusingVoidType": "off", - "noImplicitAnyLet": "off", - "noEmptyBlockStatements": "off", - "useAwait": "off", - "noConsoleLog": "off", - "noAsyncPromiseExecutor": "off", "noThenProperty": "off" }, - "style": { - "noNonNullAssertion": "off", - "noParameterAssign": "off", - "useExportType": "error", - "useImportType": "error", - "useNodejsImportProtocol": "error", - "useNamingConvention": "off", - "noParameterProperties": "off", - "useFilenamingConvention": "off", - "noNamespaceImport": "off", - "useSingleCaseStatement": "off", - "useBlockStatements": "off", - "useEnumInitializers": "off", - "noArguments": "off", - "useForOf": "off" - }, "correctness": { - "noUnusedVariables": "off", - "noNodejsModules": "off" + "noNodejsModules": "off", + "useImportExtensions": "off", + "noUnusedFunctionParameters": "off", + "noUnusedVariables": "off" }, - "nursery": { - "useImportRestrictions": "off" + "style": { + "noDefaultExport": "off", + "useBlockStatements": "off", + "noParameterProperties": "off", + "useNamingConvention": "off", + "noNonNullAssertion": "off", + "useForOf": "off", + "useDefaultSwitchClause": "off", + "noParameterAssign": "off", + "useFilenamingConvention": "off", + "useEnumInitializers": "off", + "useExplicitLengthCheck": "off", + "noNamespaceImport": "off" }, "complexity": { - "noUselessLoneBlockStatements": "warn", - "noBannedTypes": "off", "noForEach": "off", - "noUselessConstructor": "off", "noExcessiveCognitiveComplexity": "off", - "noStaticOnlyClass": "off" - }, - "a11y": { - "all": false + "noUselessConstructor": "off" }, "performance": { - "noDelete": "off", "noBarrelFile": "off", - "noReExportAll": "off" + "noDelete": "off", + "noReExportAll": "off", + "useTopLevelRegex": "off" } } }, - "json": { - "formatter": { - "enabled": true, - "indentWidth": 2, - "lineWidth": 80 - } - }, - "formatter": { - "enabled": true, - "indentWidth": 2, - "indentStyle": "tab", - "lineWidth": 120, - "lineEnding": "crlf", - "formatWithErrors": true - }, "javascript": { "formatter": { "quoteStyle": "single", + "semicolons": "always", "arrowParentheses": "asNeeded", - "bracketSameLine": true, - "semicolons": "always" + "bracketSameLine": true } - }, - "files": { - "ignoreUnknown": true, - "ignore": [ - "node_modules/", - "build", - "lib", - "__test__", - "package.json", - "tsconfig.json" - ] - }, - "organizeImports": { - "enabled": false } } diff --git a/commitlint.config.js b/commitlint.config.js index 422b194..f60a9b7 100644 --- a/commitlint.config.js +++ b/commitlint.config.js @@ -1 +1 @@ -module.exports = { extends: ['@commitlint/config-conventional'] }; +module.exports = { extends: ['@commitlint/config-conventional'] }; diff --git a/src/api/Routes/guilds.ts b/src/api/Routes/guilds.ts index acd3488..2d882bb 100644 --- a/src/api/Routes/guilds.ts +++ b/src/api/Routes/guilds.ts @@ -1,3 +1,4 @@ +import type { Identify, OmitInsert } from '../../common'; import type { APIThreadChannel, RESTDeleteAPIAutoModerationRuleResult, @@ -116,7 +117,6 @@ import type { RESTPutAPIGuildMemberRoleResult, RESTPutAPIGuildTemplateSyncResult, } from '../../types'; -import type { Identify, OmitInsert } from '../../common'; import type { ProxyRequestMethod } from '../Router'; import type { RestArguments } from '../api'; import type { RawFile } from '../shared'; @@ -334,7 +334,7 @@ export interface GuildRoutes { args: RestArguments< ProxyRequestMethod.Post, Omit, - {}, + object, OmitInsert[] >, ): Promise; diff --git a/src/api/api.ts b/src/api/api.ts index 483a347..8089b14 100644 --- a/src/api/api.ts +++ b/src/api/api.ts @@ -5,10 +5,10 @@ import type { WorkerSendApiRequest } from '../websocket/discord/worker'; import { CDNRouter, type ProxyRequestMethod } from './Router'; import { Bucket } from './bucket'; import { - DefaultUserAgent, type ApiHandlerInternalOptions, type ApiHandlerOptions, type ApiRequestOptions, + DefaultUserAgent, type HttpMethods, type RawFile, type RequestHeaders, @@ -54,7 +54,7 @@ export class ApiHandler { globalUnblock() { this.globalBlock = false; - let cb; + let cb: (() => void) | undefined; while ((cb = this.readyQueue.shift())) { cb(); } @@ -105,7 +105,7 @@ export class ApiHandler { request: { ...request, auth }, }); - let response; + let response: Response; try { const url = `${this.options.domain}/${this.options.baseUrl}${finalUrl}`; diff --git a/src/builders/Attachment.ts b/src/builders/Attachment.ts index cb35e8b..5130e0e 100644 --- a/src/builders/Attachment.ts +++ b/src/builders/Attachment.ts @@ -1,10 +1,10 @@ -import type { APIAttachment, RESTAPIAttachment } from '../types'; import { randomBytes } from 'node:crypto'; +import { promises } from 'node:fs'; import path from 'node:path'; -import type { UsingClient, RawFile } from '..'; +import type { RawFile, UsingClient } from '..'; import type { ImageResolvable, ObjectToLower } from '../common'; import { Base } from '../structures/extra/Base'; -import { promises } from 'node:fs'; +import type { APIAttachment, RESTAPIAttachment } from '../types'; export interface AttachmentResolvableMap { url: string; @@ -209,7 +209,7 @@ export async function resolveAttachmentData( if (Buffer.isBuffer(data)) return { data }; // @ts-expect-error if (typeof data[Symbol.asyncIterator] === 'function') { - const buffers = []; + const buffers: Buffer[] = []; for await (const resource of data as unknown as AsyncIterable) buffers.push(Buffer.from(resource)); return { data: Buffer.concat(buffers) }; } diff --git a/src/cache/adapters/default.ts b/src/cache/adapters/default.ts index c317138..85a572f 100644 --- a/src/cache/adapters/default.ts +++ b/src/cache/adapters/default.ts @@ -22,12 +22,14 @@ export class MemoryAdapter implements Adapter { }, ) {} - start() {} + start() { + // + } scan(query: string, keys?: false): any[]; scan(query: string, keys: true): string[]; scan(query: string, keys = false) { - const values = []; + const values: (string | unknown)[] = []; const sq = query.split('.'); for (const [key, value] of this.storage.entries()) { if (key.split('.').every((value, i) => (sq[i] === '*' ? !!value : sq[i] === value))) { diff --git a/src/cache/adapters/limited.ts b/src/cache/adapters/limited.ts index e70967f..27311e9 100644 --- a/src/cache/adapters/limited.ts +++ b/src/cache/adapters/limited.ts @@ -1,5 +1,5 @@ import { LimitedCollection } from '../..'; -import { MergeOptions, type MakeRequired } from '../../common'; +import { type MakeRequired, MergeOptions } from '../../common'; import type { Adapter } from './types'; //TODO: optimizar esto export interface ResourceLimitedMemoryAdapter { @@ -57,12 +57,14 @@ export class LimitedMemoryAdapter implements Adapter { ); } - start() {} + start() { + // + } scan(query: string, keys?: false): any[]; scan(query: string, keys: true): string[]; scan(query: string, keys = false) { - const values = []; + const values: (string | unknown)[] = []; const sq = query.split('.'); for (const iterator of [...this.storage.values()].flatMap(x => x.entries())) for (const [key, value] of iterator) { diff --git a/src/cache/adapters/workeradapter.ts b/src/cache/adapters/workeradapter.ts index 80242d1..b5603b0 100644 --- a/src/cache/adapters/workeradapter.ts +++ b/src/cache/adapters/workeradapter.ts @@ -1,8 +1,8 @@ import { randomUUID } from 'node:crypto'; +import { lazyLoadPackage } from '../../common'; import type { WorkerData } from '../../websocket'; import type { WorkerSendCacheRequest } from '../../websocket/discord/worker'; import type { Adapter } from './types'; -import { lazyLoadPackage } from '../../common'; let parentPort: import('node:worker_threads').MessagePort; @@ -15,7 +15,9 @@ export class WorkerAdapter implements Adapter { if (worker_threads?.parentPort) parentPort = worker_threads.parentPort; } - start() {} + start() { + // + } postMessage(body: any): unknown { if (parentPort) return parentPort.postMessage(body); diff --git a/src/cache/index.ts b/src/cache/index.ts index ee589a1..2ab2533 100644 --- a/src/cache/index.ts +++ b/src/cache/index.ts @@ -1,10 +1,11 @@ -import { Logger, type If } from '../common'; +import { type If, Logger } from '../common'; import type { Adapter } from './adapters'; import { Guilds } from './resources/guilds'; import { Users } from './resources/users'; +import { Bans } from './resources/bans'; import { Channels } from './resources/channels'; import { Emojis } from './resources/emojis'; import { Members } from './resources/members'; @@ -14,13 +15,9 @@ import { StageInstances } from './resources/stage-instances'; import { Stickers } from './resources/stickers'; import { Threads } from './resources/threads'; import { VoiceStates } from './resources/voice-states'; -import { Bans } from './resources/bans'; +import type { InternalOptions, UsingClient } from '../commands'; import { - ChannelType, - GatewayIntentBits, - GuildMemberFlags, - OverwriteType, type APIChannel, type APIEmoji, type APIGuildMember, @@ -28,11 +25,14 @@ import { type APISticker, type APITextChannel, type APIUser, + ChannelType, type GatewayDispatchPayload, + GatewayIntentBits, + GuildMemberFlags, + OverwriteType, } from '../types'; -import type { InternalOptions, UsingClient } from '../commands'; -import { Overwrites } from './resources/overwrites'; import { Messages } from './resources/messages'; +import { Overwrites } from './resources/overwrites'; export { BaseResource } from './resources/default/base'; export { GuildRelatedResource } from './resources/default/guild-related'; export { GuildBasedResource } from './resources/default/guild-based'; @@ -180,7 +180,9 @@ export class Cache { if (this.disabledCache.onPacket) { //@ts-expect-error - this.onPacket = () => {}; + this.onPacket = () => { + // disable cache + }; } } @@ -525,15 +527,17 @@ export class Cache { break; case 'CHANNEL_CREATE': case 'CHANNEL_UPDATE': - if ('guild_id' in event.d) { - await this.channels?.set(event.d.id, event.d.guild_id!, event.d); - if (event.d.permission_overwrites?.length) - await this.overwrites?.set(event.d.id, event.d.guild_id!, event.d.permission_overwrites); - break; - } - if (event.d.type === ChannelType.DM) { - await this.channels?.set(event.d.recipients![0]?.id, '@me', event.d); - break; + { + if ('guild_id' in event.d) { + await this.channels?.set(event.d.id, event.d.guild_id!, event.d); + if (event.d.permission_overwrites?.length) + await this.overwrites?.set(event.d.id, event.d.guild_id!, event.d.permission_overwrites); + break; + } + if (event.d.type === ChannelType.DM) { + await this.channels?.set(event.d.recipients![0]?.id, '@me', event.d); + break; + } } break; case 'CHANNEL_DELETE': @@ -553,18 +557,22 @@ export class Cache { await this.bans?.remove(event.d.user.id, event.d.guild_id); break; case 'GUILD_EMOJIS_UPDATE': - await this.emojis?.remove(await this.emojis?.keys(event.d.guild_id), event.d.guild_id); - await this.emojis?.set( - event.d.emojis.map(x => [x.id!, x] as [string, APIEmoji]), - event.d.guild_id, - ); + { + await this.emojis?.remove(await this.emojis?.keys(event.d.guild_id), event.d.guild_id); + await this.emojis?.set( + event.d.emojis.map(x => [x.id!, x] as [string, APIEmoji]), + event.d.guild_id, + ); + } break; case 'GUILD_STICKERS_UPDATE': - await this.stickers?.remove(await this.stickers?.keys(event.d.guild_id), event.d.guild_id); - await this.stickers?.set( - event.d.stickers.map(x => [x.id, x] as [string, APISticker]), - event.d.guild_id, - ); + { + await this.stickers?.remove(await this.stickers?.keys(event.d.guild_id), event.d.guild_id); + await this.stickers?.set( + event.d.stickers.map(x => [x.id, x] as [string, APISticker]), + event.d.guild_id, + ); + } break; case 'GUILD_MEMBER_ADD': case 'GUILD_MEMBER_UPDATE': @@ -593,14 +601,16 @@ export class Cache { break; case 'VOICE_STATE_UPDATE': - if (!event.d.guild_id) { - return; - } + { + if (!event.d.guild_id) { + return; + } - if (event.d.channel_id != null) { - await this.voiceStates?.set(event.d.user_id, event.d.guild_id, event.d); - } else { - await this.voiceStates?.remove(event.d.user_id, event.d.guild_id); + if (event.d.channel_id != null) { + await this.voiceStates?.set(event.d.user_id, event.d.guild_id, event.d); + } else { + await this.voiceStates?.remove(event.d.user_id, event.d.guild_id); + } } break; case 'STAGE_INSTANCE_CREATE': diff --git a/src/client/base.ts b/src/client/base.ts index 4f3522c..3ba8b0f 100644 --- a/src/client/base.ts +++ b/src/client/base.ts @@ -1,5 +1,5 @@ import { join } from 'node:path'; -import { ApiHandler, Router, type APIRoutes } from '../api'; +import { type APIRoutes, ApiHandler, Router } from '../api'; import type { Adapter } from '../cache'; import { Cache, MemoryAdapter } from '../cache'; import type { @@ -23,6 +23,7 @@ import { InteractionShorter, LogLevels, Logger, + type MakeRequired, MemberShorter, MergeOptions, MessageShorter, @@ -34,11 +35,13 @@ import { WebhookShorter, filterSplit, magicImport, - type MakeRequired, } from '../common'; -import type { LocaleString, RESTPostAPIChannelMessageJSONBody } from '../types'; +import { promises } from 'node:fs'; +import { HandleCommand } from '../commands/handle'; +import { BanShorter } from '../common/shorters/bans'; import type { Awaitable, DeepPartial, IntentStrings, OmitInsert, PermissionStrings, When } from '../common/types/util'; +import type { ComponentCommand, ComponentContext, ModalCommand, ModalContext } from '../components'; import { ComponentHandler } from '../components/handler'; import { LangsHandler } from '../langs/handler'; import type { @@ -49,10 +52,7 @@ import type { ModalSubmitInteraction, UserCommandInteraction, } from '../structures'; -import type { ComponentCommand, ComponentContext, ModalCommand, ModalContext } from '../components'; -import { promises } from 'node:fs'; -import { BanShorter } from '../common/shorters/bans'; -import { HandleCommand } from '../commands/handle'; +import type { LocaleString, RESTPostAPIChannelMessageJSONBody } from '../types'; import type { MessageStructure } from './transformers'; export class BaseClient { @@ -396,18 +396,16 @@ export class BaseClient { >() { const seyfertConfig = (BaseClient._seyfertCfWorkerConfig || (await this.options?.getRC?.()) || - ( - await Promise.any( - ['.js', '.mjs', '.cjs', '.ts', '.mts', '.cts'].map(ext => - magicImport(join(process.cwd(), `seyfert.config${ext}`)).then(x => x.default ?? x), - ), - ) + (await Promise.any( + ['.js', '.mjs', '.cjs', '.ts', '.mts', '.cts'].map(ext => + magicImport(join(process.cwd(), `seyfert.config${ext}`)).then(x => x.default ?? x), + ), ).catch((e: AggregateError) => { if (e.errors.every((err: Error) => err.stack?.includes('ERR_MODULE_NOT_FOUND'))) { throw new Error('No seyfert.config file found'); } throw e.errors.find((err: Error) => !err.stack?.includes('ERR_MODULE_NOT_FOUND')) ?? e.errors[0]; - })) as T; + }))) as T; const { locations, debug, ...env } = seyfertConfig; @@ -438,7 +436,7 @@ export interface BaseClientOptions { | ModalSubmitInteraction | EntryPointInteraction | When, - ) => {}; + ) => object; globalMiddlewares?: readonly (keyof RegisteredMiddlewares)[]; commands?: { defaults?: { diff --git a/src/client/client.ts b/src/client/client.ts index 20e4563..c9951e9 100644 --- a/src/client/client.ts +++ b/src/client/client.ts @@ -1,21 +1,21 @@ -import { type GatewayDispatchPayload, type GatewayPresenceUpdateData, GatewayIntentBits } from '../types'; import type { CommandContext, Message } from '..'; import { type Awaitable, - lazyLoadPackage, type DeepPartial, type If, type WatcherPayload, type WatcherSendToShard, + lazyLoadPackage, } from '../common'; import { EventHandler } from '../events'; -import { ShardManager, properties, type ShardManagerOptions } from '../websocket'; +import { type GatewayDispatchPayload, GatewayIntentBits, type GatewayPresenceUpdateData } from '../types'; +import { ShardManager, type ShardManagerOptions, properties } from '../websocket'; import { MemberUpdateHandler } from '../websocket/discord/events/memberUpdate'; import { PresenceUpdateHandler } from '../websocket/discord/events/presenceUpdate'; import type { BaseClientOptions, InternalRuntimeConfig, ServicesOptions, StartOptions } from './base'; import { BaseClient } from './base'; import { Collectors } from './collectors'; -import { type ClientUserStructure, Transformers, type MessageStructure } from './transformers'; +import { type ClientUserStructure, type MessageStructure, Transformers } from './transformers'; let parentPort: import('node:worker_threads').MessagePort; @@ -149,18 +149,22 @@ export class Client extends BaseClient { this.collectors.run('RAW', packet, this), ]); //ignore promise switch (packet.t) { - //// Cases where we must obtain the old data before updating + // Cases where we must obtain the old data before updating case 'GUILD_MEMBER_UPDATE': - if (!this.memberUpdateHandler.check(packet.d)) { - return; + { + if (!this.memberUpdateHandler.check(packet.d)) { + return; + } + await this.events?.execute(packet.t, packet, this as Client, shardId); } - await this.events?.execute(packet.t, packet, this as Client, shardId); break; case 'PRESENCE_UPDATE': - if (!this.presenceUpdateHandler.check(packet.d)) { - return; + { + if (!this.presenceUpdateHandler.check(packet.d)) { + return; + } + await this.events?.execute(packet.t, packet, this as Client, shardId); } - await this.events?.execute(packet.t, packet, this as Client, shardId); break; case 'GUILD_DELETE': case 'GUILD_CREATE': { @@ -181,12 +185,16 @@ export class Client extends BaseClient { default: { switch (packet.t) { case 'INTERACTION_CREATE': - await this.events?.execute(packet.t as never, packet, this as Client, shardId); - await this.handleCommand.interaction(packet.d, shardId); + { + await this.events?.execute(packet.t as never, packet, this as Client, shardId); + await this.handleCommand.interaction(packet.d, shardId); + } break; case 'MESSAGE_CREATE': - await this.events?.execute(packet.t as never, packet, this as Client, shardId); - await this.handleCommand.message(packet.d, shardId); + { + await this.events?.execute(packet.t as never, packet, this as Client, shardId); + await this.handleCommand.message(packet.d, shardId); + } break; case 'READY': { const ids = packet.d.guilds.map(x => x.id); diff --git a/src/client/transformers.ts b/src/client/transformers.ts index 2563b0b..5619e61 100644 --- a/src/client/transformers.ts +++ b/src/client/transformers.ts @@ -1,5 +1,5 @@ -import type { ChannelType } from '../types'; import { type CustomStructures, OptionResolver } from '../commands'; +import type { StructStates } from '../common/'; import { AnonymousGuild, AutoModerationRule, @@ -30,8 +30,8 @@ import { Webhook, WebhookMessage, } from '../structures'; -import type { StructStates } from '../common/'; import { GuildBan } from '../structures/GuildBan'; +import type { ChannelType } from '../types'; export type PollStructure = InferCustomStructure; export type ClientUserStructure = InferCustomStructure; @@ -64,130 +64,99 @@ export type VoiceStateStructure = InferCustomStructure export type WebhookStructure = InferCustomStructure; export type OptionResolverStructure = InferCustomStructure; -export class Transformers { - static AnonymousGuild(...args: ConstructorParameters): AnonymousGuildStructure { +export const Transformers = { + AnonymousGuild(...args: ConstructorParameters): AnonymousGuildStructure { return new AnonymousGuild(...args); - } - - static AutoModerationRule(...args: ConstructorParameters): AutoModerationRuleStructure { + }, + AutoModerationRule(...args: ConstructorParameters): AutoModerationRuleStructure { return new AutoModerationRule(...args); - } - - static BaseChannel(...args: ConstructorParameters): BaseChannelStructure { + }, + BaseChannel(...args: ConstructorParameters): BaseChannelStructure { return new BaseChannel(...args); - } - - static BaseGuildChannel(...args: ConstructorParameters): BaseGuildChannelStructure { + }, + BaseGuildChannel(...args: ConstructorParameters): BaseGuildChannelStructure { return new BaseGuildChannel(...args); - } - - static TextGuildChannel(...args: ConstructorParameters): TextGuildChannelStructure { + }, + TextGuildChannel(...args: ConstructorParameters): TextGuildChannelStructure { return new TextGuildChannel(...args); - } - - static DMChannel(...args: ConstructorParameters): DMChannelStructure { + }, + DMChannel(...args: ConstructorParameters): DMChannelStructure { return new DMChannel(...args); - } - - static VoiceChannel(...args: ConstructorParameters): VoiceChannelStructure { + }, + VoiceChannel(...args: ConstructorParameters): VoiceChannelStructure { return new VoiceChannel(...args); - } - - static StageChannel(...args: ConstructorParameters): StageChannelStructure { + }, + StageChannel(...args: ConstructorParameters): StageChannelStructure { return new StageChannel(...args); - } - - static MediaChannel(...args: ConstructorParameters): MediaChannelStructure { + }, + MediaChannel(...args: ConstructorParameters): MediaChannelStructure { return new MediaChannel(...args); - } - - static ForumChannel(...args: ConstructorParameters): ForumChannelStructure { + }, + ForumChannel(...args: ConstructorParameters): ForumChannelStructure { return new ForumChannel(...args); - } - - static ThreadChannel(...args: ConstructorParameters): ThreadChannelStructure { + }, + ThreadChannel(...args: ConstructorParameters): ThreadChannelStructure { return new ThreadChannel(...args); - } - - static CategoryChannel(...args: ConstructorParameters): CategoryChannelStructure { + }, + CategoryChannel(...args: ConstructorParameters): CategoryChannelStructure { return new CategoryChannel(...args); - } - - static NewsChannel(...args: ConstructorParameters): NewsChannelStructure { + }, + NewsChannel(...args: ConstructorParameters): NewsChannelStructure { return new NewsChannel(...args); - } - - static DirectoryChannel(...args: ConstructorParameters): DirectoryChannelStructure { + }, + DirectoryChannel(...args: ConstructorParameters): DirectoryChannelStructure { return new DirectoryChannel(...args); - } - - static ClientUser(...args: ConstructorParameters): ClientUserStructure { + }, + ClientUser(...args: ConstructorParameters): ClientUserStructure { return new ClientUser(...args); - } - - static Guild( - ...args: ConstructorParameters - ): GuildStructure { + }, + Guild(...args: ConstructorParameters): GuildStructure { return new Guild(...args); - } - - static GuildBan(...args: ConstructorParameters): GuildBanStructure { + }, + GuildBan(...args: ConstructorParameters): GuildBanStructure { return new GuildBan(...args); - } - - static GuildEmoji(...args: ConstructorParameters): GuildEmojiStructure { + }, + GuildEmoji(...args: ConstructorParameters): GuildEmojiStructure { return new GuildEmoji(...args); - } - - static GuildMember(...args: ConstructorParameters): GuildMemberStructure { + }, + GuildMember(...args: ConstructorParameters): GuildMemberStructure { return new GuildMember(...args); - } - - static InteractionGuildMember( + }, + InteractionGuildMember( ...args: ConstructorParameters ): InteractionGuildMemberStructure { return new InteractionGuildMember(...args); - } - - static GuildRole(...args: ConstructorParameters): GuildRoleStructure { + }, + GuildRole(...args: ConstructorParameters): GuildRoleStructure { return new GuildRole(...args); - } - - static GuildTemplate(...args: ConstructorParameters): GuildTemplateStructure { + }, + GuildTemplate(...args: ConstructorParameters): GuildTemplateStructure { return new GuildTemplate(...args); - } - - static Message(...args: ConstructorParameters): MessageStructure { + }, + Message(...args: ConstructorParameters): MessageStructure { return new Message(...args); - } - - static WebhookMessage(...args: ConstructorParameters): WebhookMessageStructure { + }, + WebhookMessage(...args: ConstructorParameters): WebhookMessageStructure { return new WebhookMessage(...args); - } - - static Poll(...args: ConstructorParameters): PollStructure { + }, + Poll(...args: ConstructorParameters): PollStructure { return new Poll(...args); - } - - static Sticker(...args: ConstructorParameters): StickerStructure { + }, + Sticker(...args: ConstructorParameters): StickerStructure { return new Sticker(...args); - } - - static User(...args: ConstructorParameters): UserStructure { + }, + User(...args: ConstructorParameters): UserStructure { return new User(...args); - } - - static VoiceState(...args: ConstructorParameters): VoiceStateStructure { + }, + VoiceState(...args: ConstructorParameters): VoiceStateStructure { return new VoiceState(...args); - } - - static Webhook(...args: ConstructorParameters): WebhookStructure { + }, + Webhook(...args: ConstructorParameters): WebhookStructure { return new Webhook(...args); - } - - static OptionResolver(...args: ConstructorParameters): OptionResolverStructure { + }, + OptionResolver(...args: ConstructorParameters): OptionResolverStructure { return new OptionResolver(...args); - } -} + }, +}; export type InferCustomStructure = CustomStructures extends Record ? P : T; diff --git a/src/client/workerclient.ts b/src/client/workerclient.ts index a78e39c..c138984 100644 --- a/src/client/workerclient.ts +++ b/src/client/workerclient.ts @@ -1,10 +1,10 @@ -import { type GatewayDispatchPayload, type GatewaySendPayload, GatewayIntentBits } from '../types'; import { randomUUID } from 'node:crypto'; import { ApiHandler, Logger } from '..'; import { WorkerAdapter } from '../cache'; -import { LogLevels, lazyLoadPackage, type DeepPartial, type When } from '../common'; +import { type DeepPartial, LogLevels, type When, lazyLoadPackage } from '../common'; import { EventHandler } from '../events'; -import { Shard, properties, type ShardManagerOptions, type WorkerData } from '../websocket'; +import { type GatewayDispatchPayload, GatewayIntentBits, type GatewaySendPayload } from '../types'; +import { Shard, type ShardManagerOptions, type WorkerData, properties } from '../websocket'; import type { WorkerReady, WorkerReceivePayload, @@ -23,10 +23,10 @@ import type { BaseClientOptions, ServicesOptions, StartOptions } from './base'; import { BaseClient } from './base'; import type { Client, ClientOptions } from './client'; -import { Collectors } from './collectors'; -import { type ClientUserStructure, Transformers } from './transformers'; import { MemberUpdateHandler } from '../websocket/discord/events/memberUpdate'; import { PresenceUpdateHandler } from '../websocket/discord/events/presenceUpdate'; +import { Collectors } from './collectors'; +import { type ClientUserStructure, Transformers } from './transformers'; let workerData: WorkerData; let manager: import('node:worker_threads').MessagePort; @@ -42,7 +42,9 @@ try { totalShards: Number(process.env.SEYFERT_WORKER_TOTALSHARDS), mode: process.env.SEYFERT_WORKER_MODE, } as WorkerData; -} catch {} +} catch { + // +} export class WorkerClient extends BaseClient { private __handleGuilds?: Set = new Set(); @@ -287,7 +289,7 @@ export class WorkerClient extends BaseClient { break; case 'EXECUTE_EVAL': { - let result; + let result: unknown; try { result = await eval(` (${data.func})(this) @@ -332,7 +334,7 @@ export class WorkerClient extends BaseClient { }); } - tellWorker(workerId: number, func: (_: this) => {}) { + tellWorker(workerId: number, func: (_: this) => any) { const nonce = this.generateNonce(); this.postMessage({ type: 'EVAL', @@ -389,45 +391,51 @@ export class WorkerClient extends BaseClient { default: { switch (packet.t) { case 'INTERACTION_CREATE': - await this.events?.execute(packet.t as never, packet, this, shardId); - await this.handleCommand.interaction(packet.d, shardId); + { + await this.events?.execute(packet.t as never, packet, this, shardId); + await this.handleCommand.interaction(packet.d, shardId); + } break; case 'MESSAGE_CREATE': - await this.events?.execute(packet.t as never, packet, this, shardId); - await this.handleCommand.message(packet.d, shardId); + { + await this.events?.execute(packet.t as never, packet, this, shardId); + await this.handleCommand.message(packet.d, shardId); + } break; case 'READY': - if (!this.__handleGuilds) this.__handleGuilds = new Set(); - for (const g of packet.d.guilds) { - this.__handleGuilds?.add(g.id); - } - this.botId = packet.d.user.id; - this.applicationId = packet.d.application.id; - this.me = Transformers.ClientUser(this, packet.d.user, packet.d.application) as never; - await this.events?.execute(packet.t as never, packet, this, shardId); - if ([...this.shards.values()].every(shard => shard.data.session_id)) { - this.postMessage({ - type: 'WORKER_SHARDS_CONNECTED', - workerId: this.workerId, - } as WorkerShardsConnected); - await this.events?.runEvent('WORKER_SHARDS_CONNECTED', this, this.me, -1); - } - if ( - !( - this.__handleGuilds?.size && - (workerData.intents & GatewayIntentBits.Guilds) === GatewayIntentBits.Guilds - ) - ) { + { + if (!this.__handleGuilds) this.__handleGuilds = new Set(); + for (const g of packet.d.guilds) { + this.__handleGuilds?.add(g.id); + } + this.botId = packet.d.user.id; + this.applicationId = packet.d.application.id; + this.me = Transformers.ClientUser(this, packet.d.user, packet.d.application) as never; + await this.events?.execute(packet.t as never, packet, this, shardId); if ([...this.shards.values()].every(shard => shard.data.session_id)) { this.postMessage({ - type: 'WORKER_READY', + type: 'WORKER_SHARDS_CONNECTED', workerId: this.workerId, - } as WorkerReady); - await this.events?.runEvent('WORKER_READY', this, this.me, -1); + } as WorkerShardsConnected); + await this.events?.runEvent('WORKER_SHARDS_CONNECTED', this, this.me, -1); } - delete this.__handleGuilds; + if ( + !( + this.__handleGuilds?.size && + (workerData.intents & GatewayIntentBits.Guilds) === GatewayIntentBits.Guilds + ) + ) { + if ([...this.shards.values()].every(shard => shard.data.session_id)) { + this.postMessage({ + type: 'WORKER_READY', + workerId: this.workerId, + } as WorkerReady); + await this.events?.runEvent('WORKER_READY', this, this.me, -1); + } + delete this.__handleGuilds; + } + this.debugger?.debug(`#${shardId}[${packet.d.user.username}](${this.botId}) is online...`); } - this.debugger?.debug(`#${shardId}[${packet.d.user.username}](${this.botId}) is online...`); break; default: await this.events?.execute(packet.t as never, packet, this, shardId); diff --git a/src/commands/applications/chat.ts b/src/commands/applications/chat.ts index 21bc396..62dcd98 100644 --- a/src/commands/applications/chat.ts +++ b/src/commands/applications/chat.ts @@ -1,13 +1,4 @@ -import { - ApplicationCommandOptionType, - ApplicationCommandType, - type ApplicationIntegrationType, - type InteractionContextType, - type APIApplicationCommandBasicOption, - type APIApplicationCommandOption, - type APIApplicationCommandSubcommandGroupOption, - type LocaleString, -} from '../../types'; +import { inspect } from 'node:util'; import type { ComponentContext, EntryPointContext, @@ -18,8 +9,24 @@ import type { SeyfertStringOption, } from '../..'; import type { Attachment } from '../../builders'; -import { type Awaitable, magicImport, type FlatObjectKeys } from '../../common'; +import type { + GuildRoleStructure, + InteractionGuildMemberStructure, + OptionResolverStructure, + UserStructure, +} from '../../client/transformers'; +import { type Awaitable, type FlatObjectKeys, magicImport } from '../../common'; import type { AllChannels, AutocompleteInteraction } from '../../structures'; +import { + type APIApplicationCommandBasicOption, + type APIApplicationCommandOption, + type APIApplicationCommandSubcommandGroupOption, + ApplicationCommandOptionType, + ApplicationCommandType, + type ApplicationIntegrationType, + type InteractionContextType, + type LocaleString, +} from '../../types'; import type { Groups, RegisteredMiddlewares } from '../decorators'; import type { CommandContext } from './chatcontext'; import type { @@ -32,13 +39,6 @@ import type { StopFunction, UsingClient, } from './shared'; -import { inspect } from 'node:util'; -import type { - GuildRoleStructure, - InteractionGuildMemberStructure, - OptionResolverStructure, - UserStructure, -} from '../../client/transformers'; export interface ReturnOptionsTypes { 1: never; // subcommand @@ -149,7 +149,7 @@ export class BaseCommand { /** @internal */ async __runOptions( - ctx: CommandContext<{}, never>, + ctx: CommandContext, resolver: OptionResolverStructure, ): Promise<[boolean, OnOptionsReturnObject]> { if (!this?.options?.length) { @@ -202,7 +202,12 @@ export class BaseCommand { /** @internal */ static __runMiddlewares( - context: CommandContext<{}, never> | ComponentContext | MenuCommandContext | ModalContext | EntryPointContext, + context: + | CommandContext + | ComponentContext + | MenuCommandContext + | ModalContext + | EntryPointContext, middlewares: (keyof RegisteredMiddlewares)[], global: boolean, ): Promise<{ error?: string; pass?: boolean }> { @@ -220,13 +225,12 @@ export class BaseCommand { running = false; return res({ pass: true }); }; - function next(obj: any) { + function next(...args: unknown[]) { if (!running) { return; } - if (arguments.length) { - // @ts-expect-error - context[global ? 'globalMetadata' : 'metadata'][middlewares[index]] = obj; + if (args.length) { + context[global ? 'globalMetadata' : 'metadata'][middlewares[index]] = args[0] as never; } if (++index >= middlewares.length) { running = false; @@ -246,12 +250,12 @@ export class BaseCommand { } /** @internal */ - __runMiddlewares(context: CommandContext<{}, never>) { + __runMiddlewares(context: CommandContext) { return BaseCommand.__runMiddlewares(context, this.middlewares as (keyof RegisteredMiddlewares)[], false); } /** @internal */ - __runGlobalMiddlewares(context: CommandContext<{}, never>) { + __runGlobalMiddlewares(context: CommandContext) { return BaseCommand.__runMiddlewares( context, (context.client.options?.globalMiddlewares ?? []) as (keyof RegisteredMiddlewares)[], diff --git a/src/commands/applications/chatcontext.ts b/src/commands/applications/chatcontext.ts index ddda765..64f71fc 100644 --- a/src/commands/applications/chatcontext.ts +++ b/src/commands/applications/chatcontext.ts @@ -1,13 +1,5 @@ -import { MessageFlags } from '../../types'; import type { AllChannels, InferWithPrefix, Message, ReturnCache } from '../..'; import type { Client, WorkerClient } from '../../client'; -import type { If, UnionToTuple, When } from '../../common'; -import type { InteractionCreateBodyRequest, InteractionMessageUpdateBodyRequest } from '../../common/types/write'; -import { ChatInputCommandInteraction } from '../../structures'; -import { BaseContext } from '../basecontext'; -import type { RegisteredMiddlewares } from '../decorators'; -import type { Command, ContextOptions, OptionsRecord, SubCommand } from './chat'; -import type { CommandMetadata, ExtendContext, GlobalMetadata, UsingClient } from './shared'; import type { GuildMemberStructure, GuildStructure, @@ -16,13 +8,21 @@ import type { OptionResolverStructure, WebhookMessageStructure, } from '../../client/transformers'; +import type { If, UnionToTuple, When } from '../../common'; +import type { InteractionCreateBodyRequest, InteractionMessageUpdateBodyRequest } from '../../common/types/write'; +import { ChatInputCommandInteraction } from '../../structures'; +import { MessageFlags } from '../../types'; +import { BaseContext } from '../basecontext'; +import type { RegisteredMiddlewares } from '../decorators'; +import type { Command, ContextOptions, OptionsRecord, SubCommand } from './chat'; +import type { CommandMetadata, ExtendContext, GlobalMetadata, UsingClient } from './shared'; -export interface CommandContext +export interface CommandContext extends BaseContext, ExtendContext {} export class CommandContext< - T extends OptionsRecord = {}, + T extends OptionsRecord = never, M extends keyof RegisteredMiddlewares = never, > extends BaseContext { message!: If; diff --git a/src/commands/applications/options.ts b/src/commands/applications/options.ts index 6ba9311..c4ca9b1 100644 --- a/src/commands/applications/options.ts +++ b/src/commands/applications/options.ts @@ -1,4 +1,3 @@ -import { ApplicationCommandOptionType, type APIApplicationCommandOptionChoice, type ChannelType } from '../../types'; import type { AutocompleteCallback, EntryPointContext, @@ -7,13 +6,14 @@ import type { ReturnOptionsTypes, __TypesWrapper, } from '..'; -import type { MessageCommandInteraction, UserCommandInteraction } from '../../structures'; -import type { CommandContext } from './chatcontext'; -import type { MiddlewareContext } from './shared'; import type { ModalContext } from '../../components'; import type { ComponentContext } from '../../components/componentcontext'; +import type { MessageCommandInteraction, UserCommandInteraction } from '../../structures'; +import { type APIApplicationCommandOptionChoice, ApplicationCommandOptionType, type ChannelType } from '../../types'; +import type { CommandContext } from './chatcontext'; +import type { MiddlewareContext } from './shared'; -export type SeyfertBasicOption = __TypesWrapper[T] & D; +export type SeyfertBasicOption = __TypesWrapper[T] & D; export type SeyfertStringOption = SeyfertBasicOption<'String'> & { autocomplete?: AutocompleteCallback; diff --git a/src/commands/applications/shared.ts b/src/commands/applications/shared.ts index f8766bc..ef3a8ec 100644 --- a/src/commands/applications/shared.ts +++ b/src/commands/applications/shared.ts @@ -39,13 +39,13 @@ export type CommandMetadata ] ? first extends keyof RegisteredMiddlewares ? (MetadataMiddleware extends never - ? {} + ? never : { [key in first]: MetadataMiddleware; }) & - (rest extends readonly (keyof RegisteredMiddlewares)[] ? CommandMetadata : {}) - : {} - : {}; + (rest extends readonly (keyof RegisteredMiddlewares)[] ? CommandMetadata : never) + : never + : never; export type MessageCommandOptionErrors = | ['CHANNEL_TYPES', type: ChannelType[]] diff --git a/src/commands/decorators.ts b/src/commands/decorators.ts index f2e7aaa..cfdbf83 100644 --- a/src/commands/decorators.ts +++ b/src/commands/decorators.ts @@ -1,12 +1,12 @@ +import type { FlatObjectKeys, PermissionStrings } from '../common'; import { ApplicationCommandType, ApplicationIntegrationType, type EntryPointCommandHandlerType, InteractionContextType, - PermissionFlagsBits, type LocaleString, + PermissionFlagsBits, } from '../types'; -import type { FlatObjectKeys, PermissionStrings } from '../common'; import type { CommandOption, OptionsRecord, SubCommand } from './applications/chat'; import type { DefaultLocale, ExtraProps, IgnoreCommand, MiddlewareContext } from './applications/shared'; @@ -42,7 +42,7 @@ export function Locales({ name?: [language: LocaleString, value: string][]; description?: [language: LocaleString, value: string][]; }) { - return (target: T) => + return (target: T) => class extends target { name_localizations = names ? Object.fromEntries(names) : undefined; description_localizations = descriptions ? Object.fromEntries(descriptions) : undefined; @@ -50,7 +50,7 @@ export function Locales({ } export function LocalesT(name?: FlatObjectKeys, description?: FlatObjectKeys) { - return (target: T) => + return (target: T) => class extends target { __t = { name, description }; }; @@ -67,7 +67,7 @@ export function GroupsT( } >, ) { - return (target: T) => + return (target: T) => class extends target { __tGroups = groups; groupsAliases: Record = {}; @@ -93,7 +93,7 @@ export function Groups( } >, ) { - return (target: T) => + return (target: T) => class extends target { groups = groups; groupsAliases: Record = {}; @@ -109,14 +109,14 @@ export function Groups( } export function Group(groupName: string) { - return (target: T) => + return (target: T) => class extends target { group = groupName; }; } export function Options(options: (new () => SubCommand)[] | OptionsRecord) { - return (target: T) => + return (target: T) => class extends target { options: SubCommand[] | CommandOption[] = Array.isArray(options) ? options.map(x => new x()) @@ -130,7 +130,7 @@ export function Options(options: (new () => SubCommand)[] | OptionsRecord) { } export function AutoLoad() { - return (target: T) => + return (target: T) => class extends target { __autoload = true; }; @@ -141,14 +141,14 @@ export type ParseMiddlewares> = { }; export function Middlewares(cbs: readonly (keyof RegisteredMiddlewares)[]) { - return (target: T) => + return (target: T) => class extends target { middlewares = cbs; }; } export function Declare(declare: CommandDeclareOptions) { - return (target: T) => + return (target: T) => class extends target { name = declare.name; nsfw = declare.nsfw; diff --git a/src/commands/handle.ts b/src/commands/handle.ts index 2611816..2a9fa58 100644 --- a/src/commands/handle.ts +++ b/src/commands/handle.ts @@ -1,52 +1,52 @@ import { - type APIApplicationCommandInteraction, - ApplicationCommandType, - InteractionType, - type APIInteraction, - type GatewayMessageCreateDispatchData, - InteractionContextType, - type APIApplicationCommandInteractionDataOption, - ApplicationCommandOptionType, - type APIInteractionDataResolvedChannel, - ChannelType, -} from '../types'; -import { - Command, - type ContextOptionsResolved, - type UsingClient, - type CommandAutocompleteOption, - type ContextMenuCommand, - MenuCommandContext, BaseCommand, + Command, + type CommandAutocompleteOption, CommandContext, - type RegisteredMiddlewares, - SubCommand, - IgnoreCommand, type CommandOption, + type ContextMenuCommand, + type ContextOptionsResolved, + type EntryPointCommand, + EntryPointContext, + IgnoreCommand, + MenuCommandContext, type MessageCommandOptionErrors, + type RegisteredMiddlewares, type SeyfertChannelOption, type SeyfertIntegerOption, type SeyfertNumberOption, type SeyfertStringOption, - EntryPointContext, - type EntryPointCommand, + SubCommand, + type UsingClient, } from '.'; +import type { Client, WorkerClient } from '../client'; +import { type MessageStructure, type OptionResolverStructure, Transformers } from '../client/transformers'; +import type { MakeRequired } from '../common'; +import { ComponentContext, ModalContext } from '../components'; import { AutocompleteInteraction, BaseInteraction, - type ComponentInteraction, - type ModalSubmitInteraction, type ChatInputCommandInteraction, + type ComponentInteraction, + type EntryPointInteraction, type MessageCommandInteraction, + type ModalSubmitInteraction, type UserCommandInteraction, type __InternalReplyFunction, - type EntryPointInteraction, } from '../structures'; import type { PermissionsBitField } from '../structures/extra/Permissions'; -import { ComponentContext, ModalContext } from '../components'; -import type { Client, WorkerClient } from '../client'; -import type { MakeRequired } from '../common'; -import { type MessageStructure, Transformers, type OptionResolverStructure } from '../client/transformers'; +import { + type APIApplicationCommandInteraction, + type APIApplicationCommandInteractionDataOption, + type APIInteraction, + type APIInteractionDataResolvedChannel, + ApplicationCommandOptionType, + ApplicationCommandType, + ChannelType, + type GatewayMessageCreateDispatchData, + InteractionContextType, + InteractionType, +} from '../types'; export type CommandOptionWithType = CommandOption & { type: ApplicationCommandOptionType; @@ -390,7 +390,9 @@ export class HandleCommand { } catch (error) { try { await command.onInternalError?.(this.client, command, error); - } catch {} + } catch { + // http 418 + } } } @@ -529,7 +531,7 @@ export class HandleCommand { async runGlobalMiddlewares( command: Command | ContextMenuCommand | SubCommand | EntryPointCommand, - context: CommandContext<{}, never> | MenuCommandContext | EntryPointContext, + context: CommandContext | MenuCommandContext | EntryPointContext, ) { try { const resultRunGlobalMiddlewares = await BaseCommand.__runMiddlewares( @@ -548,14 +550,16 @@ export class HandleCommand { } catch (e) { try { await command.onInternalError?.(this.client, command as never, e); - } catch {} + } catch { + // http 418 + } } return false; } async runMiddlewares( command: Command | ContextMenuCommand | SubCommand | EntryPointCommand, - context: CommandContext<{}, never> | MenuCommandContext | EntryPointContext, + context: CommandContext | MenuCommandContext | EntryPointContext, ) { try { const resultRunMiddlewares = await BaseCommand.__runMiddlewares( @@ -574,7 +578,9 @@ export class HandleCommand { } catch (e) { try { await command.onInternalError?.(this.client, command as never, e); - } catch {} + } catch { + // http 418 + } } return false; } @@ -602,7 +608,9 @@ export class HandleCommand { } catch (e) { try { await command.onInternalError?.(this.client, command, e); - } catch {} + } catch { + // http 418 + } } return false; } diff --git a/src/commands/handler.ts b/src/commands/handler.ts index b86c412..ce58017 100644 --- a/src/commands/handler.ts +++ b/src/commands/handler.ts @@ -1,23 +1,23 @@ -import { - type APIApplicationCommandOption, - Locale, - type LocaleString, - ApplicationCommandOptionType, - type APIApplicationCommandIntegerOption, - type APIApplicationCommandStringOption, - type APIApplicationCommandSubcommandOption, - type APIApplicationCommandSubcommandGroupOption, - type APIApplicationCommandChannelOption, - type LocalizationMap, -} from '../types'; +import { promises } from 'node:fs'; import { basename, dirname } from 'node:path'; +import type { EntryPointCommand } from '.'; import type { Logger, MakeRequired, NulleableCoalising, OmitInsert } from '../common'; import { BaseHandler, isCloudfareWorker } from '../common'; +import { + type APIApplicationCommandChannelOption, + type APIApplicationCommandIntegerOption, + type APIApplicationCommandOption, + type APIApplicationCommandStringOption, + type APIApplicationCommandSubcommandGroupOption, + type APIApplicationCommandSubcommandOption, + ApplicationCommandOptionType, + Locale, + type LocaleString, + type LocalizationMap, +} from '../types'; import { Command, type CommandOption, SubCommand } from './applications/chat'; import { ContextMenuCommand } from './applications/menu'; import type { UsingClient } from './applications/shared'; -import { promises } from 'node:fs'; -import type { EntryPointCommand } from '.'; export class CommandHandler extends BaseHandler { values: (Command | ContextMenuCommand)[] = []; @@ -97,26 +97,29 @@ export class CommandHandler extends BaseHandler { return option.channel_types.some(ct => !cached.channel_types!.includes(ct)); } } - return; + break; case ApplicationCommandOptionType.Subcommand: case ApplicationCommandOptionType.SubcommandGroup: - if ( - option.options?.length !== - (cached as APIApplicationCommandSubcommandOption | APIApplicationCommandSubcommandGroupOption).options?.length - ) { - return true; - } - if ( - option.options && - (cached as APIApplicationCommandSubcommandOption | APIApplicationCommandSubcommandGroupOption).options - ) - for (const i of option.options) { - const cachedOption = ( - cached as APIApplicationCommandSubcommandOption | APIApplicationCommandSubcommandGroupOption - ).options!.find(x => x.name === i.name); - if (!cachedOption) return true; - if (this.shouldUploadOption(i, cachedOption)) return true; + { + if ( + option.options?.length !== + (cached as APIApplicationCommandSubcommandOption | APIApplicationCommandSubcommandGroupOption).options + ?.length + ) { + return true; } + if ( + option.options && + (cached as APIApplicationCommandSubcommandOption | APIApplicationCommandSubcommandGroupOption).options + ) + for (const i of option.options) { + const cachedOption = ( + cached as APIApplicationCommandSubcommandOption | APIApplicationCommandSubcommandGroupOption + ).options!.find(x => x.name === i.name); + if (!cachedOption) return true; + if (this.shouldUploadOption(i, cachedOption)) return true; + } + } break; case ApplicationCommandOptionType.Integer: case ApplicationCommandOptionType.Number: @@ -210,7 +213,7 @@ export class CommandHandler extends BaseHandler { set(commands: SeteableCommand[]) { this.values ??= []; for (const command of commands) { - let commandInstance; + let commandInstance: Command | undefined; try { commandInstance = this.onCommand(command) as Command; if (!commandInstance) continue; @@ -238,7 +241,7 @@ export class CommandHandler extends BaseHandler { for (const { commands, file } of result.map(x => ({ commands: this.onFile(x.file), file: x }))) { if (!commands) continue; for (const command of commands) { - let commandInstance; + let commandInstance: ReturnType; try { commandInstance = this.onCommand(command); if (!commandInstance) continue; @@ -277,7 +280,7 @@ export class CommandHandler extends BaseHandler { const subCommand = this.onSubCommand(fileSubCommand as HandleableSubCommand); if (subCommand && subCommand instanceof SubCommand) { subCommand.__filePath = option; - commandInstance.options.push(subCommand); + commandInstance.options!.push(subCommand); } else { this.logger.warn(subCommand ? 'SubCommand expected' : 'Invalid SubCommand', subCommand); } diff --git a/src/common/it/formatter.ts b/src/common/it/formatter.ts index ea5f9de..b163772 100644 --- a/src/common/it/formatter.ts +++ b/src/common/it/formatter.ts @@ -63,61 +63,61 @@ type Timestamp = ``; /** * Represents a formatter utility for formatting content. */ -export class Formatter { +export const Formatter = { /** * Formats a code block. * @param content The content of the code block. * @param language The language of the code block. Defaults to 'txt'. * @returns The formatted code block. */ - static codeBlock(content: string, language = 'txt'): string { + codeBlock(content: string, language = 'txt'): string { return `\`\`\`${language}\n${content}\n\`\`\``; - } + }, /** * Formats content into inline code. * @param content The content to format. * @returns The formatted content. */ - static inlineCode(content: string): `\`${string}\`` { + inlineCode(content: string): `\`${string}\`` { return `\`${content}\``; - } + }, /** * Formats content into bold text. * @param content The content to format. * @returns The formatted content. */ - static bold(content: string): `**${string}**` { + bold(content: string): `**${string}**` { return `**${content}**`; - } + }, /** * Formats content into italic text. * @param content The content to format. * @returns The formatted content. */ - static italic(content: string): `*${string}*` { + italic(content: string): `*${string}*` { return `*${content}*`; - } + }, /** * Formats content into underlined text. * @param content The content to format. * @returns The formatted content. */ - static underline(content: string): `__${string}__` { + underline(content: string): `__${string}__` { return `__${content}__`; - } + }, /** * Formats content into strikethrough text. * @param content The content to format. * @returns The formatted content. */ - static strikeThrough(content: string): `~~${string}~~` { + strikeThrough(content: string): `~~${string}~~` { return `~~${content}~~`; - } + }, /** * Formats content into a hyperlink. @@ -125,36 +125,36 @@ export class Formatter { * @param url The URL to hyperlink to. * @returns The formatted content. */ - static hyperlink(content: string, url: string): `[${string}](${string})` { + hyperlink(content: string, url: string): `[${string}](${string})` { return `[${content}](${url})`; - } + }, /** * Formats content into a spoiler. * @param content The content to format. * @returns The formatted content. */ - static spoiler(content: string): `||${string}||` { + spoiler(content: string): `||${string}||` { return `||${content}||`; - } + }, /** * Formats content into a quote. * @param content The content to format. * @returns The formatted content. */ - static blockQuote(content: string): string { + blockQuote(content: string): string { return `>>> ${content}`; - } + }, /** * Formats content into a quote. * @param content The content to format. * @returns The formatted content. */ - static quote(content: string): string { + quote(content: string): string { return `> ${content}`; - } + }, /** * Formats a message link. @@ -163,9 +163,9 @@ export class Formatter { * @param messageId The ID of the message. * @returns The formatted message link. */ - static messageLink(guildId: string, channelId: string, messageId: string): MessageLink { + messageLink(guildId: string, channelId: string, messageId: string): MessageLink { return `https://discord.com/channels/${guildId}/${channelId}/${messageId}`; - } + }, /** * Formats a header. @@ -173,9 +173,9 @@ export class Formatter { * @param level The level of the header. Defaults to 1. * @returns The formatted header. */ - static header(content: string, level: HeadingLevel = HeadingLevel.H1): string { + header(content: string, level: HeadingLevel = HeadingLevel.H1): string { return `${'#'.repeat(level)} ${content}`; - } + }, /** * Formats a list. @@ -183,13 +183,13 @@ export class Formatter { * @param ordered Whether the list is ordered. Defaults to false. * @returns The formatted list. */ - static list(items: string[], ordered = false): string { + list(items: string[], ordered = false): string { return items .map((item, index) => { return (ordered ? `${index + 1}. ` : '- ') + item; }) .join('\n'); - } + }, /** * Formats the given timestamp into discord unix timestamp format. @@ -197,36 +197,36 @@ export class Formatter { * @param style The style of the timestamp. Defaults to 't'. * @returns The formatted timestamp. */ - static timestamp(timestamp: Date, style: TimestampStyle = TimestampStyle.RelativeTime): Timestamp { + timestamp(timestamp: Date, style: TimestampStyle = TimestampStyle.RelativeTime): Timestamp { return ``; - } + }, /** * Formats a user mention. * @param userId The ID of the user to mention. * @returns The formatted user mention. */ - static userMention(userId: string): `<@${string}>` { + userMention(userId: string): `<@${string}>` { return `<@${userId}>`; - } + }, /** * Formats a role mention. * @param roleId The ID of the role to mention. * @returns The formatted role mention. */ - static roleMention(roleId: string): `<@&${string}>` { + roleMention(roleId: string): `<@&${string}>` { return `<@&${roleId}>`; - } + }, /** * Formats a channel mention. * @param channelId The ID of the channel to mention. * @returns The formatted channel mention. */ - static channelMention(channelId: string): `<#${string}>` { + channelMention(channelId: string): `<#${string}>` { return `<#${channelId}>`; - } + }, /** * Formats an emoji. @@ -234,9 +234,9 @@ export class Formatter { * @param animated Whether the emoji is animated. Defaults to false. * @returns The formatted emoji. */ - static emojiMention(emojiId: string, name: string | null, animated = false): string { + emojiMention(emojiId: string, name: string | null, animated = false): string { return `<${animated ? 'a' : ''}:${name ?? '_'}:${emojiId}>`; - } + }, /** * Formats a channel link. @@ -244,7 +244,7 @@ export class Formatter { * @param guildId The ID of the guild. Defaults to '@me'. * @returns The formatted channel link. */ - static channelLink(channelId: string, guildId?: string) { + channelLink(channelId: string, guildId?: string) { return `https://discord.com/channels/${guildId ?? '@me'}/${channelId}`; - } -} + }, +}; diff --git a/src/common/it/logger.ts b/src/common/it/logger.ts index d75b995..3663a01 100644 --- a/src/common/it/logger.ts +++ b/src/common/it/logger.ts @@ -1,4 +1,4 @@ -import { createWriteStream, existsSync, mkdirSync, promises, type WriteStream } from 'node:fs'; +import { type WriteStream, createWriteStream, existsSync, mkdirSync, promises } from 'node:fs'; import { join } from 'node:path'; import { bgBrightWhite, black, bold, brightBlack, cyan, gray, italic, red, stripColor, yellow } from './colors'; import { MergeOptions } from './utils'; @@ -53,7 +53,7 @@ export class Logger { static async clearLogs() { for (const i of await promises.readdir(join(process.cwd(), Logger.dirname), { withFileTypes: true })) { if (Logger.streams[i.name]) await new Promise(res => Logger.streams[i.name]!.close(res)); - await promises.unlink(join(process.cwd(), Logger.dirname, i.name)).catch(() => {}); + await promises.unlink(join(process.cwd(), Logger.dirname, i.name)).catch(() => undefined); delete Logger.streams[i.name]; } } @@ -126,7 +126,7 @@ export class Logger { if (!this.active) return; if (level < this.level) return; - let log; + let log: unknown[] | undefined; if (Logger.__callback) { log = Logger.__callback(this, level, args); diff --git a/src/common/it/utils.ts b/src/common/it/utils.ts index cb43bfd..7e43145 100644 --- a/src/common/it/utils.ts +++ b/src/common/it/utils.ts @@ -1,17 +1,17 @@ import { promises } from 'node:fs'; import { basename, join } from 'node:path'; import { + type ColorResolvable, DiscordEpoch, EmbedColors, type EmojiResolvable, - type TypeArray, - type ColorResolvable, type Logger, type ObjectToLower, type ObjectToSnake, + type TypeArray, } from '..'; -import { type APIPartialEmoji, FormattingPatterns } from '../../types'; import type { Cache } from '../../cache'; +import { type APIPartialEmoji, FormattingPatterns } from '../../types'; /** * Calculates the shard ID for a guild based on its ID. @@ -29,11 +29,12 @@ export function calculateShardId(guildId: string, shards?: number) { */ export function resolveColor(color: ColorResolvable): number { switch (typeof color) { - case 'string': + case 'string': { if (color === 'Random') return Math.floor(Math.random() * (0xffffff + 1)); if (color.startsWith('#')) return Number.parseInt(color.slice(1), 16); if (color in EmbedColors) return EmbedColors[color as keyof typeof EmbedColors]; return EmbedColors.Default; + } case 'number': return color; case 'object': @@ -82,7 +83,7 @@ export function MergeOptions(defaults: any, ...options: any[]): T { ...Object.fromEntries( Object.entries(defaults).map(([key, value]) => [ key, - isObject(value) ? MergeOptions(value, option?.[key] || {}) : option?.[key] ?? value, + isObject(value) ? MergeOptions(value, option?.[key] || {}) : (option?.[key] ?? value), ]), ), }, @@ -195,7 +196,7 @@ export function toSnakeCase>(target: Obj): Objec case 'undefined': result[ReplaceRegex.snake(key)] = value; break; - case 'object': + case 'object': { if (Array.isArray(value)) { result[ReplaceRegex.snake(key)] = value.map(prop => typeof prop === 'object' && prop ? toSnakeCase(prop) : prop, @@ -212,6 +213,7 @@ export function toSnakeCase>(target: Obj): Objec } result[ReplaceRegex.snake(key)] = toSnakeCase(value); break; + } } } return result as ObjectToSnake; @@ -235,7 +237,7 @@ export function toCamelCase>(target: Obj): Objec case 'undefined': result[ReplaceRegex.camel(key)] = value; break; - case 'object': + case 'object': { if (Array.isArray(value)) { result[ReplaceRegex.camel(key)] = value.map(prop => typeof prop === 'object' && prop ? toCamelCase(prop) : prop, @@ -252,6 +254,7 @@ export function toCamelCase>(target: Obj): Objec } result[ReplaceRegex.camel(key)] = toCamelCase(value); break; + } } } return result as ObjectToLower; @@ -291,6 +294,8 @@ export function lazyLoadPackage(mod: string): T | undefined { try { return require(mod); } catch (e) { + // biome-ignore lint/suspicious/noConsoleLog: + // biome-ignore lint/suspicious/noConsole: console.log(`Cannot import ${mod}`, e); return; } diff --git a/src/common/shorters/bans.ts b/src/common/shorters/bans.ts index ee9cd4a..e404acd 100644 --- a/src/common/shorters/bans.ts +++ b/src/common/shorters/bans.ts @@ -1,3 +1,4 @@ +import { type GuildBanStructure, Transformers } from '../../client/transformers'; import type { APIBan, RESTGetAPIGuildBansQuery, @@ -5,7 +6,6 @@ import type { RESTPutAPIGuildBanJSONBody, } from '../../types'; import { BaseShorter } from './base'; -import { Transformers } from '../../client/transformers'; export class BanShorter extends BaseShorter { /** @@ -50,7 +50,7 @@ export class BanShorter extends BaseShorter { * @returns A Promise that resolves to the fetched ban. */ async fetch(guildId: string, userId: string, force = false) { - let ban; + let ban: APIBan | GuildBanStructure | undefined; if (!force) { ban = await this.client.cache.bans?.get(userId, guildId); if (ban) return ban; @@ -69,7 +69,7 @@ export class BanShorter extends BaseShorter { * @returns A Promise that resolves to an array of listed bans. */ async list(guildId: string, query?: RESTGetAPIGuildBansQuery, force = false) { - let bans; + let bans: APIBan[] | GuildBanStructure[]; if (!force) { bans = (await this.client.cache.bans?.values(guildId)) ?? []; if (bans.length) return bans; diff --git a/src/common/shorters/channels.ts b/src/common/shorters/channels.ts index 86b4d0f..1911024 100644 --- a/src/common/shorters/channels.ts +++ b/src/common/shorters/channels.ts @@ -1,18 +1,20 @@ +import type { Channels } from '../../cache/resources/channels'; +import type { Overwrites } from '../../cache/resources/overwrites'; +import { type MessageStructure, Transformers } from '../../client/transformers'; +import { type AllChannels, BaseChannel, type GuildMember, type GuildRole, channelFrom } from '../../structures'; +import { PermissionsBitField } from '../../structures/extra/Permissions'; import type { APIChannel, + APIGuildChannel, RESTGetAPIChannelMessagesQuery, RESTPatchAPIChannelJSONBody, RESTPostAPIChannelThreadsJSONBody, RESTPostAPIGuildForumThreadsJSONBody, - APIGuildChannel, } from '../../types'; -import { BaseChannel, type GuildRole, type GuildMember, type AllChannels, channelFrom } from '../../structures'; -import { PermissionsBitField } from '../../structures/extra/Permissions'; -import { BaseShorter } from './base'; -import { MergeOptions } from '../it/utils'; -import { type MessageStructure, Transformers } from '../../client/transformers'; -import type { MakeRequired } from '../types/util'; import { type ChannelType, PermissionFlagsBits } from '../../types'; +import { MergeOptions } from '../it/utils'; +import type { MakeRequired } from '../types/util'; +import { BaseShorter } from './base'; export class ChannelShorter extends BaseShorter { /** @@ -26,7 +28,7 @@ export class ChannelShorter extends BaseShorter { } async raw(id: string, force?: boolean): Promise { - let channel; + let channel: APIChannel | ReturnType; if (!force) { channel = await this.client.cache.channels?.raw(id); const overwrites = await this.client.cache.overwrites?.raw(id); @@ -38,7 +40,7 @@ export class ChannelShorter extends BaseShorter { channel = await this.client.proxy.channels(id).get(); await this.client.cache.channels?.patch(id, undefined, channel); - return channel; + return channel as APIChannel; } /** @@ -155,9 +157,9 @@ export class ChannelShorter extends BaseShorter { } async overwritesFor(channelId: string, member: GuildMember) { - const roleOverwrites = []; - let memberOverwrites; - let everyoneOverwrites; + const roleOverwrites: ReturnType = []; + let memberOverwrites: NonNullable>[number] | undefined; + let everyoneOverwrites: NonNullable>[number] | undefined; const channelOverwrites = (await this.client.cache.overwrites?.get(channelId)) ?? []; diff --git a/src/common/shorters/emojis.ts b/src/common/shorters/emojis.ts index 89c0104..cd8bb65 100644 --- a/src/common/shorters/emojis.ts +++ b/src/common/shorters/emojis.ts @@ -1,9 +1,9 @@ -import type { APIEmoji, RESTPatchAPIGuildEmojiJSONBody, RESTPostAPIGuildEmojiJSONBody } from '../../types'; import { resolveImage } from '../../builders'; +import { type GuildEmojiStructure, Transformers } from '../../client/transformers'; +import type { APIEmoji, RESTPatchAPIGuildEmojiJSONBody, RESTPostAPIGuildEmojiJSONBody } from '../../types'; import type { ImageResolvable } from '../types/resolvables'; import type { OmitInsert } from '../types/util'; import { BaseShorter } from './base'; -import { Transformers } from '../../client/transformers'; export class EmojiShorter extends BaseShorter { /** @@ -13,7 +13,7 @@ export class EmojiShorter extends BaseShorter { * @returns A Promise that resolves to an array of emojis. */ async list(guildId: string, force = false) { - let emojis; + let emojis: APIEmoji[] | GuildEmojiStructure[]; if (!force) { emojis = (await this.client.cache.emojis?.values(guildId)) ?? []; if (emojis.length) { @@ -53,7 +53,7 @@ export class EmojiShorter extends BaseShorter { * @returns A Promise that resolves to the fetched emoji. */ async fetch(guildId: string, emojiId: string, force = false) { - let emoji; + let emoji: APIEmoji | GuildEmojiStructure | undefined; if (!force) { emoji = await this.client.cache.emojis?.get(emojiId); if (emoji) return emoji; diff --git a/src/common/shorters/guilds.ts b/src/common/shorters/guilds.ts index f733169..59a1001 100644 --- a/src/common/shorters/guilds.ts +++ b/src/common/shorters/guilds.ts @@ -1,5 +1,10 @@ +import { resolveFiles } from '../../builders'; +import type { Channels } from '../../cache/resources/channels'; +import { type GuildStructure, type StickerStructure, Transformers } from '../../client/transformers'; +import { BaseChannel, type CreateStickerBodyRequest, Guild, GuildMember, channelFrom } from '../../structures'; import type { APIChannel, + APISticker, GuildWidgetStyle, RESTGetAPICurrentUserGuildsQuery, RESTPatchAPIAutoModerationRuleJSONBody, @@ -11,10 +16,7 @@ import type { RESTPostAPIGuildChannelJSONBody, RESTPostAPIGuildsJSONBody, } from '../../types'; -import { resolveFiles } from '../../builders'; -import { BaseChannel, channelFrom, Guild, GuildMember, type CreateStickerBodyRequest } from '../../structures'; import { BaseShorter } from './base'; -import { type GuildStructure, Transformers } from '../../client/transformers'; export class GuildShorter extends BaseShorter { /** @@ -108,7 +110,7 @@ export class GuildShorter extends BaseShorter { * @returns A Promise that resolves to an array of channels. */ list: async (guildId: string, force = false) => { - let channels; + let channels: ReturnType | APIChannel[]; if (!force) { channels = (await this.client.cache.channels?.values(guildId)) ?? []; if (channels.length) { @@ -131,7 +133,7 @@ export class GuildShorter extends BaseShorter { * @returns A Promise that resolves to the fetched channel. */ fetch: async (guildId: string, channelId: string, force?: boolean) => { - let channel; + let channel: APIChannel | ReturnType; if (!force) { channel = await this.client.cache.channels?.get(channelId); if (channel) return channel; @@ -328,7 +330,7 @@ export class GuildShorter extends BaseShorter { * @returns A Promise that resolves to the fetched sticker. */ fetch: async (guildId: string, stickerId: string, force = false) => { - let sticker; + let sticker: APISticker | StickerStructure | undefined; if (!force) { sticker = await this.client.cache.stickers?.get(stickerId); if (sticker) return sticker; diff --git a/src/common/shorters/members.ts b/src/common/shorters/members.ts index 7a6dad1..6652d8f 100644 --- a/src/common/shorters/members.ts +++ b/src/common/shorters/members.ts @@ -1,16 +1,16 @@ +import { type GuildMemberStructure, Transformers, type VoiceStateStructure } from '../../client/transformers'; +import { PermissionsBitField } from '../../structures/extra/Permissions'; import { type APIGuildMember, + FormattingPatterns, type RESTGetAPIGuildMembersQuery, type RESTGetAPIGuildMembersSearchQuery, type RESTPatchAPIGuildMemberJSONBody, type RESTPutAPIGuildBanJSONBody, type RESTPutAPIGuildMemberJSONBody, - FormattingPatterns, } from '../../types'; -import { PermissionsBitField } from '../../structures/extra/Permissions'; import type { GuildMemberResolvable } from '../types/resolvables'; import { BaseShorter } from './base'; -import { Transformers, type VoiceStateStructure } from '../../client/transformers'; export class MemberShorter extends BaseShorter { /** @@ -37,7 +37,7 @@ export class MemberShorter extends BaseShorter { return this.client.members.fetch(guildId, id); } - const displayName = 'displayName' in resolve ? resolve.displayName : resolve.nick ?? resolve.user?.username; + const displayName = 'displayName' in resolve ? resolve.displayName : (resolve.nick ?? resolve.user?.username); return displayName ? this.search(guildId, { query: displayName, limit: 1 }).then(x => x[0]) : undefined; } @@ -142,7 +142,7 @@ export class MemberShorter extends BaseShorter { } async raw(guildId: string, memberId: string, force = false) { - let member; + let member: APIGuildMember | undefined; if (!force) { member = await this.client.cache.members?.raw(memberId, guildId); if (member) return member; @@ -161,7 +161,7 @@ export class MemberShorter extends BaseShorter { * @returns A Promise that resolves to an array of listed members. */ async list(guildId: string, query?: RESTGetAPIGuildMembersQuery, force = false) { - let members; + let members: APIGuildMember[] | GuildMemberStructure[]; if (!force) { members = (await this.client.cache.members?.values(guildId)) ?? []; if (members.length) return members; diff --git a/src/common/shorters/webhook.ts b/src/common/shorters/webhook.ts index c38975e..4577edc 100644 --- a/src/common/shorters/webhook.ts +++ b/src/common/shorters/webhook.ts @@ -1,17 +1,18 @@ +import { resolveFiles } from '../../builders'; +import { Transformers } from '../../client/transformers'; +import { + type MessageWebhookMethodEditParams, + type MessageWebhookMethodWriteParams, + MessagesMethods, +} from '../../structures'; import type { + APIWebhook, RESTPatchAPIWebhookJSONBody, RESTPatchAPIWebhookWithTokenJSONBody, RESTPostAPIChannelWebhookJSONBody, RESTPostAPIWebhookWithTokenJSONBody, } from '../../types'; -import { resolveFiles } from '../../builders'; -import { - MessagesMethods, - type MessageWebhookMethodEditParams, - type MessageWebhookMethodWriteParams, -} from '../../structures'; import { BaseShorter } from './base'; -import { Transformers } from '../../client/transformers'; export class WebhookShorter extends BaseShorter { async create(channelId: string, body: RESTPostAPIChannelWebhookJSONBody) { @@ -64,7 +65,7 @@ export class WebhookShorter extends BaseShorter { * @returns A Promise that resolves to the fetched webhook. */ async fetch(webhookId: string, token?: string) { - let webhook; + let webhook: APIWebhook; if (token) { webhook = await this.client.proxy.webhooks(webhookId)(token).get({ auth: false }); } else { diff --git a/src/common/types/options.ts b/src/common/types/options.ts index d755c9c..437ad5c 100644 --- a/src/common/types/options.ts +++ b/src/common/types/options.ts @@ -4,6 +4,6 @@ import type { UsingClient } from '../../commands'; export type ImageOptions = CDNUrlOptions; -export type MethodContext = Identify<{ client: UsingClient } & T>; +export type MethodContext = Identify<{ client: UsingClient } & T>; -export type MessageWebhookPayload = Identify<{ body: Body } & Extra>; +export type MessageWebhookPayload = Identify<{ body: Body } & Extra>; diff --git a/src/common/types/util.ts b/src/common/types/util.ts index 4ad6960..b95f386 100644 --- a/src/common/types/util.ts +++ b/src/common/types/util.ts @@ -211,7 +211,7 @@ export type Clean = DropT; export type PartialAvoid = Identify & Partial>; -// eslint-disable-next-line @typescript-eslint/ban-types +//biome-ignore lint/complexity/noBannedTypes: export type PartialClass = PartialAvoid; export type AtLeastOne< diff --git a/src/components/handler.ts b/src/components/handler.ts index baed16e..81bff1a 100644 --- a/src/components/handler.ts +++ b/src/components/handler.ts @@ -2,7 +2,7 @@ import type { ComponentCallback, ListenerOptions, ModalSubmitCallback } from '.. import { LimitedCollection } from '../collection'; import { BaseCommand, type RegisteredMiddlewares, type UsingClient } from '../commands'; import type { FileLoaded } from '../commands/handler'; -import { BaseHandler, isCloudfareWorker, magicImport, type Logger, type OnFailCallback } from '../common'; +import { BaseHandler, type Logger, type OnFailCallback, isCloudfareWorker, magicImport } from '../common'; import type { ComponentInteraction, ModalSubmitInteraction, StringSelectMenuInteraction } from '../structures'; import { ComponentCommand, InteractionCommandType } from './componentcommand'; import type { ComponentContext } from './componentcontext'; @@ -165,7 +165,7 @@ export class ComponentHandler extends BaseHandler { set(instances: (new () => ComponentCommands)[]) { for (const i of instances) { - let component; + let component: ReturnType; try { component = this.callback(i); if (!component) continue; @@ -185,7 +185,7 @@ export class ComponentHandler extends BaseHandler { for (const { components, file } of paths.map(x => ({ components: this.onFile(x.file), file: x }))) { if (!components) continue; for (const value of components) { - let component; + let component: ReturnType; try { component = this.callback(value); if (!component) continue; diff --git a/src/components/index.ts b/src/components/index.ts index a30e122..3ee467d 100644 --- a/src/components/index.ts +++ b/src/components/index.ts @@ -36,7 +36,7 @@ export function componentFactory( component: APIMessageActionRowComponent, ): ActionRowMessageComponents | BaseComponent { switch (component.type) { - case ComponentType.Button: + case ComponentType.Button: { if (component.style === ButtonStyle.Link) { return new LinkButtonComponent(component); } @@ -44,6 +44,7 @@ export function componentFactory( return new SKUButtonComponent(component); } return new ButtonComponent(component); + } case ComponentType.ChannelSelect: return new ChannelSelectMenuComponent(component); case ComponentType.RoleSelect: diff --git a/src/deps/mixer.ts b/src/deps/mixer.ts index 72fbdff..6fd73aa 100644 --- a/src/deps/mixer.ts +++ b/src/deps/mixer.ts @@ -57,7 +57,7 @@ export function Mixin(...args: C): C[number] & T { } // https://github.com/tannerntannern/ts-mixer -export type TypeClass = (abstract new ( +export type TypeClass = (abstract new ( ...args: any[] ) => InstanceType) & StaticType; diff --git a/src/index.ts b/src/index.ts index 61cba94..119abc9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,3 @@ -import { GatewayIntentBits } from './types'; import { BaseClient, type BaseClientOptions, @@ -7,8 +6,9 @@ import { type RuntimeConfig, type RuntimeConfigHTTP, } from './client/base'; -import type { CustomEventsKeys, ClientNameEvents, ResolveEventParams } from './events'; import { isCloudfareWorker } from './common'; +import type { ClientNameEvents, CustomEventsKeys, ResolveEventParams } from './events'; +import { GatewayIntentBits } from './types'; export { Logger, PermissionStrings, Formatter } from './common'; // export { Collection, LimitedCollection } from './collection'; @@ -64,11 +64,11 @@ export const config = { 'intents' in data ? typeof data.intents === 'number' ? data.intents - : data.intents?.reduce( + : (data.intents?.reduce( (pr, acc) => pr | (typeof acc === 'number' ? acc : GatewayIntentBits[acc as keyof typeof GatewayIntentBits]), 0, - ) ?? 0 + ) ?? 0) : 0, } as InternalRuntimeConfig; }, diff --git a/src/langs/router.ts b/src/langs/router.ts index 607baba..b255792 100644 --- a/src/langs/router.ts +++ b/src/langs/router.ts @@ -18,7 +18,7 @@ export const LangRouter = (userLocale: string, defaultLang: string, langs: Parti return value; } return (locale?: string) => { - let result; + let result: unknown; try { result = getValue(locale ?? userLocale); } catch { diff --git a/src/structures/Interaction.ts b/src/structures/Interaction.ts index e9c0704..3e8c61e 100644 --- a/src/structures/Interaction.ts +++ b/src/structures/Interaction.ts @@ -6,6 +6,7 @@ import { type APIChatInputApplicationCommandInteraction, type APIChatInputApplicationCommandInteractionData, type APICommandAutocompleteInteractionResponseCallbackData, + type APIEntryPointCommandInteraction, type APIInteraction, type APIInteractionResponse, type APIInteractionResponseChannelMessageWithSource, @@ -31,24 +32,28 @@ import { ApplicationCommandType, ComponentType, type GatewayInteractionCreateDispatchData, + type InteractionCallbackData, + type InteractionCallbackResourceActivity, InteractionResponseType, InteractionType, type MessageFlags, - type RESTPostAPIInteractionCallbackJSONBody, type RESTAPIAttachment, - type APIEntryPointCommandInteraction, - type InteractionCallbackData, - type InteractionCallbackResourceActivity, + type RESTPostAPIInteractionCallbackJSONBody, } from '../types'; import type { RawFile } from '../api'; import { ActionRow, Embed, Modal, PollBuilder, resolveAttachment, resolveFiles } from '../builders'; +import { + type GuildRoleStructure, + type InteractionGuildMemberStructure, + type MessageStructure, + type OptionResolverStructure, + Transformers, + type UserStructure, + type WebhookMessageStructure, +} from '../client/transformers'; import type { ContextOptionsResolved, UsingClient } from '../commands'; import { - type ObjectToLower, - type OmitInsert, - type ToClass, - type When, type ComponentInteractionMessageUpdate, type InteractionCreateBodyRequest, type InteractionMessageUpdateBodyRequest, @@ -56,22 +61,17 @@ import { type MessageUpdateBodyRequest, type MessageWebhookCreateBodyRequest, type ModalCreateBodyRequest, + type ObjectToLower, + type OmitInsert, + type ToClass, + type When, toCamelCase, } from '../common'; -import { channelFrom, type AllChannels } from './'; +import { mix } from '../deps/mixer'; +import { type AllChannels, channelFrom } from './'; +import { Entitlement } from './Entitlement'; import { DiscordBase } from './extra/DiscordBase'; import { PermissionsBitField } from './extra/Permissions'; -import { - type GuildRoleStructure, - type InteractionGuildMemberStructure, - type MessageStructure, - Transformers, - type UserStructure, - type WebhookMessageStructure, - type OptionResolverStructure, -} from '../client/transformers'; -import { mix } from '../deps/mixer'; -import { Entitlement } from './Entitlement'; export type ReplyInteractionBody = | { type: InteractionResponseType.Modal; data: ModalCreateBodyRequest } @@ -774,7 +774,7 @@ export class ModalSubmitInteraction extends getInputValue(customId: string, required: true): string; getInputValue(customId: string, required?: false): string | undefined; getInputValue(customId: string, required?: boolean): string | undefined { - let value; + let value: string | undefined; for (const { components } of this.components) { const get = components.find(x => x.customId === customId); if (get) { diff --git a/src/structures/channels.ts b/src/structures/channels.ts index a33609a..0939e92 100644 --- a/src/structures/channels.ts +++ b/src/structures/channels.ts @@ -1,45 +1,5 @@ -import { - type APIChannelBase, - type RESTPatchAPIChannelJSONBody, - type RESTPostAPIGuildChannelJSONBody, - type RESTPatchAPIGuildChannelPositionsJSONBody, - type APIGuildChannel, - type RESTGetAPIChannelMessageReactionUsersQuery, - type RESTAPIAttachment, - type APITextChannel, - type APIGuildForumTag, - type ThreadAutoArchiveDuration, - type APIGuildForumDefaultReactionEmoji, - type SortOrderType, - type RESTPostAPIGuildForumThreadsJSONBody, - type RESTPostAPIChannelWebhookJSONBody, - type APIDMChannel, - type APIGuildVoiceChannel, - type APIGuildStageVoiceChannel, - type APIGuildMediaChannel, - type APIGuildForumChannel, - type APIThreadChannel, - ChannelFlags, - type APIGuildCategoryChannel, - type APINewsChannel, - ChannelType, - VideoQualityMode, -} from '../types'; -import { ActionRow, Embed, PollBuilder, resolveAttachment } from '../builders'; -import type { UsingClient } from '../commands'; -import type { - EmojiResolvable, - MessageCreateBodyRequest, - MessageUpdateBodyRequest, - MethodContext, - ObjectToLower, - StringToNumber, - ToClass, -} from '../common'; -import type { GuildMember } from './GuildMember'; -import type { GuildRole } from './GuildRole'; -import { DiscordBase } from './extra/DiscordBase'; import { Collection, Formatter, type RawFile } from '..'; +import { ActionRow, Embed, PollBuilder, resolveAttachment } from '../builders'; import { type BaseChannelStructure, type BaseGuildChannelStructure, @@ -56,7 +16,47 @@ import { Transformers, type VoiceChannelStructure, } from '../client/transformers'; +import type { UsingClient } from '../commands'; +import type { + EmojiResolvable, + MessageCreateBodyRequest, + MessageUpdateBodyRequest, + MethodContext, + ObjectToLower, + StringToNumber, + ToClass, +} from '../common'; import { mix } from '../deps/mixer'; +import { + type APIChannelBase, + type APIDMChannel, + type APIGuildCategoryChannel, + type APIGuildChannel, + type APIGuildForumChannel, + type APIGuildForumDefaultReactionEmoji, + type APIGuildForumTag, + type APIGuildMediaChannel, + type APIGuildStageVoiceChannel, + type APIGuildVoiceChannel, + type APINewsChannel, + type APITextChannel, + type APIThreadChannel, + ChannelFlags, + ChannelType, + type RESTAPIAttachment, + type RESTGetAPIChannelMessageReactionUsersQuery, + type RESTPatchAPIChannelJSONBody, + type RESTPatchAPIGuildChannelPositionsJSONBody, + type RESTPostAPIChannelWebhookJSONBody, + type RESTPostAPIGuildChannelJSONBody, + type RESTPostAPIGuildForumThreadsJSONBody, + type SortOrderType, + type ThreadAutoArchiveDuration, + VideoQualityMode, +} from '../types'; +import type { GuildMember } from './GuildMember'; +import type { GuildRole } from './GuildRole'; +import { DiscordBase } from './extra/DiscordBase'; export class BaseChannel extends DiscordBase> { declare type: T; @@ -189,7 +189,7 @@ export class BaseGuildChannel extends BaseChannel { permissionOverwrites = { fetch: () => this.client.cache.overwrites?.get(this.id), - values: () => (this.guildId ? this.client.cache.overwrites?.values(this.guildId) ?? [] : []), + values: () => (this.guildId ? (this.client.cache.overwrites?.values(this.guildId) ?? []) : []), }; memberPermissions(member: GuildMember, checkAdmin = true) { @@ -333,11 +333,12 @@ export function channelFrom(data: APIChannelBase, client: UsingClie return Transformers.CategoryChannel(client, data); case ChannelType.GuildAnnouncement: return Transformers.NewsChannel(client, data); - default: + default: { if ('guild_id' in data) { return Transformers.BaseGuildChannel(client, data as APIGuildChannel); } return Transformers.BaseChannel(client, data); + } } } diff --git a/src/structures/extra/BitField.ts b/src/structures/extra/BitField.ts index 54de824..8606003 100644 --- a/src/structures/extra/BitField.ts +++ b/src/structures/extra/BitField.ts @@ -60,11 +60,12 @@ export class BitField { return this.resolve(this.Flags[bits]); case 'bigint': return bits; - case 'object': + case 'object': { if (!Array.isArray(bits)) { throw new TypeError(`Cannot resolve permission: ${bits}`); } return bits.map(x => this.resolve(x)).reduce((acc, cur) => acc | cur, BitField.None); + } default: throw new TypeError(`Cannot resolve permission: ${typeof bits === 'symbol' ? String(bits) : (bits as any)}`); } diff --git a/src/types/payloads/user.ts b/src/types/payloads/user.ts index ffdbee0..7a6e145 100644 --- a/src/types/payloads/user.ts +++ b/src/types/payloads/user.ts @@ -296,7 +296,6 @@ export enum ConnectionService { * @deprecated This is the old name for {@apilink ConnectionService#X} */ - // biome-ignore lint/correctness/noUndeclaredVariables: biome bug lol Twitter = X, Xbox = 'xbox', YouTube = 'youtube', diff --git a/src/types/utils/index.ts b/src/types/utils/index.ts index 3759a64..174350e 100644 --- a/src/types/utils/index.ts +++ b/src/types/utils/index.ts @@ -293,7 +293,6 @@ export enum GatewayIntentBits { * @deprecated This is the old name for {@apilink GatewayIntentBits#GuildModeration} */ - // biome-ignore lint/correctness/noUndeclaredVariables: no reason lmao GuildBans = GuildModeration, GuildEmojisAndStickers = 1 << 3, GuildIntegrations = 1 << 4, diff --git a/src/websocket/constants/index.ts b/src/websocket/constants/index.ts index 6e7e1c0..8a6a13d 100644 --- a/src/websocket/constants/index.ts +++ b/src/websocket/constants/index.ts @@ -1,5 +1,4 @@ import type { DeepPartial } from '../../common'; -import type { GatewayDispatchPayload } from '../../types'; import type { ShardManagerOptions, WorkerManagerOptions } from '../discord'; const COMPRESS = false; @@ -18,9 +17,6 @@ const ShardManagerDefaults: DeepPartial = { properties, version: 10, shardStart: 0, - handlePayload: (shardId: number, packet: GatewayDispatchPayload): void => { - console.info(`Packet ${packet.t} on shard ${shardId}`); - }, resharding: { interval: 8 * 60 * 60 * 1e3, // 8h percentage: 80, @@ -36,7 +32,6 @@ const ShardManagerDefaults: DeepPartial = { const WorkerManagerDefaults: DeepPartial = { ...ShardManagerDefaults, shardsPerWorker: 16, - handlePayload: (_shardId: number, _workerId: number, _packet: GatewayDispatchPayload): void => {}, }; export interface IdentifyProperties { diff --git a/src/websocket/discord/shard.ts b/src/websocket/discord/shard.ts index 5f63d65..36dcb24 100644 --- a/src/websocket/discord/shard.ts +++ b/src/websocket/discord/shard.ts @@ -1,18 +1,19 @@ import { inflateSync } from 'node:zlib'; -import { Logger, LogLevels, type MakeRequired, MergeOptions } from '../../common'; +import { LogLevels, Logger, type MakeRequired, MergeOptions } from '../../common'; +import { + GatewayCloseCodes, + GatewayDispatchEvents, + type GatewayDispatchPayload, + GatewayOpcodes, + type GatewayReceivePayload, + type GatewaySendPayload, +} from '../../types'; import { properties } from '../constants'; import { DynamicBucket } from '../structures'; import { ConnectTimeout } from '../structures/timeout'; import { BaseSocket } from './basesocket'; import type { ShardData, ShardOptions } from './shared'; import { ShardSocketCloseCodes } from './shared'; -import { - type GatewaySendPayload, - type GatewayReceivePayload, - GatewayCloseCodes, - GatewayDispatchEvents, - GatewayOpcodes, -} from '../../types'; export interface ShardHeart { interval: number; @@ -229,8 +230,10 @@ export class Shard { } break; case GatewayOpcodes.HeartbeatAck: - this.heart.ack = true; - this.heart.lastAck = Date.now(); + { + this.heart.ack = true; + this.heart.lastAck = Date.now(); + } break; case GatewayOpcodes.Heartbeat: this.heartbeat(true); @@ -254,8 +257,10 @@ export class Shard { { switch (packet.t) { case GatewayDispatchEvents.Resumed: - this.offlineSendQueue.map((resolve: () => any) => resolve()); - this.options.handlePayload(this.id, packet); + { + this.offlineSendQueue.map((resolve: () => any) => resolve()); + this.options.handlePayload(this.id, packet); + } break; case GatewayDispatchEvents.Ready: { this.data.resume_gateway_url = packet.d.resume_gateway_url; @@ -288,10 +293,12 @@ export class Shard { case GatewayCloseCodes.UnknownOpcode: case GatewayCloseCodes.InvalidSeq: case GatewayCloseCodes.SessionTimedOut: - this.data.resume_seq = 0; - this.data.session_id = undefined; - this.data.resume_gateway_url = undefined; - await this.reconnect(); + { + this.data.resume_seq = 0; + this.data.session_id = undefined; + this.data.resume_gateway_url = undefined; + await this.reconnect(); + } break; case 1001: case 1006: @@ -301,8 +308,10 @@ export class Shard { case GatewayCloseCodes.NotAuthenticated: case GatewayCloseCodes.AlreadyAuthenticated: case GatewayCloseCodes.RateLimited: - this.logger.info('Trying to reconnect'); - await this.reconnect(); + { + this.logger.info('Trying to reconnect'); + await this.reconnect(); + } break; case GatewayCloseCodes.AuthenticationFailed: @@ -315,8 +324,10 @@ export class Shard { break; default: - this.logger.warn('Unknown close code, trying to reconnect anyways'); - await this.reconnect(); + { + this.logger.warn('Unknown close code, trying to reconnect anyways'); + await this.reconnect(); + } break; } } @@ -331,7 +342,7 @@ export class Shard { } protected handleMessage(data: string | Buffer) { - let packet; + let packet: GatewayDispatchPayload; try { if (data instanceof Buffer) { data = inflateSync(data); diff --git a/src/websocket/discord/sharder.ts b/src/websocket/discord/sharder.ts index 5ddd4b7..42a2b48 100644 --- a/src/websocket/discord/sharder.ts +++ b/src/websocket/discord/sharder.ts @@ -3,23 +3,23 @@ import { Logger, type MakeRequired, MergeOptions, - lazyLoadPackage, type WatcherSendToShard, calculateShardId, + lazyLoadPackage, } from '../../common'; +import type { MakeDeepPartial } from '../../common/types/util'; import { + type GatewayDispatchPayload, + GatewayOpcodes, + type GatewaySendPayload, type GatewayUpdatePresence, type GatewayVoiceStateUpdate, - type GatewaySendPayload, - GatewayOpcodes, - type GatewayDispatchPayload, } from '../../types'; import { ShardManagerDefaults } from '../constants'; import { DynamicBucket } from '../structures'; import { ConnectQueue } from '../structures/timeout'; import { Shard } from './shard'; import type { ShardManagerOptions, WorkerData } from './shared'; -import type { MakeDeepPartial } from '../../common/types/util'; let parentPort: import('node:worker_threads').MessagePort; let workerData: WorkerData; @@ -162,7 +162,9 @@ export class ShardManager extends Map { if (++shardsConnected < info.shards) return; //waiting for last shard to connect // dont listen more events when all shards are ready - handlePayload = async () => {}; + handlePayload = async () => { + // + }; await this.disconnectAll(); this.clear(); @@ -183,7 +185,9 @@ export class ShardManager extends Map { getInfo: () => ({}) as any, interval: 0, percentage: 0, - reloadGuilds() {}, + reloadGuilds() { + // + }, onGuild() { return true; }, diff --git a/src/websocket/discord/shared.ts b/src/websocket/discord/shared.ts index 6a76d19..685812c 100644 --- a/src/websocket/discord/shared.ts +++ b/src/websocket/discord/shared.ts @@ -1,10 +1,10 @@ +import type { Awaitable, DeepPartial, Logger } from '../../common'; import type { APIGatewayBotInfo, GatewayDispatchPayload, GatewayIntentBits, GatewayPresenceUpdateData, } from '../../types'; -import type { Awaitable, DeepPartial, Logger } from '../../common'; import type { IdentifyProperties } from '../constants'; export interface ShardManagerOptions extends ShardDetails { @@ -79,7 +79,7 @@ export interface WorkerManagerOptions extends Omit>; } diff --git a/src/websocket/discord/socket/custom.ts b/src/websocket/discord/socket/custom.ts index 1384269..5c1f1cb 100644 --- a/src/websocket/discord/socket/custom.ts +++ b/src/websocket/discord/socket/custom.ts @@ -1,4 +1,4 @@ -import { randomBytes, createHash, randomUUID } from 'node:crypto'; +import { createHash, randomBytes, randomUUID } from 'node:crypto'; import { request } from 'node:https'; import type { Socket } from 'node:net'; @@ -179,7 +179,7 @@ export class SeyfertWebSocket { private _write(buffer: Buffer, opcode: number) { if (!this.socket?.writable) return; const length = buffer.length; - let frame; + let frame: Buffer; // Kinda same logic as above, but client-side if (length < 126) { frame = Buffer.allocUnsafe(6 + length); @@ -200,17 +200,29 @@ export class SeyfertWebSocket { this.socket?.write(frame); } - onping(_data: string) {} + onping(_data: string) { + // + } - onpong(_data: string) {} + onpong(_data: string) { + // + } - onopen() {} + onopen() { + // + } - onmessage(_payload: { data: string | Buffer }) {} + onmessage(_payload: { data: string | Buffer }) { + // + } - onclose(_close: { code: number; reason: string }) {} + onclose(_close: { code: number; reason: string }) { + // + } - onerror(_err: unknown) {} + onerror(_err: unknown) { + // + } close(code: number, reason: string) { this.__closeCalled = true; @@ -299,7 +311,7 @@ export class SeyfertWebSocket { // actual index of the buffer to read let blockIndex = readable.bufferIndex; // Buffer to read - let block; + let block: Buffer | undefined; while ((block = readable.buffer[blockIndex++])) { for (let i = 0; i < block.length; i++) { if (++bitIndex > start) { diff --git a/src/websocket/discord/worker.ts b/src/websocket/discord/worker.ts index fbadd8a..b798c6b 100644 --- a/src/websocket/discord/worker.ts +++ b/src/websocket/discord/worker.ts @@ -10,7 +10,7 @@ export interface WorkerShardInfo { export type WorkerInfo = { shards: WorkerShardInfo[] }; -type CreateWorkerMessage = { +type CreateWorkerMessage = { type: T; workerId: number; } & D; diff --git a/src/websocket/discord/workermanager.ts b/src/websocket/discord/workermanager.ts index b3b88e2..d04b970 100644 --- a/src/websocket/discord/workermanager.ts +++ b/src/websocket/discord/workermanager.ts @@ -1,10 +1,10 @@ -import type { GatewayPresenceUpdateData, GatewaySendPayload } from '../../types'; import cluster, { type Worker as ClusterWorker } from 'node:cluster'; import { randomUUID } from 'node:crypto'; import { ApiHandler, Logger, Router } from '../..'; -import { MemoryAdapter, type Adapter } from '../../cache'; +import { type Adapter, MemoryAdapter } from '../../cache'; import { BaseClient, type InternalRuntimeConfig } from '../../client/base'; -import { MergeOptions, lazyLoadPackage, type MakePartial } from '../../common'; +import { type MakePartial, MergeOptions, lazyLoadPackage } from '../../common'; +import type { GatewayPresenceUpdateData, GatewaySendPayload } from '../../types'; import { WorkerManagerDefaults, properties } from '../constants'; import { DynamicBucket } from '../structures'; import { ConnectQueue } from '../structures/timeout'; @@ -181,11 +181,12 @@ export class WorkerManager extends Map< worker.on('message', data => this.handleWorkerMessage(data)); return worker; } - case 'custom': + case 'custom': { this.options.adapter!.spawn(workerData, env); return { ready: false, }; + } } } @@ -450,7 +451,7 @@ export class WorkerManager extends Map< } } -type CreateManagerMessage = { type: T } & D; +type CreateManagerMessage = { type: T } & D; export type ManagerAllowConnect = CreateManagerMessage< 'ALLOW_CONNECT',