From 03e60d859bea6155003b40ae348803c0fe0ded59 Mon Sep 17 00:00:00 2001 From: Skillz4Killz Date: Fri, 8 Oct 2021 14:43:55 +0000 Subject: [PATCH] change: prettier code --- src/util/calculate_shard_id.ts | 2 +- src/ws/create_shard.ts | 2 +- src/ws/handle_discord_payload.ts | 2 +- src/ws/handle_on_message.ts | 4 ++-- src/ws/heartbeat.ts | 2 +- src/ws/identify.ts | 4 ++-- src/ws/process_queue.ts | 2 +- src/ws/resume.ts | 4 ++-- src/ws/send_shard_message.ts | 7 ++++++- src/ws/start_gateway.ts | 10 +++++----- src/ws/tell_cluster_to_identify.ts | 9 +++++++-- 11 files changed, 29 insertions(+), 19 deletions(-) diff --git a/src/util/calculate_shard_id.ts b/src/util/calculate_shard_id.ts index e9b7a331b..f6756eba4 100644 --- a/src/util/calculate_shard_id.ts +++ b/src/util/calculate_shard_id.ts @@ -1,4 +1,4 @@ -import {GatewayManager} from "../bot.ts"; +import { GatewayManager } from "../bot.ts"; export function calculateShardId(gateway: GatewayManager, guildId: bigint) { if (gateway.maxShards === 1) return 0; diff --git a/src/ws/create_shard.ts b/src/ws/create_shard.ts index f2909dfe5..a83b36823 100644 --- a/src/ws/create_shard.ts +++ b/src/ws/create_shard.ts @@ -1,5 +1,5 @@ import { DiscordGatewayCloseEventCodes } from "../types/codes/gateway_close_event_codes.ts"; -import {GatewayManager} from "../bot.ts"; +import { GatewayManager } from "../bot.ts"; export function createShard(gateway: GatewayManager, shardId: number) { const socket = new WebSocket(gateway.botGatewayData.url); diff --git a/src/ws/handle_discord_payload.ts b/src/ws/handle_discord_payload.ts index 6ca60e1e0..8bd709724 100644 --- a/src/ws/handle_discord_payload.ts +++ b/src/ws/handle_discord_payload.ts @@ -1,5 +1,5 @@ import type { DiscordGatewayPayload } from "../types/gateway/gateway_payload.ts"; -import {GatewayManager} from "../bot.ts"; +import { GatewayManager } from "../bot.ts"; /** Handler for processing all dispatch payloads that should be sent/forwarded to another server/vps/process. */ export async function handleDiscordPayload(gateway: GatewayManager, data: DiscordGatewayPayload, shardId: number) { diff --git a/src/ws/handle_on_message.ts b/src/ws/handle_on_message.ts index e09427d79..c860921e1 100644 --- a/src/ws/handle_on_message.ts +++ b/src/ws/handle_on_message.ts @@ -1,4 +1,4 @@ -import {eventHandlers, GatewayManager} from "../bot.ts"; +import { eventHandlers, GatewayManager } from "../bot.ts"; import { handlers } from "../handlers/mod.ts"; import { DiscordGatewayOpcodes } from "../types/codes/gateway_opcodes.ts"; import type { DiscordGatewayPayload } from "../types/gateway/gateway_payload.ts"; @@ -32,7 +32,7 @@ export async function handleOnMessage(gateway: GatewayManager, message: any, sha shard.heartbeat.lastSentAt = Date.now(); // Discord randomly sends this requiring an immediate heartbeat back gateway.sendShardMessage( - gateway, + gateway, shard, { op: DiscordGatewayOpcodes.Heartbeat, diff --git a/src/ws/heartbeat.ts b/src/ws/heartbeat.ts index ef25f1f63..0f7ab8c45 100644 --- a/src/ws/heartbeat.ts +++ b/src/ws/heartbeat.ts @@ -1,6 +1,6 @@ import { DiscordGatewayOpcodes } from "../types/codes/gateway_opcodes.ts"; import { delay } from "../util/utils.ts"; -import {GatewayManager} from "../bot.ts"; +import { GatewayManager } from "../bot.ts"; export async function heartbeat(gateway: GatewayManager, shardId: number, interval: number) { gateway.log("HEARTBEATING_STARTED", { shardId, interval }); diff --git a/src/ws/identify.ts b/src/ws/identify.ts index 9441e7144..47f17d5eb 100644 --- a/src/ws/identify.ts +++ b/src/ws/identify.ts @@ -1,5 +1,5 @@ import { DiscordGatewayOpcodes } from "../types/codes/gateway_opcodes.ts"; -import {GatewayManager} from "../bot.ts"; +import { GatewayManager } from "../bot.ts"; export function identify(gateway: GatewayManager, shardId: number, maxShards: number) { gateway.log("IDENTIFYING", { shardId, maxShards }); @@ -40,7 +40,7 @@ export function identify(gateway: GatewayManager, shardId: number, maxShards: nu socket.onopen = () => { gateway.sendShardMessage( - gateway, + gateway, shardId, { op: DiscordGatewayOpcodes.Identify, diff --git a/src/ws/process_queue.ts b/src/ws/process_queue.ts index ab670d3f1..b0b3629c2 100644 --- a/src/ws/process_queue.ts +++ b/src/ws/process_queue.ts @@ -1,6 +1,6 @@ import { loopObject } from "../util/loop_object.ts"; import { delay } from "../util/utils.ts"; -import {GatewayManager} from "../bot.ts"; +import { GatewayManager } from "../bot.ts"; export async function processQueue(gateway: GatewayManager, id: number) { const shard = gateway.shards.get(id); diff --git a/src/ws/resume.ts b/src/ws/resume.ts index e63e8da41..51fed0114 100644 --- a/src/ws/resume.ts +++ b/src/ws/resume.ts @@ -1,5 +1,5 @@ import { DiscordGatewayOpcodes } from "../types/codes/gateway_opcodes.ts"; -import {GatewayManager} from "../bot.ts"; +import { GatewayManager } from "../bot.ts"; export function resume(gateway: GatewayManager, shardId: number) { gateway.log("RESUMING", { shardId }); @@ -47,7 +47,7 @@ export function resume(gateway: GatewayManager, shardId: number) { // Resume on open socket.onopen = () => { gateway.sendShardMessage( - gateway, + gateway, shardId, { op: DiscordGatewayOpcodes.Resume, diff --git a/src/ws/send_shard_message.ts b/src/ws/send_shard_message.ts index 6179e00d3..5e99bc537 100644 --- a/src/ws/send_shard_message.ts +++ b/src/ws/send_shard_message.ts @@ -1,7 +1,12 @@ import { DiscordenoShard, WebSocketRequest } from "./ws.ts"; import { GatewayManager } from "../bot.ts"; -export function sendShardMessage(gateway: GatewayManager, shard: number | DiscordenoShard, message: WebSocketRequest, highPriority = false) { +export function sendShardMessage( + gateway: GatewayManager, + shard: number | DiscordenoShard, + message: WebSocketRequest, + highPriority = false +) { if (typeof shard === "number") shard = gateway.shards.get(shard)!; if (!shard) return; diff --git a/src/ws/start_gateway.ts b/src/ws/start_gateway.ts index 99c704f94..4c281499a 100644 --- a/src/ws/start_gateway.ts +++ b/src/ws/start_gateway.ts @@ -24,14 +24,14 @@ export async function startGateway(gateway: GatewayManager, options: StartGatewa setInterval(() => gateway.resharder(gateway), 1000 * 60 * 60); gateway.identifyPayload.intents = options.intents.reduce( - (bits, next) => (bits |= typeof next === "string" ? DiscordGatewayIntents[next] : next), - 0 + (bits, next) => (bits |= typeof next === "string" ? DiscordGatewayIntents[next] : next), + 0 ); gateway.botGatewayData = camelize( - await fetch(`https://discord.com/api/gateway/bot`, { - headers: { Authorization: gateway.identifyPayload.token }, - }).then((res) => res.json()) + await fetch(`https://discord.com/api/gateway/bot`, { + headers: { Authorization: gateway.identifyPayload.token }, + }).then((res) => res.json()) ) as GetGatewayBot; gateway.maxShards = options.maxShards || gateway.botGatewayData.shards; diff --git a/src/ws/tell_cluster_to_identify.ts b/src/ws/tell_cluster_to_identify.ts index bbef60e95..b9f6d1f4f 100644 --- a/src/ws/tell_cluster_to_identify.ts +++ b/src/ws/tell_cluster_to_identify.ts @@ -1,6 +1,11 @@ -import {GatewayManager} from "../bot.ts"; +import { GatewayManager } from "../bot.ts"; /** Allows users to hook in and change to communicate to different clusters across different servers or anything they like. For example using redis pubsub to talk to other servers. */ -export async function tellClusterToIdentify(gateway: GatewayManager, _workerId: number, shardId: number, _bucketId: number) { +export async function tellClusterToIdentify( + gateway: GatewayManager, + _workerId: number, + shardId: number, + _bucketId: number +) { await gateway.identify(gateway, shardId, gateway.maxShards); }