Files
discordeno/gateway/identify.ts
Skillz4Killz a0a1554756 refactor: typings using ReturnType (#2105)
* fix: check new types idea

* fix: type errors

* fix: new style

* fix: more cleanup

* fix: more cleanup

* fix: cleanup audit logs

* fix: cleanup stickers

* fix: cleanup integrations

* fix: more cleanup

* fix: organize into 1 place

* fix: few errors

* fix: some broken import fixes

* fix: quite a lot of fixes across the board

* fix: more fixes for broken imports

* fix: more fixes for broken imports

* fix: handler imports

* fix: all remaining import errors

* fix: more errors needing fixes

* fix: clearing up transformers

* fix: few moer types

* fix: more cleanup of extra types

* fix: fmt

* fix: cleanup discordeno file

* Nuke Base Types (#2102)

* fix: cleanup snake stuff

* convert camelCase to snake_case (#2103)

* fix: add camelize

* fix: finalize remaining errors

* fix: imports in test

Co-authored-by: LTS20050703 <87189679+lts20050703@users.noreply.github.com>
2022-03-14 22:11:22 -04:00

73 lines
1.8 KiB
TypeScript

import { GatewayOpcodes } from "../types/shared.ts";
import { GatewayManager } from "./gateway_manager.ts";
export function identify(gateway: GatewayManager, shardId: number, maxShards: number) {
gateway.debug("GW IDENTIFYING", { shardId, maxShards });
// Need to clear the old heartbeat interval
const oldShard = gateway.shards.get(shardId);
if (oldShard) {
gateway.closeWS(oldShard.ws, 3065, "Reidentifying closure of old shard");
clearInterval(oldShard.heartbeat.intervalId);
}
// CREATE A SHARD
const socket = gateway.createShard(gateway, shardId);
// Identify can just set/reset the settings for the shard
gateway.shards.set(shardId, {
id: shardId,
ws: socket,
resumeInterval: 0,
sessionId: "",
previousSequenceNumber: 0,
resuming: false,
ready: false,
unavailableGuildIds: new Set(),
heartbeat: {
lastSentAt: 0,
lastReceivedAt: 0,
acknowledged: false,
keepAlive: false,
interval: 0,
intervalId: 0,
},
queue: [],
processingQueue: false,
queueStartedAt: Date.now(),
queueCounter: 0,
// BY DEFAULT SET TO 120. EDIT IN HELLO
safeRequestsPerShard: 120,
});
socket.onopen = () => {
gateway.sendShardMessage(
gateway,
shardId,
{
op: GatewayOpcodes.Identify,
d: {
token: `Bot ${gateway.token}`,
compress: gateway.compress,
properties: {
$os: gateway.$os,
$browser: gateway.$browser,
$device: gateway.$device,
},
intents: gateway.intents,
shard: [shardId, maxShards],
presence: gateway.presence,
},
},
true,
);
};
return new Promise((resolve) => {
gateway.loadingShards.set(shardId, {
shardId,
resolve,
});
});
}