message: fix(ws): resume identify when oldShard is undefined
diff: import { DiscordGatewayOpcodes } from "../types/codes/gateway_opcodes.ts";
  +import { identify } from "./identify.ts";
  import { ws } from "./ws.ts";
  export async function resume(shardId: number) {
  ws.log("RESUMING", { shardId });
  - // CREATE A SHARD
  - const socket = await ws.createShard(shardId);
  -
  // NOW WE HANDLE RESUMING THIS SHARD
  // Get the old data for this shard necessary for resuming
  const oldShard = ws.shards.get(shardId);
  + if (!oldShard) return identify(shardId, ws.maxShards);
  +
  + // CREATE A SHARD
  + const socket = await ws.createShard(shardId);
  - if (oldShard) {
  // ONLY CLOSE IF SHARD SOCKET IS STILL CONNECTED
  if (oldShard.ws.readyState === WebSocket.OPEN) {
  // HOW TO CLOSE OLD SHARD SOCKET!!!
  @@ -19,17 +20,13 @@ export async function resume(shardId: number) {
  }
  // STOP OLD HEARTBEAT
  clearInterval(oldShard.heartbeat.intervalId);
  - }
  -
  - const sessionId = oldShard?.sessionId || "";
  - const previousSequenceNumber = oldShard?.previousSequenceNumber || 0;
  ws.shards.set(shardId, {
  id: shardId,
  ws: socket,
  resumeInterval: 0,
  - sessionId,
  - previousSequenceNumber,
  + sessionId: oldShard.sessionId,
  + previousSequenceNumber: oldShard.previousSequenceNumber,
  resuming: false,
  ready: false,
  unavailableGuildIds: new Set(),
  @@ -41,7 +38,7 @@ export async function resume(shardId: number) {
  interval: 0,
  intervalId: 0,
  },
  - queue: oldShard?.queue || [],
  + queue: oldShard.queue || [],
  processingQueue: false,
  queueStartedAt: Date.now(),
  queueCounter: 0,
  @@ -53,8 +50,8 @@ export async function resume(shardId: number) {
  op: DiscordGatewayOpcodes.Resume,
  d: {
  token: ws.identifyPayload.token,
  - session_id: sessionId,
  - seq: previousSequenceNumber,
  + session_id: oldShard.sessionId,
  + seq: oldShard.previousSequenceNumber,
  },
  });
  