From d1f952be270a0798632995216c7e4b038e02dd7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Susa=C3=B1a?= Date: Fri, 2 Sep 2022 09:44:11 -0400 Subject: [PATCH] fix: Eslint and packages sizes (#104) which fixes #102 * chore: disabled source map * linter --- .eslintrc.yml | 2 +- packages/api-types/tsup.config.ts | 2 +- packages/cache/tsup.config.ts | 2 +- packages/core/src/adapters/event-adapter.ts | 3 +- packages/core/src/adapters/events.ts | 7 +- packages/core/src/snowflakes.ts | 1 + packages/core/src/structures/automod.ts | 22 ++--- packages/core/src/structures/channels.ts | 83 ++++++++++--------- packages/core/src/structures/components.ts | 4 +- packages/core/src/structures/embed.ts | 1 + packages/core/src/structures/emojis.ts | 10 ++- packages/core/src/structures/guilds.ts | 27 +++--- packages/core/src/structures/interactions.ts | 28 ++----- packages/core/src/structures/invite.ts | 3 +- packages/core/src/structures/members.ts | 2 +- .../core/src/structures/message-reaction.ts | 3 +- packages/core/src/structures/message.ts | 3 +- packages/core/src/structures/presence.ts | 3 +- .../structures/special/interaction-options.ts | 4 +- .../src/structures/special/permissions.ts | 8 +- packages/core/src/utils/calculate-shard.ts | 2 +- packages/core/src/utils/url-to-base-64.ts | 2 +- packages/core/src/utils/util.ts | 11 +-- packages/core/tsup.config.ts | 2 +- packages/helpers/tsup.config.ts | 2 +- packages/rest/tsup.config.ts | 2 +- packages/ws/tsup.config.ts | 2 +- 27 files changed, 116 insertions(+), 125 deletions(-) diff --git a/.eslintrc.yml b/.eslintrc.yml index 51cdfc8..06e5891 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -57,7 +57,7 @@ rules: '@typescript-eslint/no-misused-new': 'error' '@typescript-eslint/no-namespace': 'error' '@typescript-eslint/no-this-alias': 'error' - '@typescript-eslint/no-use-before-define': 'error' + '@typescript-eslint/no-use-before-define': 'off' '@typescript-eslint/no-var-requires': 'error' '@typescript-eslint/triple-slash-reference': 'error' '@typescript-eslint/type-annotation-spacing': 'error' diff --git a/packages/api-types/tsup.config.ts b/packages/api-types/tsup.config.ts index 6eebbb4..2e8c9eb 100644 --- a/packages/api-types/tsup.config.ts +++ b/packages/api-types/tsup.config.ts @@ -8,5 +8,5 @@ export default defineConfig({ entry: ['src/index.ts'], format: ['cjs', 'esm'], minify: isProduction, - sourcemap: true, + sourcemap: false, }); diff --git a/packages/cache/tsup.config.ts b/packages/cache/tsup.config.ts index 6eebbb4..2e8c9eb 100644 --- a/packages/cache/tsup.config.ts +++ b/packages/cache/tsup.config.ts @@ -8,5 +8,5 @@ export default defineConfig({ entry: ['src/index.ts'], format: ['cjs', 'esm'], minify: isProduction, - sourcemap: true, + sourcemap: false, }); diff --git a/packages/core/src/adapters/event-adapter.ts b/packages/core/src/adapters/event-adapter.ts index e132f89..008a0a3 100644 --- a/packages/core/src/adapters/event-adapter.ts +++ b/packages/core/src/adapters/event-adapter.ts @@ -1,6 +1,7 @@ +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/core/src/adapters/events.ts b/packages/core/src/adapters/events.ts index 5754913..f97b990 100644 --- a/packages/core/src/adapters/events.ts +++ b/packages/core/src/adapters/events.ts @@ -1,4 +1,3 @@ -/* eslint-disable no-mixed-spaces-and-tabs */ import type { DiscordAutoModerationActionExecution, DiscordAutoModerationRule, @@ -277,7 +276,7 @@ export const TYPING_START: RawHandler = ( session, payload.member as DiscordMemberWithUser, payload.guild_id - ) + ) : undefined, }); }; @@ -664,7 +663,7 @@ export const GUILD_SCHEDULED_EVENT_USER_REMOVE: RawHandler< }; export const VOICE_STATE_UPDATE: RawHandler = (session, _shardId, payload) => { - if (!payload.guild_id) return; + if (!payload.guild_id) { return; } session.events.emit('voiceStateUpdate', payload); }; @@ -828,6 +827,6 @@ export interface Events { debug: Handler<[string]>; voiceStateUpdate: Handler<[DiscordVoiceState]>; voiceServerUpdate: Handler< - [{ token: string, guildId: Snowflake, endpoint?: string }] + [{ token: string; guildId: Snowflake; endpoint?: string }] >; } diff --git a/packages/core/src/snowflakes.ts b/packages/core/src/snowflakes.ts index bed3406..1b2a918 100644 --- a/packages/core/src/snowflakes.ts +++ b/packages/core/src/snowflakes.ts @@ -5,6 +5,7 @@ export type Snowflake = string; export const DiscordEpoch = 14200704e5; /** utilities for Snowflakes */ +// eslint-disable-next-line @typescript-eslint/no-redeclare export const Snowflake = { snowflakeToTimestamp(id: Snowflake): number { return (Number(id) >> 22) + DiscordEpoch; diff --git a/packages/core/src/structures/automod.ts b/packages/core/src/structures/automod.ts index bc169ef..63dd0c1 100644 --- a/packages/core/src/structures/automod.ts +++ b/packages/core/src/structures/automod.ts @@ -1,13 +1,14 @@ -import { Model } from './base'; -import { Session } from '../biscuit'; -import { Snowflake } from '../snowflakes'; -import { +import type { Model } from './base'; +import type { Session } from '../biscuit'; +import type { Snowflake } from '../snowflakes'; +import type { AutoModerationActionType, AutoModerationEventTypes, AutoModerationTriggerTypes, DiscordAutoModerationRule, DiscordAutoModerationRuleTriggerMetadataPresets, - DiscordAutoModerationActionExecution, + DiscordAutoModerationActionExecution } from '@biscuitland/api-types'; +import { AUTO_MODERATION_RULES } from '@biscuitland/api-types'; @@ -27,7 +28,7 @@ export interface AutoModerationAction { metadata: ActionMetadata; } -/**@link https://discord.com/developers/docs/resources/auto-moderation#create-auto-moderation-rule-json-params */ +/** @link https://discord.com/developers/docs/resources/auto-moderation#create-auto-moderation-rule-json-params */ export interface CreateAutoModerationRule { name: string; eventType: 1; @@ -86,10 +87,11 @@ export class AutoModerationRule implements Model { const request = await this.session.rest.get< DiscordAutoModerationRule | DiscordAutoModerationRule[] >(AUTO_MODERATION_RULES(this.guildId, ruleId)); - if (Array.isArray(request)) - return request.map( + if (Array.isArray(request)) { + return request.map( amr => new AutoModerationRule(this.session, amr) ); +} return new AutoModerationRule(this.session, request); } @@ -114,7 +116,7 @@ export class AutoModerationRule implements Model { } } ) - ) + ) : undefined, enabled: !!options.enabled, exempt_roles: options.exemptRoles, @@ -147,7 +149,7 @@ export class AutoModerationRule implements Model { } } ) - ) + ) : undefined, enabled: !!options.enabled, exempt_roles: options.exemptRoles, diff --git a/packages/core/src/structures/channels.ts b/packages/core/src/structures/channels.ts index 2ee9567..6c2eb38 100644 --- a/packages/core/src/structures/channels.ts +++ b/packages/core/src/structures/channels.ts @@ -10,36 +10,37 @@ import { urlToBase64 } from '../utils/url-to-base-64'; /** Classes and routes */ import { - DiscordChannel, - DiscordInvite, - DiscordInviteMetadata, - DiscordListArchivedThreads, - DiscordMessage, - DiscordOverwrite, - DiscordThreadMember, - DiscordWebhook, - TargetTypes, - VideoQualityModes, - GetReactions, - GetMessagesOptions, - ListArchivedThreads, - USER_DM} from '@biscuitland/api-types'; -import { - CHANNEL, - CHANNEL_PINS, - CHANNEL_INVITES, - CHANNEL_TYPING, - CHANNEL_MESSAGES, - CHANNEL_WEBHOOKS, - THREAD_USER, - THREAD_ME, - THREAD_MEMBERS, - THREAD_START_PRIVATE, - THREAD_ARCHIVED_PUBLIC, - THREAD_ARCHIVED_PRIVATE_JOINED, - THREAD_START_PUBLIC, - ChannelTypes, - GatewayOpcodes as _GatewayOpcodes + USER_DM, + CHANNEL, + CHANNEL_PINS, + CHANNEL_INVITES, + CHANNEL_TYPING, + CHANNEL_MESSAGES, + CHANNEL_WEBHOOKS, + THREAD_USER, + THREAD_ME, + THREAD_MEMBERS, + THREAD_START_PRIVATE, + THREAD_ARCHIVED_PUBLIC, + THREAD_ARCHIVED_PRIVATE_JOINED, + THREAD_START_PUBLIC, + ChannelTypes +} from '@biscuitland/api-types'; +import type { + DiscordChannel, + DiscordInvite, + DiscordInviteMetadata, + DiscordListArchivedThreads, + DiscordMessage, + DiscordOverwrite, + DiscordThreadMember, + DiscordWebhook, + TargetTypes, + VideoQualityModes, + GetReactions, + GetMessagesOptions, + ListArchivedThreads, + GatewayOpcodes as _GatewayOpcodes } from '@biscuitland/api-types'; import type { CreateMessage, EditMessage, EmojiResolvable } from './message'; @@ -256,6 +257,7 @@ export class TextChannel { /** * Mixin */ + // eslint-disable-next-line @typescript-eslint/ban-types static applyTo(klass: Function, ignore: (keyof TextChannel)[] = []): void { const methods: (keyof TextChannel)[] = [ 'fetchPins', @@ -322,6 +324,7 @@ export class TextChannel { * @returns The messages */ async fetchMessages(options?: GetMessagesOptions): Promise { + // eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain if (options?.limit! > 100) { throw Error('Values must be between 0-100'); } const messages = await this.session.rest.get( CHANNEL_MESSAGES(this.id, options), @@ -633,7 +636,7 @@ export class GuildChannel extends BaseChannel implements Model { break; } - const { threads, members, has_more } = await this.session.rest.get( + const { threads, members, has_more: hasMore } = await this.session.rest.get( func(this.id, options), ); @@ -644,7 +647,7 @@ export class GuildChannel extends BaseChannel implements Model { members: Object.fromEntries( members.map(threadMember => [threadMember.id, new ThreadMember(this.session, threadMember)]), ) as Record, - hasMore: has_more, + hasMore, }; } @@ -671,7 +674,7 @@ export class GuildChannel extends BaseChannel implements Model { * @param overwrites - The overwrites to add to the channel. */ async setPermissions(overwrites: PermissionsOverwrites[]): Promise { - return this.edit({ permissionOverwrites: overwrites } as EditGuildChannelOptions) + return this.edit({ permissionOverwrites: overwrites } as EditGuildChannelOptions); } } @@ -715,7 +718,7 @@ export abstract class BaseVoiceChannel extends GuildChannel { export class DMChannel extends BaseChannel implements Model { constructor(session: Session, data: DiscordChannel) { super(session, data); - + if (data.owner_id && data.recipents) { this.user = new User(session, data.recipents.find(user => user.id === data.owner_id)!); } else { @@ -748,13 +751,13 @@ export class DMChannel extends BaseChannel implements Model { } async open(userId: Snowflake): Promise { - const channel = await this.session.rest.post(USER_DM(), { recipient_id: userId}); + const channel = await this.session.rest.post(USER_DM(), { recipient_id: userId }); return new DMChannel(this.session, channel); } } -export interface DMChannel extends Omit, Omit {} +export interface DMChannel extends Omit, Omit { } TextChannel.applyTo(DMChannel); @@ -768,7 +771,7 @@ export class VoiceChannel extends BaseVoiceChannel { override type: ChannelTypes.GuildVoice; } -export interface VoiceChannel extends TextChannel, BaseVoiceChannel {} +export interface VoiceChannel extends TextChannel, BaseVoiceChannel { } TextChannel.applyTo(VoiceChannel); @@ -794,7 +797,7 @@ export class NewsChannel extends GuildChannel { TextChannel.applyTo(NewsChannel); -export interface NewsChannel extends TextChannel, GuildChannel {} +export interface NewsChannel extends TextChannel, GuildChannel { } /** StageChannel */ export class StageChannel extends BaseVoiceChannel { @@ -865,7 +868,7 @@ export class ThreadChannel extends GuildChannel implements Model { } } -export interface ThreadChannel extends Omit, Omit {} +export interface ThreadChannel extends Omit, Omit { } TextChannel.applyTo(ThreadChannel); @@ -878,7 +881,7 @@ export class GuildTextChannel extends GuildChannel { override type: ChannelTypes.GuildText; } -export interface GuildTextChannel extends GuildChannel, TextChannel {} +export interface GuildTextChannel extends GuildChannel, TextChannel { } TextChannel.applyTo(GuildTextChannel); diff --git a/packages/core/src/structures/components.ts b/packages/core/src/structures/components.ts index 4136a35..12bb62a 100644 --- a/packages/core/src/structures/components.ts +++ b/packages/core/src/structures/components.ts @@ -158,12 +158,12 @@ export class SelectMenu extends BaseComponent implements SelectMenuComponent { this.type = data.type as MessageComponentTypes.SelectMenu; this.customId = data.custom_id!; this.options = data.options!.map(option => { - return { + return { label: option.label, description: option.description, emoji: option.emoji ? new Emoji(session, option.emoji) : undefined, value: option.value, - }; + } as SelectMenuOption; }); this.placeholder = data.placeholder; this.minValues = data.min_values; diff --git a/packages/core/src/structures/embed.ts b/packages/core/src/structures/embed.ts index dbf6c74..bb78d4e 100644 --- a/packages/core/src/structures/embed.ts +++ b/packages/core/src/structures/embed.ts @@ -151,4 +151,5 @@ export function NewEmbedR(data: DiscordEmbed): Embed { }; } +// eslint-disable-next-line @typescript-eslint/naming-convention export const embed_ = NewEmbedR; diff --git a/packages/core/src/structures/emojis.ts b/packages/core/src/structures/emojis.ts index 2bf6f05..de6b0d1 100644 --- a/packages/core/src/structures/emojis.ts +++ b/packages/core/src/structures/emojis.ts @@ -1,9 +1,11 @@ import type { Session } from '../biscuit'; import type { Model } from './base'; import type { Snowflake } from '../snowflakes'; -import { Guild, ModifyGuildEmoji} from './guilds'; +import type { ModifyGuildEmoji } from './guilds'; +import { Guild } from './guilds'; import { User } from './user'; -import { EMOJI_URL, DiscordEmoji, GUILD_EMOJIS } from '@biscuitland/api-types'; +import type { DiscordEmoji } from '@biscuitland/api-types'; +import { EMOJI_URL, GUILD_EMOJIS } from '@biscuitland/api-types'; export class Emoji implements Partial { constructor(session: Session, data: DiscordEmoji) { @@ -65,7 +67,7 @@ export class GuildEmoji extends Emoji implements Model { async fetchAuthor(): Promise { const emoji = await this.session.rest.get(GUILD_EMOJIS(this.guildId, this.id)); - if (emoji.user) return new User(this.session, emoji.user); + if (emoji.user) { return new User(this.session, emoji.user); } return null; } @@ -78,6 +80,6 @@ export class GuildEmoji extends Emoji implements Model { } toString(): string { - return `<${this.animated ? 'a' : ''}:${this.name}:${this.id}>` + return `<${this.animated ? 'a' : ''}:${this.name}:${this.id}>`; } } diff --git a/packages/core/src/structures/guilds.ts b/packages/core/src/structures/guilds.ts index 9cc709c..9c4375a 100644 --- a/packages/core/src/structures/guilds.ts +++ b/packages/core/src/structures/guilds.ts @@ -1,6 +1,7 @@ import type { Model } from './base'; import type { Session } from '../biscuit'; -import { +import type { + PremiumTiers, ChannelTypes, DefaultMessageNotificationLevels, DiscordBan, @@ -27,18 +28,14 @@ import { GetInvite, ListGuildMembers, GetAuditLogs, - GUILD_AUDIT_LOGS, DiscordAuditLog, AuditLogEvents, - DiscordAuditLogChange, -} from '@biscuitland/api-types'; -import type { ImageFormat, ImageSize } from '../utils/util'; -import { GuildFeatures, PremiumTiers } from '@biscuitland/api-types'; -import { Snowflake } from '../snowflakes'; -import { Util } from '../utils/util'; + DiscordAuditLogChange } from '@biscuitland/api-types'; import { + GUILD_AUDIT_LOGS, INVITE, GUILD_BANNER, + GuildFeatures, GUILD_ICON, GUILD_SPLASH, USER_NICK, @@ -61,9 +58,12 @@ import { GUILD_WIDGET, USER_GUILDS, CHANNEL, - GUILD_CHANNELS, -} from '@biscuitland/api-types'; -import { ChannelFactory, GuildChannel, ReturnThreadsArchive, ThreadChannel, ChannelInGuild } from './channels'; + GUILD_CHANNELS } from '@biscuitland/api-types'; +import type { ImageFormat, ImageSize } from '../utils/util'; +import { Snowflake } from '../snowflakes'; +import { Util } from '../utils/util'; +import type { ReturnThreadsArchive, ChannelInGuild } from './channels'; +import { ChannelFactory, GuildChannel, ThreadChannel } from './channels'; import { Member, ThreadMember } from './members'; import { Role } from './role'; import { GuildEmoji } from './emojis'; @@ -311,6 +311,7 @@ export class GuildPreview implements Model { this.approximatePresenceCount = data.approximate_presence_count; this.stickers = data.stickers.map(x => new Sticker(this.session, x)); } + session: Session; /** guild id */ id: Snowflake; @@ -1326,7 +1327,7 @@ export class Guild extends BaseGuild implements Model { threads: auditLog.threads.map(x => ChannelFactory.fromGuildChannel(this.session, x) as ThreadChannel), users: auditLog.users.map(x => new User(this.session, x)), webhooks: auditLog.webhooks.map(x => new Webhook(this.session, x)), - } + }; } async fetchOwner(): Promise { @@ -1348,6 +1349,6 @@ export class Guild extends BaseGuild implements Model { GUILD_MEMBERS(this.id, options) ); - return members.map((member) => new Member(this.session, member, this.id)); + return members.map(member => new Member(this.session, member, this.id)); } } diff --git a/packages/core/src/structures/interactions.ts b/packages/core/src/structures/interactions.ts index f9e2586..24b3550 100644 --- a/packages/core/src/structures/interactions.ts +++ b/packages/core/src/structures/interactions.ts @@ -7,6 +7,7 @@ import type { DiscordMessageComponents, DiscordMemberWithUser, DiscordMessageInteraction, + Locales } from '@biscuitland/api-types'; import type { CreateMessage } from './message'; import type { MessageFlags } from '../utils/util'; @@ -15,7 +16,11 @@ import { InteractionResponseTypes, InteractionTypes, MessageComponentTypes, + INTERACTION_ID_TOKEN, + WEBHOOK_MESSAGE, + WEBHOOK_MESSAGE_ORIGINAL } from '@biscuitland/api-types'; + import { Role } from './role'; import { Attachment } from './attachment'; import { Snowflake } from '../snowflakes'; @@ -25,11 +30,6 @@ import { Message } from './message'; import { Permissions } from './special/permissions'; import { Webhook } from './webhook'; import { InteractionOptions } from './special/interaction-options'; -import { - INTERACTION_ID_TOKEN, - WEBHOOK_MESSAGE, - WEBHOOK_MESSAGE_ORIGINAL, -} from '@biscuitland/api-types'; export type InteractionResponseWith = { with: InteractionApplicationCommandCallbackData; @@ -80,6 +80,8 @@ export abstract class BaseInteraction implements Model { this.applicationId = data.application_id; this.version = data.version; + this.locale = data.locale as Locales; + const perms = data.app_permissions; if (perms) { @@ -113,7 +115,7 @@ export abstract class BaseInteraction implements Model { appPermissions?: Permissions; // must be implemented - abstract locale?: string; + locale: Locales; // readonly property according to docs readonly version: 1; @@ -220,7 +222,6 @@ export abstract class BaseInteraction implements Model { { id: this.session.applicationId, token: this.token, - session: this.session, }, messageId, options @@ -237,7 +238,6 @@ export abstract class BaseInteraction implements Model { { id: this.session.applicationId, token: this.token, - session: this.session, }, messageId, threadId @@ -251,8 +251,8 @@ export abstract class BaseInteraction implements Model { const message = await Webhook.prototype.fetchMessage.call( { id: this.session.applicationId, + session: this.session, token: this.token, - session: this.session, }, messageId, threadId @@ -339,7 +339,6 @@ export class AutoCompleteInteraction extends BaseInteraction implements Model { this.options = new InteractionOptions( data.data!.options ?? [] ); - this.locale = data.locale; } override type: InteractionTypes.ApplicationCommandAutocomplete; @@ -348,7 +347,6 @@ export class AutoCompleteInteraction extends BaseInteraction implements Model { commandType: ApplicationCommandTypes; commandGuildId?: Snowflake; options: InteractionOptions; - override locale?: string; async respondWithChoices( choices: ApplicationCommandOptionChoice[] @@ -434,8 +432,6 @@ export class CommandInteraction extends BaseInteraction implements Model { this.resolved.messages.set(id, new Message(session, m)); } } - - this.locale = data.locale; } override type: InteractionTypes.ApplicationCommand; @@ -445,7 +441,6 @@ export class CommandInteraction extends BaseInteraction implements Model { commandGuildId?: Snowflake; resolved: CommandInteractionDataResolved; options: InteractionOptions; - override locale?: string; } export type ModalInMessage = ModalSubmitInteraction & { @@ -468,8 +463,6 @@ export class ModalSubmitInteraction extends BaseInteraction implements Model { if (data.message) { this.message = new Message(session, data.message); } - - this.locale = data.locale; } override type: InteractionTypes.MessageComponent; @@ -479,7 +472,6 @@ export class ModalSubmitInteraction extends BaseInteraction implements Model { values?: string[]; message?: Message; components; - override locale?: string; static transformComponent(component: DiscordMessageComponents[number]) { return { @@ -535,7 +527,6 @@ export class ComponentInteraction extends BaseInteraction implements Model { this.targetId = data.data!.target_id; this.values = data.data!.values; this.message = new Message(session, data.message!); - this.locale = data.locale; } override type: InteractionTypes.MessageComponent; @@ -544,7 +535,6 @@ export class ComponentInteraction extends BaseInteraction implements Model { targetId?: Snowflake; values?: string[]; message: Message; - override locale?: string; isButton(): boolean { return this.componentType === MessageComponentTypes.Button; diff --git a/packages/core/src/structures/invite.ts b/packages/core/src/structures/invite.ts index 6802ed4..03d0254 100644 --- a/packages/core/src/structures/invite.ts +++ b/packages/core/src/structures/invite.ts @@ -1,4 +1,3 @@ -/* eslint-disable no-mixed-spaces-and-tabs */ import type { Session } from '../biscuit'; import type { Snowflake } from '../snowflakes'; import type { @@ -121,7 +120,7 @@ export class Invite { ? new Application( session, data.target_application as DiscordApplication - ) + ) : undefined; this.targetType = data.target_type; diff --git a/packages/core/src/structures/members.ts b/packages/core/src/structures/members.ts index ecfb7cd..c13543d 100644 --- a/packages/core/src/structures/members.ts +++ b/packages/core/src/structures/members.ts @@ -188,7 +188,7 @@ export class Member implements Model { } else { url = USER_AVATAR( this.user.id, - this.avatarHash + this.avatarHash ); } diff --git a/packages/core/src/structures/message-reaction.ts b/packages/core/src/structures/message-reaction.ts index c45ec32..de3e87a 100644 --- a/packages/core/src/structures/message-reaction.ts +++ b/packages/core/src/structures/message-reaction.ts @@ -1,4 +1,3 @@ -/* eslint-disable no-mixed-spaces-and-tabs */ import type { Session } from '../biscuit'; import type { DiscordMemberWithUser, @@ -71,7 +70,7 @@ export function NewMessageReactionAdd( session, data.member as DiscordMemberWithUser, data.guild_id ?? '' - ) + ) : undefined, emoji: new Emoji(session, data.emoji), }; diff --git a/packages/core/src/structures/message.ts b/packages/core/src/structures/message.ts index 65cc0b5..74c06b4 100644 --- a/packages/core/src/structures/message.ts +++ b/packages/core/src/structures/message.ts @@ -15,7 +15,8 @@ import type { Channel } from './channels'; import type { Component } from './components'; import type { MessageInteraction } from './interactions'; import type { StickerItem } from './sticker'; -import { Embed, NewEmbed } from './embed'; +import type { Embed } from './embed'; +import { NewEmbed } from './embed'; import { MessageFlags } from '../utils/util'; import { Snowflake } from '../snowflakes'; import { ChannelFactory, ThreadChannel } from './channels'; diff --git a/packages/core/src/structures/presence.ts b/packages/core/src/structures/presence.ts index 5d4a5a9..2793644 100644 --- a/packages/core/src/structures/presence.ts +++ b/packages/core/src/structures/presence.ts @@ -1,4 +1,3 @@ -/* eslint-disable no-mixed-spaces-and-tabs */ import type { ActivityTypes, DiscordActivityButton, @@ -74,7 +73,7 @@ export class Presence { largeText: activity.assets.large_text, smallImage: activity.assets.small_image, smallText: activity.assets.small_text, - } + } : null, secrets: activity.secrets ? activity.secrets : undefined, instance: !!activity.instance, diff --git a/packages/core/src/structures/special/interaction-options.ts b/packages/core/src/structures/special/interaction-options.ts index 6637839..2708ca4 100644 --- a/packages/core/src/structures/special/interaction-options.ts +++ b/packages/core/src/structures/special/interaction-options.ts @@ -233,8 +233,8 @@ export class InteractionOptions { /** searches for the focused option */ getFocused(full: true): DiscordInteractionDataOption; - getFocused(full: false): DiscordInteractionDataOption["value"]; - getFocused(full: boolean = false) { + getFocused(full: false): DiscordInteractionDataOption['value']; + getFocused(full = false) { const focusedOption: DiscordInteractionDataOption | void = this.hoistedOptions.find(option => option.focused); diff --git a/packages/core/src/structures/special/permissions.ts b/packages/core/src/structures/special/permissions.ts index 717c18b..c7c9f7c 100644 --- a/packages/core/src/structures/special/permissions.ts +++ b/packages/core/src/structures/special/permissions.ts @@ -26,7 +26,7 @@ export class Permissions implements BitField { bitfield: bigint; /** Wheter to grant all other permissions to the administrator */ - __admin__: boolean = true; + __admin__ = true; constructor(bitfield: PermissionResolvable) { this.bitfield = Permissions.resolve(bitfield); @@ -39,7 +39,7 @@ export class Permissions implements BitField { } add(...bits: PermissionResolvable[]): this { - let reduced: bigint = 0n; + let reduced = 0n; for (const bit of bits) { reduced |= Permissions.resolve(bit); } @@ -48,7 +48,7 @@ export class Permissions implements BitField { } remove(...bits: PermissionResolvable[]): this { - let reduced: bigint = 0n; + let reduced = 0n; for (const bit of bits) { reduced |= Permissions.resolve(bit); } @@ -121,7 +121,7 @@ export class Permissions implements BitField { } toJSON(): { fields: string[] } { - const fields = Object.keys(Permissions.Flags).filter((bit) => typeof bit === 'number' && this.has(bit)); + const fields = Object.keys(Permissions.Flags).filter(bit => typeof bit === 'number' && this.has(bit)); return { fields }; } diff --git a/packages/core/src/utils/calculate-shard.ts b/packages/core/src/utils/calculate-shard.ts index ed28043..41fb290 100644 --- a/packages/core/src/utils/calculate-shard.ts +++ b/packages/core/src/utils/calculate-shard.ts @@ -1,5 +1,5 @@ export function calculateShardId(totalShards: number, guildId: bigint) { - if (totalShards === 1) return 0; + if (totalShards === 1) { return 0; } return Number((guildId >> 22n) % BigInt(totalShards - 1)); } diff --git a/packages/core/src/utils/url-to-base-64.ts b/packages/core/src/utils/url-to-base-64.ts index 310e0e5..d60d8d1 100644 --- a/packages/core/src/utils/url-to-base-64.ts +++ b/packages/core/src/utils/url-to-base-64.ts @@ -1,6 +1,6 @@ /** Converts a url to base 64. Useful for example, uploading/creating server emojis. */ export async function urlToBase64(url: string): Promise { - const buffer = await fetch(url).then((res) => res.arrayBuffer()); + const buffer = await fetch(url).then(res => res.arrayBuffer()); const imageStr = encode(buffer); const type = url.substring(url.lastIndexOf('.') + 1); return `data:image/${type};base64,${imageStr}`; diff --git a/packages/core/src/utils/util.ts b/packages/core/src/utils/util.ts index 9a49ed2..7dcb3aa 100644 --- a/packages/core/src/utils/util.ts +++ b/packages/core/src/utils/util.ts @@ -2,13 +2,6 @@ import type { SelectMenuBuilder, InputTextBuilder, ButtonBuilder } from '@biscui import type { Permissions } from '../structures/special/permissions'; import type { Snowflake } from '../snowflakes'; -/* - * Represents a session's cache - * */ -export interface SymCache { - readonly cache: symbol; -} - /* * @link https://discord.com/developers/docs/resources/channel#message-object-message-flags */ @@ -88,10 +81,10 @@ export abstract class Util { /** Removes the Bot before the token. */ static removeTokenPrefix(token?: string, type: 'GATEWAY' | 'REST' = 'REST'): string { // If no token is provided, throw an error - if (!token) throw new Error(`The ${type} was not given a token. Please provide a token and try again.`); + if (!token) { throw new Error(`The ${type} was not given a token. Please provide a token and try again.`); } // If the token does not have a prefix just return token - if (!token.startsWith('Bot ')) return token; + if (!token.startsWith('Bot ')) { return token; } // Remove the prefix and return only the token. return token.substring(token.indexOf(' ') + 1); diff --git a/packages/core/tsup.config.ts b/packages/core/tsup.config.ts index 6eebbb4..2e8c9eb 100644 --- a/packages/core/tsup.config.ts +++ b/packages/core/tsup.config.ts @@ -8,5 +8,5 @@ export default defineConfig({ entry: ['src/index.ts'], format: ['cjs', 'esm'], minify: isProduction, - sourcemap: true, + sourcemap: false, }); diff --git a/packages/helpers/tsup.config.ts b/packages/helpers/tsup.config.ts index 6eebbb4..2e8c9eb 100644 --- a/packages/helpers/tsup.config.ts +++ b/packages/helpers/tsup.config.ts @@ -8,5 +8,5 @@ export default defineConfig({ entry: ['src/index.ts'], format: ['cjs', 'esm'], minify: isProduction, - sourcemap: true, + sourcemap: false, }); diff --git a/packages/rest/tsup.config.ts b/packages/rest/tsup.config.ts index 6eebbb4..2e8c9eb 100644 --- a/packages/rest/tsup.config.ts +++ b/packages/rest/tsup.config.ts @@ -8,5 +8,5 @@ export default defineConfig({ entry: ['src/index.ts'], format: ['cjs', 'esm'], minify: isProduction, - sourcemap: true, + sourcemap: false, }); diff --git a/packages/ws/tsup.config.ts b/packages/ws/tsup.config.ts index 6eebbb4..2e8c9eb 100644 --- a/packages/ws/tsup.config.ts +++ b/packages/ws/tsup.config.ts @@ -8,5 +8,5 @@ export default defineConfig({ entry: ['src/index.ts'], format: ['cjs', 'esm'], minify: isProduction, - sourcemap: true, + sourcemap: false, });