fix: Eslint and packages sizes (#104) which fixes #102

* chore: disabled source map

* linter
This commit is contained in:
Marcos Susaña 2022-09-02 09:44:11 -04:00 committed by GitHub
parent b335172d1a
commit d1f952be27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 116 additions and 125 deletions

View File

@ -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'

View File

@ -8,5 +8,5 @@ export default defineConfig({
entry: ['src/index.ts'],
format: ['cjs', 'esm'],
minify: isProduction,
sourcemap: true,
sourcemap: false,
});

View File

@ -8,5 +8,5 @@ export default defineConfig({
entry: ['src/index.ts'],
format: ['cjs', 'esm'],
minify: isProduction,
sourcemap: true,
sourcemap: false,
});

View File

@ -1,6 +1,7 @@
import type { EventEmitter } from 'stream';
import type { Events } from './events';
export interface EventAdapter extends Omit<NodeJS.EventEmitter, "emit" | "on" | "off" | "once"> {
export interface EventAdapter extends Omit<EventEmitter, 'emit' | 'on' | 'off' | 'once'> {
options?: any;
emit<K extends keyof Events>(

View File

@ -1,4 +1,3 @@
/* eslint-disable no-mixed-spaces-and-tabs */
import type {
DiscordAutoModerationActionExecution,
DiscordAutoModerationRule,
@ -277,7 +276,7 @@ export const TYPING_START: RawHandler<DiscordTypingStart> = (
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<DiscordVoiceState> = (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 }]
>;
}

View File

@ -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;

View File

@ -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,

View File

@ -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<Message[] | []> {
// 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<DiscordMessage[]>(
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<DiscordListArchivedThreads>(
const { threads, members, has_more: hasMore } = await this.session.rest.get<DiscordListArchivedThreads>(
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<Snowflake, ThreadMember>,
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<Channel> {
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<DMChannel> {
const channel = await this.session.rest.post<DiscordChannel>(USER_DM(), { recipient_id: userId});
const channel = await this.session.rest.post<DiscordChannel>(USER_DM(), { recipient_id: userId });
return new DMChannel(this.session, channel);
}
}
export interface DMChannel extends Omit<TextChannel, 'type'>, Omit<BaseChannel, 'type'> {}
export interface DMChannel extends Omit<TextChannel, 'type'>, Omit<BaseChannel, 'type'> { }
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<GuildChannel, 'type'>, Omit<TextChannel, 'type'> {}
export interface ThreadChannel extends Omit<GuildChannel, 'type'>, Omit<TextChannel, 'type'> { }
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);

View File

@ -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 <SelectMenuOption>{
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;

View File

@ -151,4 +151,5 @@ export function NewEmbedR(data: DiscordEmbed): Embed {
};
}
// eslint-disable-next-line @typescript-eslint/naming-convention
export const embed_ = NewEmbedR;

View File

@ -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<Model> {
constructor(session: Session, data: DiscordEmoji) {
@ -65,7 +67,7 @@ export class GuildEmoji extends Emoji implements Model {
async fetchAuthor(): Promise<User | null> {
const emoji = await this.session.rest.get<DiscordEmoji>(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}>`;
}
}

View File

@ -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<Member> {
@ -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));
}
}

View File

@ -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;

View File

@ -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;

View File

@ -188,7 +188,7 @@ export class Member implements Model {
} else {
url = USER_AVATAR(
this.user.id,
this.avatarHash
this.avatarHash
);
}

View File

@ -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),
};

View File

@ -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';

View File

@ -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,

View File

@ -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);

View File

@ -26,7 +26,7 @@ export class Permissions implements BitField<bigint> {
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<bigint> {
}
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<bigint> {
}
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<bigint> {
}
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 };
}

View File

@ -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));
}

View File

@ -1,6 +1,6 @@
/** Converts a url to base 64. Useful for example, uploading/creating server emojis. */
export async function urlToBase64(url: string): Promise<string> {
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}`;

View File

@ -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);

View File

@ -8,5 +8,5 @@ export default defineConfig({
entry: ['src/index.ts'],
format: ['cjs', 'esm'],
minify: isProduction,
sourcemap: true,
sourcemap: false,
});

View File

@ -8,5 +8,5 @@ export default defineConfig({
entry: ['src/index.ts'],
format: ['cjs', 'esm'],
minify: isProduction,
sourcemap: true,
sourcemap: false,
});

View File

@ -8,5 +8,5 @@ export default defineConfig({
entry: ['src/index.ts'],
format: ['cjs', 'esm'],
minify: isProduction,
sourcemap: true,
sourcemap: false,
});

View File

@ -8,5 +8,5 @@ export default defineConfig({
entry: ['src/index.ts'],
format: ['cjs', 'esm'],
minify: isProduction,
sourcemap: true,
sourcemap: false,
});