diff --git a/.eslintignore b/.eslintignore index f995260..f81bd34 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,4 +1,5 @@ node_modules/ build dist -examples/** \ No newline at end of file +examples/** +tsup.config.ts diff --git a/.eslintrc.yml b/.eslintrc.yml index 06e5891..504b65d 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -20,12 +20,18 @@ ignorePatterns: parser: '@typescript-eslint/parser' parserOptions: - project: 'tsconfig.json' + project: './packages/**/tsconfig.json' sourceType: 'module' plugins: - '@typescript-eslint' +# silly eslint bug +overrides: + - files: ['*.ts'] + rules: + no-undef: 'off' + rules: '@typescript-eslint/consistent-type-imports': 'error' '@typescript-eslint/no-duplicate-imports': 'error' diff --git a/.gitignore b/.gitignore index 704df77..ece695a 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ package-lock.json # Eater asked for this dunno why bot/ +apps/ # Enviorment .env diff --git a/packages/api-types/src/common.ts b/packages/api-types/src/common.ts index f44c17f..fc2d605 100644 --- a/packages/api-types/src/common.ts +++ b/packages/api-types/src/common.ts @@ -1,4 +1,3 @@ -/* eslint-disable no-mixed-spaces-and-tabs */ /** https://discord.com/developers/docs/resources/user#user-object-premium-types */ export enum PremiumTypes { None, @@ -1253,9 +1252,9 @@ export type Camelize = { // eslint-disable-next-line @typescript-eslint/array-type [K in keyof T as CamelCase]: T[K] extends Array ? // eslint-disable-next-line @typescript-eslint/ban-types - U extends {} + U extends {} ? // eslint-disable-next-line @typescript-eslint/array-type - Array> + Array> : T[K] : // eslint-disable-next-line @typescript-eslint/ban-types T[K] extends {} diff --git a/packages/api-types/src/utils/routes.ts b/packages/api-types/src/utils/routes.ts index 1447621..20baa81 100644 --- a/packages/api-types/src/utils/routes.ts +++ b/packages/api-types/src/utils/routes.ts @@ -81,8 +81,8 @@ export interface ListGuildMembers { export function GUILD_MEMBERS(guildId: Snowflake, options?: ListGuildMembers) { let url = `/guilds/${guildId}/members?`; - if (options?.limit) url += `limit=${options.limit}`; - if (options?.after) url += `&after=${options.after}`; + if (options?.limit) { url += `limit=${options.limit}`; } + if (options?.after) { url += `&after=${options.after}`; } return url; } @@ -129,13 +129,13 @@ export function USER_DM() { } export function GUILD_EMOJIS(guildId: Snowflake, emojiId?: Snowflake): string { - if (emojiId) return `/guilds/${guildId}/emojis/${emojiId}`; + if (emojiId) { return `/guilds/${guildId}/emojis/${emojiId}`; } return `/guilds/${guildId}/emojis`; } export interface GetAuditLogs { userId?: Snowflake; - actionType?: AuditLogEvents + actionType?: AuditLogEvents; before?: Snowflake; limit?: number; } @@ -150,8 +150,8 @@ export function GUILD_AUDIT_LOGS(guildId: Snowflake, options?: GetAuditLogs) { limit: options.limit }; for (const [key, value] of Object.entries(obj)) { - if (!value) continue; - url += `&${key}=${value}` + if (!value) { continue; } + url += `&${key}=${value}`; } } return url; diff --git a/packages/api-types/src/v10/index.ts b/packages/api-types/src/v10/index.ts index 260ca02..1656d74 100644 --- a/packages/api-types/src/v10/index.ts +++ b/packages/api-types/src/v10/index.ts @@ -1,4 +1,3 @@ -/* eslint-disable no-mixed-spaces-and-tabs */ import type { ActivityTypes, AllowedMentionsTypes, @@ -18,8 +17,6 @@ import type { GuildNsfwLevel, IntegrationExpireBehaviors, InteractionTypes, - // No used - // Locales, Localization, MessageActivityTypes, MessageComponentTypes, diff --git a/packages/cache/src/adapters/memory-cache-adapter.ts b/packages/cache/src/adapters/memory-cache-adapter.ts index 66e64df..24dd640 100644 --- a/packages/cache/src/adapters/memory-cache-adapter.ts +++ b/packages/cache/src/adapters/memory-cache-adapter.ts @@ -1,5 +1,5 @@ import type { CacheAdapter } from './cache-adapter'; - + interface Options { expire?: number; } diff --git a/packages/cache/src/adapters/redis-cache-adapter.ts b/packages/cache/src/adapters/redis-cache-adapter.ts index 3c131b5..9b0bbcf 100644 --- a/packages/cache/src/adapters/redis-cache-adapter.ts +++ b/packages/cache/src/adapters/redis-cache-adapter.ts @@ -1,6 +1,7 @@ import type { CacheAdapter } from './cache-adapter'; -import Redis, { RedisOptions } from 'ioredis'; +import type { RedisOptions } from 'ioredis'; +import type Redis from 'ioredis'; import IORedis from 'ioredis'; interface BaseOptions { @@ -13,7 +14,7 @@ interface BuildOptions extends BaseOptions, RedisOptions { } interface ClientOptions extends BaseOptions { client: Redis; } - + type Options = BuildOptions | ClientOptions; export class RedisCacheAdapter implements CacheAdapter { @@ -114,7 +115,7 @@ export class RedisCacheAdapter implements CacheAdapter { * @inheritDoc */ - composite(id: string): string { + composite(id: string): string { return `${this.options.namespace}:${id}`; } -} \ No newline at end of file +} diff --git a/packages/cache/src/cache.ts b/packages/cache/src/cache.ts index 730fd32..5ac79f5 100644 --- a/packages/cache/src/cache.ts +++ b/packages/cache/src/cache.ts @@ -1,3 +1,4 @@ +/* eslint-disable no-case-declarations */ import { MemoryCacheAdapter } from './adapters/memory-cache-adapter'; // import { RedisCacheAdapter } from './adapters/redis-cache-adapter'; @@ -69,7 +70,7 @@ export class Cache { case 'READY': await this.users.set(event.d.user.id, event.d.user); - const guilds: Array | undefined> = []; + const guilds: (Promise | undefined)[] = []; for (const guild of event.d.guilds) { guilds.push(this.guilds.set(guild.id, guild)); @@ -170,7 +171,7 @@ export class Cache { break; case 'GUILD_MEMBERS_CHUNK': - const members: Array | undefined> = []; + const members: (Promise | undefined)[] = []; for (const member of event.d.members) { members.push( diff --git a/packages/cache/src/resources/base-resource.ts b/packages/cache/src/resources/base-resource.ts index 23b6c13..b453e35 100644 --- a/packages/cache/src/resources/base-resource.ts +++ b/packages/cache/src/resources/base-resource.ts @@ -1,14 +1,10 @@ -import { CacheAdapter } from '../adapters/cache-adapter'; +import type { CacheAdapter } from '../adapters/cache-adapter'; export class BaseResource { namespace = 'base'; adapter!: CacheAdapter; // replace - constructor() { - // - } - /** * @inheritDoc */ diff --git a/packages/cache/src/resources/channel-resource.ts b/packages/cache/src/resources/channel-resource.ts index caed1ca..bcc65c1 100644 --- a/packages/cache/src/resources/channel-resource.ts +++ b/packages/cache/src/resources/channel-resource.ts @@ -1,10 +1,10 @@ -import { CacheAdapter } from '../adapters/cache-adapter'; -import { DiscordChannel } from '@biscuitland/api-types'; +import type { CacheAdapter } from '../adapters/cache-adapter'; +import type { DiscordChannel } from '@biscuitland/api-types'; import { BaseResource } from './base-resource'; export class ChannelResource extends BaseResource { - namespace: 'channel' = 'channel'; + namespace = 'channel' as const; adapter: CacheAdapter; diff --git a/packages/cache/src/resources/guild-emoji-resource.ts b/packages/cache/src/resources/guild-emoji-resource.ts index 00844f7..accd145 100644 --- a/packages/cache/src/resources/guild-emoji-resource.ts +++ b/packages/cache/src/resources/guild-emoji-resource.ts @@ -1,10 +1,10 @@ -import { CacheAdapter } from '../adapters/cache-adapter'; -import { DiscordEmoji } from '@biscuitland/api-types'; +import type { CacheAdapter } from '../adapters/cache-adapter'; +import type { DiscordEmoji } from '@biscuitland/api-types'; import { BaseResource } from './base-resource'; export class GuildEmojiResource extends BaseResource { - namespace: 'emoji' = 'emoji'; + namespace = 'emoji' as const; adapter: CacheAdapter; diff --git a/packages/cache/src/resources/guild-member-resource.ts b/packages/cache/src/resources/guild-member-resource.ts index c7fb5c1..87ac4b1 100644 --- a/packages/cache/src/resources/guild-member-resource.ts +++ b/packages/cache/src/resources/guild-member-resource.ts @@ -1,11 +1,11 @@ -import { CacheAdapter } from '../adapters/cache-adapter'; -import { DiscordMember } from '@biscuitland/api-types'; +import type { CacheAdapter } from '../adapters/cache-adapter'; +import type { DiscordMember } from '@biscuitland/api-types'; import { BaseResource } from './base-resource'; import { UserResource } from './user-resource'; export class GuildMemberResource extends BaseResource { - namespace: 'member' = 'member'; + namespace = 'member' as const; adapter: CacheAdapter; users: UserResource; diff --git a/packages/cache/src/resources/guild-resource.ts b/packages/cache/src/resources/guild-resource.ts index 0df4981..f7d80a1 100644 --- a/packages/cache/src/resources/guild-resource.ts +++ b/packages/cache/src/resources/guild-resource.ts @@ -1,5 +1,5 @@ -import { CacheAdapter } from '../adapters/cache-adapter'; -import { DiscordGuild } from '@biscuitland/api-types'; +import type { CacheAdapter } from '../adapters/cache-adapter'; +import type { DiscordGuild } from '@biscuitland/api-types'; import { ChannelResource } from './channel-resource'; import { GuildEmojiResource } from './guild-emoji-resource'; @@ -11,7 +11,7 @@ import { VoiceResource } from './voice-resource'; import { BaseResource } from './base-resource'; export class GuildResource extends BaseResource { - namespace: 'guild' = 'guild'; + namespace = 'guild' as const; adapter: CacheAdapter; @@ -55,7 +55,7 @@ export class GuildResource extends BaseResource { async set(id: string, data: any, expire?: number): Promise { if (data.channels) { - const channels: Array | undefined> = []; + const channels: (Promise | undefined)[] = []; for (const channel of data.channels) { await this.channels.set(channel.id, channel); @@ -65,7 +65,7 @@ export class GuildResource extends BaseResource { } if (data.members) { - const members: Array | undefined> = []; + const members: (Promise | undefined)[] = []; for (const member of data.members) { await this.members.set(member.user.id, id, member); @@ -75,7 +75,7 @@ export class GuildResource extends BaseResource { } if (data.roles) { - const roles: Array | undefined> = []; + const roles: (Promise | undefined)[] = []; for (const role of data.roles) { await this.roles.set(role.id, id, role); @@ -85,7 +85,7 @@ export class GuildResource extends BaseResource { } if (data.stickers) { - const stickers: Array | undefined> = []; + const stickers: (Promise | undefined)[] = []; for (const sticker of data.stickers) { await this.stickers.set(sticker.id, id, sticker); @@ -95,7 +95,7 @@ export class GuildResource extends BaseResource { } if (data.emojis) { - const emojis: Array | undefined> = []; + const emojis: (Promise | undefined)[] = []; for (const emoji of data.emojis) { await this.emojis.set(emoji.id, id, emoji); @@ -105,7 +105,7 @@ export class GuildResource extends BaseResource { } if (data.voice_states) { - const voices: Array> = []; + const voices: Promise[] = []; for (const voice of data.voice_states) { if (!voice.guild_id) { diff --git a/packages/cache/src/resources/guild-role-resource.ts b/packages/cache/src/resources/guild-role-resource.ts index 80933b4..7c69b99 100644 --- a/packages/cache/src/resources/guild-role-resource.ts +++ b/packages/cache/src/resources/guild-role-resource.ts @@ -1,10 +1,10 @@ -import { CacheAdapter } from '../adapters/cache-adapter'; -import { DiscordRole } from '@biscuitland/api-types'; +import type { CacheAdapter } from '../adapters/cache-adapter'; +import type { DiscordRole } from '@biscuitland/api-types'; import { BaseResource } from './base-resource'; export class GuildRoleResource extends BaseResource { - namespace: 'role' = 'role'; + namespace = 'role' as const; adapter: CacheAdapter; diff --git a/packages/cache/src/resources/guild-sticker-resource.ts b/packages/cache/src/resources/guild-sticker-resource.ts index 9e88c73..e7938b0 100644 --- a/packages/cache/src/resources/guild-sticker-resource.ts +++ b/packages/cache/src/resources/guild-sticker-resource.ts @@ -1,10 +1,10 @@ -import { CacheAdapter } from '../adapters/cache-adapter'; -import { DiscordSticker } from '@biscuitland/api-types'; +import type { CacheAdapter } from '../adapters/cache-adapter'; +import type { DiscordSticker } from '@biscuitland/api-types'; import { BaseResource } from './base-resource'; export class GuildStickerResource extends BaseResource { - namespace: 'sticker' = 'sticker'; + namespace = 'sticker' as const; adapter: CacheAdapter; diff --git a/packages/cache/src/resources/user-resource.ts b/packages/cache/src/resources/user-resource.ts index 5d42b9a..310d3ef 100644 --- a/packages/cache/src/resources/user-resource.ts +++ b/packages/cache/src/resources/user-resource.ts @@ -1,10 +1,10 @@ -import { CacheAdapter } from '../adapters/cache-adapter'; -import { DiscordUser } from '@biscuitland/api-types'; +import type { CacheAdapter } from '../adapters/cache-adapter'; +import type { DiscordUser } from '@biscuitland/api-types'; import { BaseResource } from './base-resource'; export class UserResource extends BaseResource { - namespace: 'user' = 'user'; + namespace = 'user' as const; adapter: CacheAdapter; diff --git a/packages/cache/src/resources/voice-resource.ts b/packages/cache/src/resources/voice-resource.ts index b4d2e8f..20b25d5 100644 --- a/packages/cache/src/resources/voice-resource.ts +++ b/packages/cache/src/resources/voice-resource.ts @@ -1,10 +1,10 @@ -import { CacheAdapter } from '../adapters/cache-adapter'; -import { DiscordVoiceState } from '@biscuitland/api-types'; +import type { CacheAdapter } from '../adapters/cache-adapter'; +import type { DiscordVoiceState } from '@biscuitland/api-types'; import { BaseResource } from './base-resource'; export class VoiceResource extends BaseResource { - namespace: 'voice' = 'voice'; + namespace = 'voice' as const; adapter: CacheAdapter; diff --git a/packages/core/package.json b/packages/core/package.json index c3d2eab..65fa6d1 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -28,6 +28,7 @@ "@biscuitland/ws": "^2.0.5" }, "devDependencies": { + "@types/node": "^18.7.14", "tsup": "^6.1.3" }, "license": "Apache-2.0", diff --git a/packages/core/src/adapters/event-adapter.ts b/packages/core/src/adapters/event-adapter.ts index 008a0a3..1c5c664 100644 --- a/packages/core/src/adapters/event-adapter.ts +++ b/packages/core/src/adapters/event-adapter.ts @@ -1,7 +1,6 @@ -import type { EventEmitter } from 'stream'; import type { Events } from './events'; -export interface EventAdapter extends Omit { +export interface EventAdapter extends Omit { options?: any; emit( diff --git a/packages/helpers/package.json b/packages/helpers/package.json index 27dfa9b..b41d44c 100644 --- a/packages/helpers/package.json +++ b/packages/helpers/package.json @@ -27,6 +27,7 @@ "@biscuitland/core": "^2.0.5" }, "devDependencies": { + "@types/node": "^18.7.14", "tsup": "^6.1.3" }, "license": "Apache-2.0", diff --git a/packages/helpers/src/builders/components/InputTextBuilder.ts b/packages/helpers/src/builders/components/InputTextBuilder.ts index 9dd9757..fd61c7e 100644 --- a/packages/helpers/src/builders/components/InputTextBuilder.ts +++ b/packages/helpers/src/builders/components/InputTextBuilder.ts @@ -1,10 +1,12 @@ -import { DiscordInputTextComponent, MessageComponentTypes, TextStyles } from '@biscuitland/api-types'; +import type { DiscordInputTextComponent, TextStyles } from '@biscuitland/api-types'; +import { MessageComponentTypes } from '@biscuitland/api-types'; export class InputTextBuilder { constructor() { this.#data = {} as DiscordInputTextComponent; this.type = MessageComponentTypes.InputText; } + #data: DiscordInputTextComponent; type: MessageComponentTypes.InputText; @@ -43,6 +45,7 @@ export class InputTextBuilder { this.#data.required = required; return this; } + toJSON(): DiscordInputTextComponent { return { ...this.#data, type: this.type }; } diff --git a/packages/helpers/src/builders/components/MessageActionRowBuilder.ts b/packages/helpers/src/builders/components/MessageActionRowBuilder.ts index d20d281..261b003 100644 --- a/packages/helpers/src/builders/components/MessageActionRowBuilder.ts +++ b/packages/helpers/src/builders/components/MessageActionRowBuilder.ts @@ -1,4 +1,5 @@ -import { DiscordActionRow, MessageComponentTypes } from '@biscuitland/api-types'; +import type { DiscordActionRow } from '@biscuitland/api-types'; +import { MessageComponentTypes } from '@biscuitland/api-types'; import type { ComponentBuilder } from '../../../../core/src/utils/util'; export class ActionRowBuilder { @@ -6,6 +7,7 @@ export class ActionRowBuilder { this.components = [] as T[]; this.type = MessageComponentTypes.ActionRow; } + components: T[]; type: MessageComponentTypes.ActionRow; @@ -27,7 +29,7 @@ export class ActionRowBuilder { return { type: this.type, // @ts-ignore: socram fix this - components: this.components.map((c) => c.toJSON()) as DiscordActionRow['components'], + components: this.components.map(c => c.toJSON()) as DiscordActionRow['components'], }; } } diff --git a/packages/helpers/src/builders/components/MessageButtonBuilder.ts b/packages/helpers/src/builders/components/MessageButtonBuilder.ts index db7de46..124f608 100644 --- a/packages/helpers/src/builders/components/MessageButtonBuilder.ts +++ b/packages/helpers/src/builders/components/MessageButtonBuilder.ts @@ -1,4 +1,5 @@ -import { ButtonStyles, DiscordButtonComponent, MessageComponentTypes } from '@biscuitland/api-types'; +import type { ButtonStyles, DiscordButtonComponent } from '@biscuitland/api-types'; +import { MessageComponentTypes } from '@biscuitland/api-types'; import type { ComponentEmoji } from '../../../../core/src/utils/util'; export class ButtonBuilder { @@ -6,6 +7,7 @@ export class ButtonBuilder { this.#data = {} as DiscordButtonComponent; this.type = MessageComponentTypes.Button; } + #data: DiscordButtonComponent; type: MessageComponentTypes.Button; diff --git a/packages/helpers/src/builders/components/MessageSelectMenuBuilder.ts b/packages/helpers/src/builders/components/MessageSelectMenuBuilder.ts index a687c3d..e359cca 100644 --- a/packages/helpers/src/builders/components/MessageSelectMenuBuilder.ts +++ b/packages/helpers/src/builders/components/MessageSelectMenuBuilder.ts @@ -1,11 +1,12 @@ import type { DiscordSelectOption, DiscordSelectMenuComponent, } from '@biscuitland/api-types'; import type { ComponentEmoji } from '../../../../core/src/utils/util'; -import { MessageComponentTypes } from '@biscuitland/api-types'; +import { MessageComponentTypes } from '@biscuitland/api-types'; export class SelectMenuOptionBuilder { constructor() { this.#data = {} as DiscordSelectOption; } + #data: DiscordSelectOption; setLabel(label: string): SelectMenuOptionBuilder { @@ -44,6 +45,7 @@ export class SelectMenuBuilder { this.type = MessageComponentTypes.SelectMenu; this.options = []; } + #data: DiscordSelectMenuComponent; type: MessageComponentTypes.SelectMenu; options: SelectMenuOptionBuilder[]; @@ -86,6 +88,6 @@ export class SelectMenuBuilder { } toJSON(): DiscordSelectMenuComponent { - return { ...this.#data, type: this.type, options: this.options.map((option) => option.toJSON()) }; + return { ...this.#data, type: this.type, options: this.options.map(option => option.toJSON()) }; } } diff --git a/packages/helpers/src/builders/embeds/embed-builder.ts b/packages/helpers/src/builders/embeds/embed-builder.ts index e6acd33..67a509a 100644 --- a/packages/helpers/src/builders/embeds/embed-builder.ts +++ b/packages/helpers/src/builders/embeds/embed-builder.ts @@ -36,7 +36,7 @@ export class EmbedBuilder { #data: Embed; constructor(data: Embed = {}) { this.#data = data; - if (!this.#data.fields) this.#data.fields = []; + if (!this.#data.fields) { this.#data.fields = []; } } setAuthor(author: EmbedAuthor): EmbedBuilder { @@ -86,7 +86,7 @@ export class EmbedBuilder { setTitle(title: string, url?: string): EmbedBuilder { this.#data.title = title; - if (url) this.setUrl(url); + if (url) { this.setUrl(url); } return this; } diff --git a/packages/helpers/src/builders/slash/ApplicationCommand.ts b/packages/helpers/src/builders/slash/ApplicationCommand.ts index 22ca3a8..fde507f 100644 --- a/packages/helpers/src/builders/slash/ApplicationCommand.ts +++ b/packages/helpers/src/builders/slash/ApplicationCommand.ts @@ -1,20 +1,21 @@ -import { +import type { Localization, - PermissionStrings, + PermissionStrings } from '@biscuitland/api-types'; +import { ApplicationCommandTypes } from '@biscuitland/api-types'; -import { CreateApplicationCommand } from '@biscuitland/core'; +import type { CreateApplicationCommand } from '@biscuitland/core'; import { OptionBased } from './ApplicationCommandOption'; export abstract class ApplicationCommandBuilder { constructor( type: ApplicationCommandTypes = ApplicationCommandTypes.ChatInput, - name: string = '', - description: string = '', + name = '', + description = '', defaultMemberPermissions?: PermissionStrings[], nameLocalizations?: Localization, descriptionLocalizations?: Localization, - dmPermission: boolean = true + dmPermission = true ) { this.type = type; this.name = name; @@ -24,6 +25,7 @@ export abstract class ApplicationCommandBuilder { this.descriptionLocalizations = descriptionLocalizations; this.dmPermission = dmPermission; } + type: ApplicationCommandTypes; name: string; description: string; @@ -79,7 +81,7 @@ export class MessageApplicationCommandBuilder { } toJSON(): MessageApplicationCommandBuilderJSON { - if (!this.name) throw new TypeError("Propety 'name' is required"); + if (!this.name) { throw new TypeError("Propety 'name' is required"); } return { type: ApplicationCommandTypes.Message, @@ -92,8 +94,8 @@ export class ChatInputApplicationCommandBuilder extends ApplicationCommandBuilde type: ApplicationCommandTypes.ChatInput = ApplicationCommandTypes.ChatInput; toJSON(): CreateApplicationCommand { - if (!this.type) throw new TypeError("Propety 'type' is required"); - if (!this.name) throw new TypeError("Propety 'name' is required"); + if (!this.type) { throw new TypeError("Propety 'type' is required"); } + if (!this.name) { throw new TypeError("Propety 'name' is required"); } if (!this.description) { throw new TypeError("Propety 'description' is required"); } diff --git a/packages/helpers/src/builders/slash/ApplicationCommandOption.ts b/packages/helpers/src/builders/slash/ApplicationCommandOption.ts index 1d84dd2..eb4e418 100644 --- a/packages/helpers/src/builders/slash/ApplicationCommandOption.ts +++ b/packages/helpers/src/builders/slash/ApplicationCommandOption.ts @@ -1,5 +1,6 @@ -import { ChannelTypes, Localization, Locales, ApplicationCommandOptionTypes } from '@biscuitland/api-types'; -import { ApplicationCommandOptionChoice } from '@biscuitland/core'; +import type { ChannelTypes, Localization, Locales } from '@biscuitland/api-types'; +import { ApplicationCommandOptionTypes } from '@biscuitland/api-types'; +import type { ApplicationCommandOptionChoice } from '@biscuitland/core'; export type Localizations = typeof Locales[keyof typeof Locales] & string; @@ -19,8 +20,8 @@ export class ChoiceBuilder { } toJSON(): ApplicationCommandOptionChoice { - if (!this.name) throw new TypeError('Property \'name\' is required'); - if (!this.value) throw new TypeError('Property \'value\' is required'); + if (!this.name) { throw new TypeError('Property \'name\' is required'); } + if (!this.value) { throw new TypeError('Property \'value\' is required'); } return { name: this.name, @@ -67,8 +68,8 @@ export class OptionBuilder { } toJSON(): ApplicationCommandOption { - if (!this.type) throw new TypeError('Property \'type\' is required'); - if (!this.name) throw new TypeError('Property \'name\' is required'); + if (!this.type) { throw new TypeError('Property \'type\' is required'); } + if (!this.name) { throw new TypeError('Property \'name\' is required'); } if (!this.description) { throw new TypeError('Property \'description\' is required'); } @@ -120,7 +121,7 @@ export class OptionBuilderLimitedValues extends OptionBuilder { override toJSON(): ApplicationCommandOption { return { ...super.toJSON(), - choices: this.choices?.map((c) => c.toJSON()) ?? [], + choices: this.choices?.map(c => c.toJSON()) ?? [], min_value: this.minValue, max_value: this.maxValue, }; @@ -151,7 +152,7 @@ export class OptionBuilderString extends OptionBuilder { override toJSON(): ApplicationCommandOption { return { ...super.toJSON(), - choices: this.choices?.map((c) => c.toJSON()) ?? [], + choices: this.choices?.map(c => c.toJSON()) ?? [], }; } } @@ -271,8 +272,9 @@ export class OptionBased { return this.addOption(fn, ApplicationCommandOptionTypes.Mentionable); } - static applyTo(klass: Function, ignore: Array = []): void { - const methods: Array = [ + // eslint-disable-next-line @typescript-eslint/ban-types + static applyTo(klass: Function, ignore: (keyof OptionBased)[] = []): void { + const methods: (keyof OptionBased)[] = [ 'addOption', 'addNestedOption', 'addStringOption', @@ -288,7 +290,7 @@ export class OptionBased { ]; for (const method of methods) { - if (ignore.includes(method)) continue; + if (ignore.includes(method)) { continue; } klass.prototype[method] = OptionBased.prototype[method]; } @@ -308,8 +310,8 @@ export class OptionBuilderNested extends OptionBuilder { } override toJSON(): ApplicationCommandOption { - if (!this.type) throw new TypeError('Property \'type\' is required'); - if (!this.name) throw new TypeError('Property \'name\' is required'); + if (!this.type) { throw new TypeError('Property \'type\' is required'); } + if (!this.name) { throw new TypeError('Property \'name\' is required'); } if (!this.description) { throw new TypeError('Property \'description\' is required'); } @@ -318,7 +320,7 @@ export class OptionBuilderNested extends OptionBuilder { type: this.type, name: this.name, description: this.description, - options: this.options?.map((o) => o.toJSON()) ?? [], + options: this.options?.map(o => o.toJSON()) ?? [], required: this.required ? true : false, }; } diff --git a/packages/helpers/src/collectors.ts b/packages/helpers/src/collectors.ts index 12fd520..f003fdf 100644 --- a/packages/helpers/src/collectors.ts +++ b/packages/helpers/src/collectors.ts @@ -1,6 +1,7 @@ import type { Session, Events } from '@biscuitland/core'; import { EventEmitter } from 'node:events'; + export interface CollectorOptions { event: E; filter?(...args: Parameters): unknown; @@ -12,16 +13,15 @@ export interface CollectorOptions { export class Collector extends EventEmitter { collected = new Set[0]>(); ended = false; + private timeout: NodeJS.Timeout; constructor(readonly session: Session, public options: CollectorOptions) { super(); - if (!('filter' in this.options)) - this.options.filter = (() => true); + if (!('filter' in this.options)) { this.options.filter = (() => true); } - if (!('max' in this.options)) - this.options.max = -1; + if (!('max' in this.options)) { this.options.max = -1; } this.session.events.setMaxListeners(this.session.events.getMaxListeners() + 1); @@ -41,12 +41,11 @@ export class Collector extends EventEmitter { this.timeout = setTimeout(() => this.stop('time'), this.options.idle); } - if (this.collected.size >= this.options.max!) - this.stop('max'); + if (this.collected.size >= this.options.max!) { this.stop('max'); } } stop(reason?: string) { - if (this.ended) return; + if (this.ended) { return; } clearTimeout(this.timeout);