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.
This commit is contained in:
Wimmie
2026-01-20 20:49:40 +00:00
committed by Peter Steinberger
parent 9b47f463b7
commit 64d29b0c31
2 changed files with 43 additions and 1 deletions

View File

@@ -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", () => {

View File

@@ -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 };
}