From 580206a6f501e6fbed52d47b61b1d2bcbba01052 Mon Sep 17 00:00:00 2001 From: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> Date: Thu, 16 Mar 2023 13:22:04 +0000 Subject: [PATCH] fix: linter --- packages/client/src/Client.ts | 2 ++ packages/client/src/RequestHandler.ts | 5 ++++- packages/client/src/gateway/Shard.ts | 4 +++- packages/client/src/typings.ts | 1 + packages/client/src/utils/BrowserWebSocket.ts | 1 + packages/client/src/utils/Bucket.ts | 1 + packages/eslint-config-discordeno/index.js | 1 + packages/gateway/src/Shard.ts | 11 ++++++----- packages/gateway/src/manager.ts | 11 ++++++----- packages/utils/src/logger.ts | 1 + packages/utils/src/utils.ts | 1 + website/docs/bigbot/step-3-gateway.md | 12 +++++++----- 12 files changed, 34 insertions(+), 17 deletions(-) diff --git a/packages/client/src/Client.ts b/packages/client/src/Client.ts index c14d4ff73..6a396ff80 100644 --- a/packages/client/src/Client.ts +++ b/packages/client/src/Client.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-confusing-void-expression */ /* eslint-disable no-prototype-builtins */ /* eslint-disable @typescript-eslint/restrict-template-expressions */ /* eslint-disable @typescript-eslint/restrict-plus-operands */ @@ -2300,6 +2301,7 @@ export class Client extends EventEmitter { // Typescript is not so good as we developers so we need this little utility function to help it out // Taken from https://fettblog.eu/typescript-hasownproperty/ /** TS save way to check if a property exists in an object */ + // eslint-disable-next-line @typescript-eslint/ban-types hasProperty(obj: T, prop: Y): obj is T & Record { return obj.hasOwnProperty(prop) } diff --git a/packages/client/src/RequestHandler.ts b/packages/client/src/RequestHandler.ts index 0dfdf5085..e8545af47 100644 --- a/packages/client/src/RequestHandler.ts +++ b/packages/client/src/RequestHandler.ts @@ -54,7 +54,10 @@ export class RequestHandler { this.client = client this.discordeno = createRestManager({ token: this.client.token, - baseUrl: options.baseURL ?? this.client.options.proxyURL, + proxy : { + baseUrl: options.baseURL ?? this.client.options.proxyURL, + authorization: this.client.token, + } }) this.userAgent = `DiscordBot (https://github.com/discordeno/discordeno, ${version})` diff --git a/packages/client/src/gateway/Shard.ts b/packages/client/src/gateway/Shard.ts index 5a427a5d3..2698eba8c 100644 --- a/packages/client/src/gateway/Shard.ts +++ b/packages/client/src/gateway/Shard.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/consistent-indexed-object-style */ /* eslint-disable no-useless-call */ /* eslint-disable no-prototype-builtins */ /* eslint-disable @typescript-eslint/restrict-template-expressions */ @@ -5,7 +6,6 @@ /* eslint-disable @typescript-eslint/restrict-plus-operands */ /* eslint-disable @typescript-eslint/explicit-function-return-type */ import { DiscordenoShard, ShardState } from '@discordeno/gateway' -import type { DiscordGuildStickersUpdate, DiscordThreadMemberUpdate } from '@discordeno/types' import { ActivityTypes, ChannelTypes, @@ -25,6 +25,7 @@ import { type DiscordGuildRoleCreate, type DiscordGuildRoleDelete, type DiscordGuildRoleUpdate, + type DiscordGuildStickersUpdate, type DiscordInteraction, type DiscordInviteCreate, type DiscordInviteDelete, @@ -41,6 +42,7 @@ import { type DiscordStageInstance, type DiscordThreadListSync, type DiscordThreadMembersUpdate, + type DiscordThreadMemberUpdate, type DiscordTypingStart, type DiscordUnavailableGuild, type DiscordUser, diff --git a/packages/client/src/typings.ts b/packages/client/src/typings.ts index f807215f6..adc14dc82 100644 --- a/packages/client/src/typings.ts +++ b/packages/client/src/typings.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/consistent-indexed-object-style */ import type { ActivityTypes, ApplicationCommandOptionTypes, diff --git a/packages/client/src/utils/BrowserWebSocket.ts b/packages/client/src/utils/BrowserWebSocket.ts index 9cd1f18a1..9ab22447d 100644 --- a/packages/client/src/utils/BrowserWebSocket.ts +++ b/packages/client/src/utils/BrowserWebSocket.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/class-literal-property-style */ /* eslint-disable @typescript-eslint/explicit-function-return-type */ /* eslint-disable @typescript-eslint/no-var-requires */ import { EventEmitter } from 'node:events' diff --git a/packages/client/src/utils/Bucket.ts b/packages/client/src/utils/Bucket.ts index 6758c709f..e3dd20de2 100644 --- a/packages/client/src/utils/Bucket.ts +++ b/packages/client/src/utils/Bucket.ts @@ -20,6 +20,7 @@ class Bucket { tokenLimit: number tokens: number reservedTokens: number + // eslint-disable-next-line @typescript-eslint/ban-types _queue: Array<{ func: Function; priority: boolean }> timeout: NodeJS.Timeout | null = null diff --git a/packages/eslint-config-discordeno/index.js b/packages/eslint-config-discordeno/index.js index c6c043f65..9dea991d6 100644 --- a/packages/eslint-config-discordeno/index.js +++ b/packages/eslint-config-discordeno/index.js @@ -26,5 +26,6 @@ module.exports = { '@typescript-eslint/no-invalid-void-type': 'off', '@typescript-eslint/consistent-type-imports': 'error', '@typescript-eslint/no-misused-promises': 'off', + '@typescript-eslint/no-confusing-void-expression': 'off', }, } diff --git a/packages/gateway/src/Shard.ts b/packages/gateway/src/Shard.ts index 06a74dc34..5ad8e72ce 100644 --- a/packages/gateway/src/Shard.ts +++ b/packages/gateway/src/Shard.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-confusing-void-expression */ import type { AtLeastOne, BigString, @@ -112,7 +113,7 @@ export class DiscordenoShard { close(code: number, reason: string): void { if (this.socket?.readyState !== WebSocket.OPEN) return - return this.socket?.close(code, reason) + this.socket?.close(code, reason) } /** Connect the shard with the gateway and start heartbeating. This will not identify the shard to the gateway. */ @@ -601,7 +602,7 @@ export class DiscordenoShard { options?: AtLeastOne>, ): Promise { logger.debug(`[Shard] joinVoiceChannel guildId: ${guildId} channelId: ${channelId}`) - return await this.send({ + await this.send({ op: GatewayOpcodes.VoiceStateUpdate, d: { guild_id: guildId.toString(), @@ -620,7 +621,7 @@ export class DiscordenoShard { */ async editBotStatus(data: StatusUpdate): Promise { logger.debug(`[Shard] editBotStatus data: ${JSON.stringify(data)}`) - return await this.editShardStatus(data) + await this.editShardStatus(data) } /** @@ -632,7 +633,7 @@ export class DiscordenoShard { */ async editShardStatus(data: StatusUpdate): Promise { logger.debug(`[Shard] editShardStatus shardId: ${this.id} -> data: ${JSON.stringify(data)}`) - return await this.send({ + await this.send({ op: GatewayOpcodes.PresenceUpdate, d: { since: null, @@ -731,7 +732,7 @@ export class DiscordenoShard { */ async leaveVoiceChannel(guildId: BigString): Promise { logger.debug(`[Shard] leaveVoiceChannel guildId: ${guildId} Shard ${this.id}`) - return await this.send({ + await this.send({ op: GatewayOpcodes.VoiceStateUpdate, d: { guild_id: guildId.toString(), diff --git a/packages/gateway/src/manager.ts b/packages/gateway/src/manager.ts index b986c4d4d..581f57d3a 100644 --- a/packages/gateway/src/manager.ts +++ b/packages/gateway/src/manager.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-confusing-void-expression */ import type { AtLeastOne, BigString, Camelize, DiscordGetGatewayBot, DiscordMember, RequestGuildMembers } from '@discordeno/types' import { Collection, delay, logger } from '@discordeno/utils' import Shard from './Shard.js' @@ -144,7 +145,7 @@ export function createGatewayManager(options: CreateGatewayManagerOptions): Gate }, async tellWorkerToIdentify(workerId, shardId, bucketId) { logger.debug(`[Gateway] tell worker to identify (${workerId}, ${shardId}, ${bucketId})`) - return await gateway.identify(shardId) + await gateway.identify(shardId) }, async identify(shardId: number) { let shard = this.shards.get(shardId) @@ -164,7 +165,7 @@ export function createGatewayManager(options: CreateGatewayManagerOptions): Gate }, events: options.events, requestIdentify: async () => { - return await gateway.identify(shardId); + await gateway.identify(shardId); }, shardIsReady: async () => { logger.debug(`[Shard] Shard #${shardId} is ready`) @@ -196,7 +197,7 @@ export function createGatewayManager(options: CreateGatewayManagerOptions): Gate logger.debug(`[Gateway] kill shard (${shardId})`) this.shards.delete(shardId) - return await shard.shutdown() + await shard.shutdown() }, async requestIdentify(shardId: number) { @@ -251,7 +252,7 @@ export function createGatewayManager(options: CreateGatewayManagerOptions): Gate } logger.debug(`[Gateway] editShardStatus shardId: ${shardId} -> data: ${JSON.stringify(data)}`) - return await shard.editShardStatus(data) + await shard.editShardStatus(data) }, async requestMembers(guildId, options) { @@ -273,7 +274,7 @@ export function createGatewayManager(options: CreateGatewayManagerOptions): Gate } logger.debug(`[Gateway] leaveVoiceChannel guildId: ${guildId} Shard ${shardId}`) - return await shard.leaveVoiceChannel(guildId) + await shard.leaveVoiceChannel(guildId) }, } diff --git a/packages/utils/src/logger.ts b/packages/utils/src/logger.ts index 70746fbcd..1ae922b83 100644 --- a/packages/utils/src/logger.ts +++ b/packages/utils/src/logger.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-confusing-void-expression */ /* eslint-disable @typescript-eslint/explicit-function-return-type */ import { bgBrightMagenta, black, bold, cyan, gray, italic, red, yellow } from './colors.js' diff --git a/packages/utils/src/utils.ts b/packages/utils/src/utils.ts index 05288b892..dddb5b1ff 100644 --- a/packages/utils/src/utils.ts +++ b/packages/utils/src/utils.ts @@ -12,6 +12,7 @@ export async function delay(ms: number): Promise { // Typescript is not so good as we developers so we need this little utility function to help it out // Taken from https://fettblog.eu/typescript-hasownproperty/ /** TS save way to check if a property exists in an object */ +// eslint-disable-next-line @typescript-eslint/ban-types export function hasProperty(obj: T, prop: Y): obj is T & Record { // eslint-disable-next-line no-prototype-builtins return obj.hasOwnProperty(prop) diff --git a/website/docs/bigbot/step-3-gateway.md b/website/docs/bigbot/step-3-gateway.md index d14d64b57..3ad1af077 100644 --- a/website/docs/bigbot/step-3-gateway.md +++ b/website/docs/bigbot/step-3-gateway.md @@ -22,7 +22,7 @@ Let's say the bot process needs to execute some code on some shard such as fetch ## Creating The Manager -## Preparing Connecting To REST +## Connecting To REST Before we begin making a gateway manager, we need to first prepare a connection to our REST manager. Go ahead and make a file called `services/gateway/rest/index.ts`. @@ -32,8 +32,10 @@ import { createRestManager } from '@discordeno/rest' export const REST = createRestManager({ // YOUR BOT TOKEN HERE token: process.env.TOKEN, - baseUrl: process.env.REST_URL, - authorization: process.env.AUTHORIZATION, + proxy: { + baseUrl: process.env.REST_URL, + authorization: process.env.AUTHORIZATION, + } }) ``` @@ -53,7 +55,7 @@ export const GATEWAY = createGatewayManager({ intents: Intents.Guilds | Intents.GuildMessages, shardsPerWorker: 500, totalWorkers: 10, - connection = await REST.getSessionInfo(), + connection: await REST.getSessionInfo(), }) // More code to be added here but first you need to understand this part. @@ -81,7 +83,7 @@ export const GATEWAY = createGatewayManager({ intents: Intents.Guilds | Intents.GuildMessages, shardsPerWorker: 500, totalWorkers: 10, - connection = await REST.getSessionInfo(), + connection: await REST.getSessionInfo(), }) GATEWAY.tellWorkerToIdentify = async function (workerId, shardId, bucketId) {