mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-04 09:50:07 +00:00
change: prettier code
This commit is contained in:
committed by
GitHub Action
parent
854da807f7
commit
03e60d859b
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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 });
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user