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,
@ -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';
@ -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))
if (Array.isArray(request)) {
return request.map(
amr => new AutoModerationRule(this.session, amr)
);
}
return new AutoModerationRule(this.session, request);
}

View File

@ -10,21 +10,7 @@ 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 {
USER_DM,
CHANNEL,
CHANNEL_PINS,
CHANNEL_INVITES,
@ -38,7 +24,22 @@ import {
THREAD_ARCHIVED_PUBLIC,
THREAD_ARCHIVED_PRIVATE_JOINED,
THREAD_START_PUBLIC,
ChannelTypes,
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';
@ -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);
}
}

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,
token: this.token,
session: this.session,
token: this.token,
},
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 {

View File

@ -1,4 +1,3 @@
/* eslint-disable no-mixed-spaces-and-tabs */
import type { Session } from '../biscuit';
import type {
DiscordMemberWithUser,

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,

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