Discord: clarify startup readiness log
This commit is contained in:
parent
d78e13f545
commit
f7da963fa8
@ -92,6 +92,7 @@ import { resolveDiscordPresenceUpdate } from "./presence.js";
|
||||
import { resolveDiscordAllowlistConfig } from "./provider.allowlist.js";
|
||||
import { runDiscordGatewayLifecycle } from "./provider.lifecycle.js";
|
||||
import { resolveDiscordRestFetch } from "./rest-fetch.js";
|
||||
import { formatDiscordStartupStatusMessage } from "./startup-status.js";
|
||||
import type { DiscordMonitorStatusSink } from "./status.js";
|
||||
import {
|
||||
createNoopThreadBindingManager,
|
||||
@ -972,7 +973,12 @@ export async function monitorDiscordProvider(opts: MonitorDiscordOpts = {}) {
|
||||
|
||||
const botIdentity =
|
||||
botUserId && botUserName ? `${botUserId} (${botUserName})` : (botUserId ?? botUserName ?? "");
|
||||
runtime.log?.(`logged in to discord${botIdentity ? ` as ${botIdentity}` : ""}`);
|
||||
runtime.log?.(
|
||||
formatDiscordStartupStatusMessage({
|
||||
gatewayReady: lifecycleGateway?.isConnected === true,
|
||||
botIdentity: botIdentity || undefined,
|
||||
}),
|
||||
);
|
||||
if (lifecycleGateway?.isConnected) {
|
||||
opts.setStatus?.(createConnectedChannelStatusPatch());
|
||||
}
|
||||
|
||||
30
extensions/discord/src/monitor/startup-status.test.ts
Normal file
30
extensions/discord/src/monitor/startup-status.test.ts
Normal file
@ -0,0 +1,30 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { formatDiscordStartupStatusMessage } from "./startup-status.js";
|
||||
|
||||
describe("formatDiscordStartupStatusMessage", () => {
|
||||
it("reports logged-in status only after the gateway is ready", () => {
|
||||
expect(
|
||||
formatDiscordStartupStatusMessage({
|
||||
gatewayReady: true,
|
||||
botIdentity: "bot-1 (Molty)",
|
||||
}),
|
||||
).toBe("logged in to discord as bot-1 (Molty)");
|
||||
});
|
||||
|
||||
it("reports client initialization while gateway readiness is still pending", () => {
|
||||
expect(
|
||||
formatDiscordStartupStatusMessage({
|
||||
gatewayReady: false,
|
||||
botIdentity: "bot-1 (Molty)",
|
||||
}),
|
||||
).toBe("discord client initialized as bot-1 (Molty); awaiting gateway readiness");
|
||||
});
|
||||
|
||||
it("handles missing identity without awkward punctuation", () => {
|
||||
expect(
|
||||
formatDiscordStartupStatusMessage({
|
||||
gatewayReady: false,
|
||||
}),
|
||||
).toBe("discord client initialized; awaiting gateway readiness");
|
||||
});
|
||||
});
|
||||
10
extensions/discord/src/monitor/startup-status.ts
Normal file
10
extensions/discord/src/monitor/startup-status.ts
Normal file
@ -0,0 +1,10 @@
|
||||
export function formatDiscordStartupStatusMessage(params: {
|
||||
gatewayReady: boolean;
|
||||
botIdentity?: string;
|
||||
}): string {
|
||||
const identitySuffix = params.botIdentity ? ` as ${params.botIdentity}` : "";
|
||||
if (params.gatewayReady) {
|
||||
return `logged in to discord${identitySuffix}`;
|
||||
}
|
||||
return `discord client initialized${identitySuffix}; awaiting gateway readiness`;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user