From 64d29b0c310ca73f1b6b8716c2d317e3d038b528 Mon Sep 17 00:00:00 2001 From: Wimmie Date: Tue, 20 Jan 2026 20:49:40 +0000 Subject: [PATCH] feat(discord): add wildcard channel config support Add support for '*' wildcard in Discord channel configuration, matching the existing guild-level wildcard behavior. This allows applying default channel settings (like autoThread) to all channels without listing each one explicitly: guilds: '*': channels: '*': { autoThread: true } Specific channel configs still take precedence over the wildcard. --- src/discord/monitor.test.ts | 30 ++++++++++++++++++++++++++++++ src/discord/monitor/allow-list.ts | 14 +++++++++++++- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/discord/monitor.test.ts b/src/discord/monitor.test.ts index 6d3565b66..e5c3ad347 100644 --- a/src/discord/monitor.test.ts +++ b/src/discord/monitor.test.ts @@ -281,6 +281,36 @@ describe("discord guild/channel resolution", () => { }); expect(thread?.allowed).toBe(false); }); + + it("applies wildcard channel config when no specific match", () => { + const guildInfo: DiscordGuildEntryResolved = { + channels: { + general: { allow: true, requireMention: false }, + "*": { allow: true, autoThread: true, requireMention: true }, + }, + }; + // Specific channel should NOT use wildcard + const general = resolveDiscordChannelConfig({ + guildInfo, + channelId: "123", + channelName: "general", + channelSlug: "general", + }); + expect(general?.allowed).toBe(true); + expect(general?.requireMention).toBe(false); + expect(general?.autoThread).toBeUndefined(); + + // Unknown channel should use wildcard + const random = resolveDiscordChannelConfig({ + guildInfo, + channelId: "999", + channelName: "random", + channelSlug: "random", + }); + expect(random?.allowed).toBe(true); + expect(random?.autoThread).toBe(true); + expect(random?.requireMention).toBe(true); + }); }); describe("discord mention gating", () => { diff --git a/src/discord/monitor/allow-list.ts b/src/discord/monitor/allow-list.ts index 0b4914e1c..b3dc048e7 100644 --- a/src/discord/monitor/allow-list.ts +++ b/src/discord/monitor/allow-list.ts @@ -234,7 +234,14 @@ export function resolveDiscordChannelConfig(params: { name: channelName, slug: channelSlug, }); - if (!match.entry || !match.matchKey) return { allowed: false }; + 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"); } @@ -284,6 +291,11 @@ export function resolveDiscordChannelConfigWithFallback(params: { match.matchSource === "parent" ? "parent" : "direct", ); } + // Wildcard fallback: apply to all channels if "*" is configured + const wildcard = channels["*"]; + if (wildcard) { + return resolveDiscordChannelConfigEntry(wildcard, "*", "direct"); + } return { allowed: false }; }