mirror of
https://github.com/farcasclaudiu/openclaw.git
synced 2026-06-29 11:02:12 +03:00
fix(discord): align wildcard channel matching
This commit is contained in:
@@ -3,6 +3,7 @@ import type { Guild, User } from "@buape/carbon";
|
||||
import {
|
||||
buildChannelKeyCandidates,
|
||||
resolveChannelEntryMatchWithFallback,
|
||||
type ChannelMatchSource,
|
||||
} from "../../channels/channel-config.js";
|
||||
import type { AllowlistMatch } from "../../channels/allowlist-match.js";
|
||||
import { formatDiscordUserTag } from "./format.js";
|
||||
@@ -44,7 +45,7 @@ export type DiscordChannelConfigResolved = {
|
||||
systemPrompt?: string;
|
||||
autoThread?: boolean;
|
||||
matchKey?: string;
|
||||
matchSource?: "direct" | "parent";
|
||||
matchSource?: ChannelMatchSource;
|
||||
};
|
||||
|
||||
export function normalizeDiscordAllowList(
|
||||
@@ -198,13 +199,14 @@ function resolveDiscordChannelEntryMatch(
|
||||
entries: channels,
|
||||
keys,
|
||||
parentKeys,
|
||||
wildcardKey: "*",
|
||||
});
|
||||
}
|
||||
|
||||
function resolveDiscordChannelConfigEntry(
|
||||
entry: DiscordChannelEntry,
|
||||
matchKey: string | undefined,
|
||||
matchSource: "direct" | "parent",
|
||||
matchSource: ChannelMatchSource,
|
||||
): DiscordChannelConfigResolved {
|
||||
const resolved: DiscordChannelConfigResolved = {
|
||||
allowed: entry.allow !== false,
|
||||
@@ -234,15 +236,8 @@ export function resolveDiscordChannelConfig(params: {
|
||||
name: channelName,
|
||||
slug: channelSlug,
|
||||
});
|
||||
if (!match.entry || !match.matchKey) {
|
||||
// Wildcard fallback: apply to all channels if "*" is configured
|
||||
const wildcard = channels["*"];
|
||||
if (wildcard) {
|
||||
return resolveDiscordChannelConfigEntry(wildcard, "*", "direct");
|
||||
}
|
||||
return { allowed: false };
|
||||
}
|
||||
return resolveDiscordChannelConfigEntry(match.entry, match.matchKey, "direct");
|
||||
if (!match.entry || !match.matchKey || !match.matchSource) return { allowed: false };
|
||||
return resolveDiscordChannelConfigEntry(match.entry, match.matchKey, match.matchSource);
|
||||
}
|
||||
|
||||
export function resolveDiscordChannelConfigWithFallback(params: {
|
||||
@@ -285,16 +280,7 @@ export function resolveDiscordChannelConfigWithFallback(params: {
|
||||
: undefined,
|
||||
);
|
||||
if (match.entry && match.matchKey && match.matchSource) {
|
||||
return resolveDiscordChannelConfigEntry(
|
||||
match.entry,
|
||||
match.matchKey,
|
||||
match.matchSource === "parent" ? "parent" : "direct",
|
||||
);
|
||||
}
|
||||
// Wildcard fallback: apply to all channels if "*" is configured
|
||||
const wildcard = channels["*"];
|
||||
if (wildcard) {
|
||||
return resolveDiscordChannelConfigEntry(wildcard, "*", "direct");
|
||||
return resolveDiscordChannelConfigEntry(match.entry, match.matchKey, match.matchSource);
|
||||
}
|
||||
return { allowed: false };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user