* Extensions: fix oxfmt drift on main * Plugins: restore runtime barrel exports on main * Config: restore web search compatibility types * Telegram: align test harness with reply runtime * Plugin SDK: fix channel config accessor generics * CLI: remove redundant search provider casts * Tests: restore main typecheck coverage * Lobster: fix test import formatting * Extensions: route bundled seams through plugin-sdk * Tests: use extension env helper for xai * Image generation: fix main oxfmt drift * Config: restore latest main compatibility checks * Plugin SDK: align guardrail tests with lint * Telegram: type native command skill mock
55 lines
2.0 KiB
TypeScript
55 lines
2.0 KiB
TypeScript
import {
|
|
applyDirectoryQueryAndLimit,
|
|
collectNormalizedDirectoryIds,
|
|
toDirectoryEntries,
|
|
type DirectoryConfigParams,
|
|
} from "openclaw/plugin-sdk/directory-runtime";
|
|
import { inspectDiscordAccount, type InspectedDiscordAccount } from "../api.js";
|
|
|
|
export async function listDiscordDirectoryPeersFromConfig(params: DirectoryConfigParams) {
|
|
const account = inspectDiscordAccount({
|
|
cfg: params.cfg,
|
|
accountId: params.accountId,
|
|
}) as InspectedDiscordAccount | null;
|
|
if (!account || !("config" in account)) {
|
|
return [];
|
|
}
|
|
|
|
const allowFrom = account.config.allowFrom ?? account.config.dm?.allowFrom ?? [];
|
|
const guildUsers = Object.values(account.config.guilds ?? {}).flatMap((guild) => [
|
|
...(guild.users ?? []),
|
|
...Object.values(guild.channels ?? {}).flatMap((channel) => channel.users ?? []),
|
|
]);
|
|
const ids = collectNormalizedDirectoryIds({
|
|
sources: [allowFrom, Object.keys(account.config.dms ?? {}), guildUsers],
|
|
normalizeId: (raw) => {
|
|
const mention = raw.match(/^<@!?(\d+)>$/);
|
|
const cleaned = (mention?.[1] ?? raw).replace(/^(discord|user):/i, "").trim();
|
|
return /^\d+$/.test(cleaned) ? `user:${cleaned}` : null;
|
|
},
|
|
});
|
|
return toDirectoryEntries("user", applyDirectoryQueryAndLimit(ids, params));
|
|
}
|
|
|
|
export async function listDiscordDirectoryGroupsFromConfig(params: DirectoryConfigParams) {
|
|
const account = inspectDiscordAccount({
|
|
cfg: params.cfg,
|
|
accountId: params.accountId,
|
|
}) as InspectedDiscordAccount | null;
|
|
if (!account || !("config" in account)) {
|
|
return [];
|
|
}
|
|
|
|
const ids = collectNormalizedDirectoryIds({
|
|
sources: Object.values(account.config.guilds ?? {}).map((guild) =>
|
|
Object.keys(guild.channels ?? {}),
|
|
),
|
|
normalizeId: (raw) => {
|
|
const mention = raw.match(/^<#(\d+)>$/);
|
|
const cleaned = (mention?.[1] ?? raw).replace(/^(discord|channel|group):/i, "").trim();
|
|
return /^\d+$/.test(cleaned) ? `channel:${cleaned}` : null;
|
|
},
|
|
});
|
|
return toDirectoryEntries("group", applyDirectoryQueryAndLimit(ids, params));
|
|
}
|