mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 20:54:33 +00:00
feat(discord): add set-presence action for bot activity and status
Bridge the agent tools layer to the Discord gateway WebSocket via a new gateway registry, allowing agents to set the bot's activity and online status. Supports playing, streaming, listening, watching, custom, and competing activity types. Custom type uses activityState as the sidebar text; other types show activityName in the sidebar and activityState in the flyout. Opt-in via channels.discord.actions.presence (default false). Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
committed by
clawdinator[bot]
parent
b64c1a56a1
commit
5af322f710
33
src/discord/monitor/gateway-registry.ts
Normal file
33
src/discord/monitor/gateway-registry.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import type { GatewayPlugin } from "@buape/carbon/gateway";
|
||||
|
||||
/**
|
||||
* Module-level registry of active Discord GatewayPlugin instances.
|
||||
* Bridges the gap between agent tool handlers (which only have REST access)
|
||||
* and the gateway WebSocket (needed for operations like updatePresence).
|
||||
* Follows the same pattern as presence-cache.ts.
|
||||
*/
|
||||
const gatewayRegistry = new Map<string, GatewayPlugin>();
|
||||
|
||||
function resolveAccountKey(accountId?: string): string {
|
||||
return accountId ?? "default";
|
||||
}
|
||||
|
||||
/** Register a GatewayPlugin instance for an account. */
|
||||
export function registerGateway(accountId: string | undefined, gateway: GatewayPlugin): void {
|
||||
gatewayRegistry.set(resolveAccountKey(accountId), gateway);
|
||||
}
|
||||
|
||||
/** Unregister a GatewayPlugin instance for an account. */
|
||||
export function unregisterGateway(accountId?: string): void {
|
||||
gatewayRegistry.delete(resolveAccountKey(accountId));
|
||||
}
|
||||
|
||||
/** Get the GatewayPlugin for an account. Returns undefined if not registered. */
|
||||
export function getGateway(accountId?: string): GatewayPlugin | undefined {
|
||||
return gatewayRegistry.get(resolveAccountKey(accountId));
|
||||
}
|
||||
|
||||
/** Clear all registered gateways (for testing). */
|
||||
export function clearGateways(): void {
|
||||
gatewayRegistry.clear();
|
||||
}
|
||||
Reference in New Issue
Block a user