From cb9ebad0fa8d655569166b43f535b3dd8621e5fb Mon Sep 17 00:00:00 2001 From: Clove Twilight Date: Fri, 19 Jun 2026 00:24:31 +0100 Subject: [PATCH] Fixes --- src/gateway.ts | 16 ++++++++++++++++ src/index.ts | 7 +++++++ 2 files changed, 23 insertions(+) diff --git a/src/gateway.ts b/src/gateway.ts index cf2cca1..2221a16 100644 --- a/src/gateway.ts +++ b/src/gateway.ts @@ -36,6 +36,8 @@ export class GatewayManager implements DurableObject { private heartbeatTimer: ReturnType | null = null; private heartbeatAcked = true; private reconnectAttempts = 0; + private lastCloseCode: number | null = null; + private connectedSince: number | null = null; private presences = new Map(); private clients = new Map(); @@ -61,6 +63,16 @@ export class GatewayManager implements DurableObject { if (url.pathname === "/connect") { return Response.json({ connected: !!this.discord, tracked: this.presences.size }); } + if (url.pathname === "/status") { + return Response.json({ + connected: !!this.discord, + tracked: this.presences.size, + connected_since: this.connectedSince, + last_close_code: this.lastCloseCode, + reconnect_attempts: this.reconnectAttempts, + has_session: !!this.sessionId, + }); + } if (url.pathname === "/presences") { return Response.json(Object.fromEntries(this.presences)); } @@ -151,6 +163,8 @@ export class GatewayManager implements DurableObject { this.sessionId = d.session_id ?? null; this.resumeUrl = d.resume_gateway_url ?? null; this.reconnectAttempts = 0; + this.lastCloseCode = null; + this.connectedSince = Date.now(); break; case "RESUMED": this.reconnectAttempts = 0; @@ -237,6 +251,8 @@ export class GatewayManager implements DurableObject { this.heartbeatTimer = null; } this.discord = null; + this.lastCloseCode = code; + this.connectedSince = null; // 4004/4010/4011/4013/4014 = fatal (bad token/intents) — don't hammer. const fatal = [4004, 4010, 4011, 4012, 4013, 4014].includes(code); if (fatal) { diff --git a/src/index.ts b/src/index.ts index 95da6a6..59cfebb 100644 --- a/src/index.ts +++ b/src/index.ts @@ -55,6 +55,13 @@ export default { return gatewayStub(env).fetch(new Request("https://do/ws", req)); } + // ---- Gateway status (debug) ---- + if (path === "/status") { + const res = await gatewayStub(env).fetch("https://do/status"); + const body = await res.json(); + return json({ success: true, data: body as any }); + } + if (path === "/") { return json({ success: true,