feat(turn-init): use internal Discord channel member resolver for bootstrap (no public tool)

This commit is contained in:
2026-03-08 06:08:51 +00:00
parent 121786e6e3
commit 307235e207
5 changed files with 162 additions and 11 deletions

View File

@@ -1,7 +1,9 @@
import type { OpenClawPluginApi } from "openclaw/plugin-sdk";
import { initTurnOrder } from "../turn-manager.js";
import { fetchVisibleChannelBotAccountIds } from "./channel-members.js";
const channelSeenAccounts = new Map<string, Set<string>>();
const channelBootstrapTried = new Set<string>();
function getAllBotAccountIds(api: OpenClawPluginApi): string[] {
const root = (api.config as Record<string, unknown>) || {};
@@ -35,8 +37,16 @@ export function recordChannelAccount(channelId: string, accountId: string): bool
return true;
}
export function ensureTurnOrder(api: OpenClawPluginApi, channelId: string): void {
const botAccounts = getChannelBotAccountIds(api, channelId);
export async function ensureTurnOrder(api: OpenClawPluginApi, channelId: string): Promise<void> {
let botAccounts = getChannelBotAccountIds(api, channelId);
if (botAccounts.length === 0 && !channelBootstrapTried.has(channelId)) {
channelBootstrapTried.add(channelId);
const discovered = await fetchVisibleChannelBotAccountIds(api, channelId).catch(() => [] as string[]);
for (const aid of discovered) recordChannelAccount(channelId, aid);
botAccounts = getChannelBotAccountIds(api, channelId);
}
if (botAccounts.length > 0) {
initTurnOrder(channelId, botAccounts);
}