mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 21:48:27 +00:00
refactor(channels): share directory allowFrom parsing
This commit is contained in:
@@ -14,6 +14,26 @@ export type DirectoryConfigParams = {
|
|||||||
limit?: number | null;
|
limit?: number | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function addAllowFromAndDmsIds(
|
||||||
|
ids: Set<string>,
|
||||||
|
allowFrom: readonly unknown[] | undefined,
|
||||||
|
dms: Record<string, unknown> | undefined,
|
||||||
|
) {
|
||||||
|
for (const entry of allowFrom ?? []) {
|
||||||
|
const raw = String(entry).trim();
|
||||||
|
if (!raw || raw === "*") {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
ids.add(raw);
|
||||||
|
}
|
||||||
|
for (const id of Object.keys(dms ?? {})) {
|
||||||
|
const trimmed = id.trim();
|
||||||
|
if (trimmed) {
|
||||||
|
ids.add(trimmed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export async function listSlackDirectoryPeersFromConfig(
|
export async function listSlackDirectoryPeersFromConfig(
|
||||||
params: DirectoryConfigParams,
|
params: DirectoryConfigParams,
|
||||||
): Promise<ChannelDirectoryEntry[]> {
|
): Promise<ChannelDirectoryEntry[]> {
|
||||||
@@ -21,19 +41,7 @@ export async function listSlackDirectoryPeersFromConfig(
|
|||||||
const q = params.query?.trim().toLowerCase() || "";
|
const q = params.query?.trim().toLowerCase() || "";
|
||||||
const ids = new Set<string>();
|
const ids = new Set<string>();
|
||||||
|
|
||||||
for (const entry of account.config.allowFrom ?? account.dm?.allowFrom ?? []) {
|
addAllowFromAndDmsIds(ids, account.config.allowFrom ?? account.dm?.allowFrom, account.config.dms);
|
||||||
const raw = String(entry).trim();
|
|
||||||
if (!raw || raw === "*") {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
ids.add(raw);
|
|
||||||
}
|
|
||||||
for (const id of Object.keys(account.config.dms ?? {})) {
|
|
||||||
const trimmed = id.trim();
|
|
||||||
if (trimmed) {
|
|
||||||
ids.add(trimmed);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (const channel of Object.values(account.config.channels ?? {})) {
|
for (const channel of Object.values(account.config.channels ?? {})) {
|
||||||
for (const user of channel.users ?? []) {
|
for (const user of channel.users ?? []) {
|
||||||
const raw = String(user).trim();
|
const raw = String(user).trim();
|
||||||
@@ -84,19 +92,11 @@ export async function listDiscordDirectoryPeersFromConfig(
|
|||||||
const q = params.query?.trim().toLowerCase() || "";
|
const q = params.query?.trim().toLowerCase() || "";
|
||||||
const ids = new Set<string>();
|
const ids = new Set<string>();
|
||||||
|
|
||||||
for (const entry of account.config.allowFrom ?? account.config.dm?.allowFrom ?? []) {
|
addAllowFromAndDmsIds(
|
||||||
const raw = String(entry).trim();
|
ids,
|
||||||
if (!raw || raw === "*") {
|
account.config.allowFrom ?? account.config.dm?.allowFrom,
|
||||||
continue;
|
account.config.dms,
|
||||||
}
|
);
|
||||||
ids.add(raw);
|
|
||||||
}
|
|
||||||
for (const id of Object.keys(account.config.dms ?? {})) {
|
|
||||||
const trimmed = id.trim();
|
|
||||||
if (trimmed) {
|
|
||||||
ids.add(trimmed);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (const guild of Object.values(account.config.guilds ?? {})) {
|
for (const guild of Object.values(account.config.guilds ?? {})) {
|
||||||
for (const entry of guild.users ?? []) {
|
for (const entry of guild.users ?? []) {
|
||||||
const raw = String(entry).trim();
|
const raw = String(entry).trim();
|
||||||
|
|||||||
Reference in New Issue
Block a user