惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

爱范儿
爱范儿
量子位
大猫的无限游戏
大猫的无限游戏
小众软件
小众软件
J
Java Code Geeks
B
Blog
V
V2EX
博客园 - 三生石上(FineUI控件)
Blog — PlanetScale
Blog — PlanetScale
aimingoo的专栏
aimingoo的专栏
Y
Y Combinator Blog
F
Fortinet All Blogs
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
The Cloudflare Blog
A
About on SuperTechFans
D
DataBreaches.Net
阮一峰的网络日志
阮一峰的网络日志
博客园 - Franky
H
Help Net Security
宝玉的分享
宝玉的分享
Martin Fowler
Martin Fowler
酷 壳 – CoolShell
酷 壳 – CoolShell
MongoDB | Blog
MongoDB | Blog
L
LangChain Blog

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
refactor(discord): split preflight and native command hel...
steipete · 2026-04-30 · via Recent Commits to openclaw:main

@@ -0,0 +1,86 @@

1+

import { logVerbose } from "openclaw/plugin-sdk/runtime-env";

2+

import { logDebug } from "openclaw/plugin-sdk/text-runtime";

3+

import {

4+

isDiscordGroupAllowedByPolicy,

5+

resolveGroupDmAllow,

6+

type DiscordChannelConfigResolved,

7+

type DiscordGuildEntryResolved,

8+

} from "./allow-list.js";

9+10+

export function resolveDiscordPreflightChannelAccess(params: {

11+

isGuildMessage: boolean;

12+

isGroupDm: boolean;

13+

groupPolicy: "open" | "disabled" | "allowlist";

14+

groupDmChannels?: string[];

15+

messageChannelId: string;

16+

displayChannelName?: string;

17+

displayChannelSlug: string;

18+

guildInfo: DiscordGuildEntryResolved | null;

19+

channelConfig: DiscordChannelConfigResolved | null;

20+

channelMatchMeta: string;

21+

}): { allowed: boolean; channelAllowlistConfigured: boolean; channelAllowed: boolean } {

22+

if (params.isGuildMessage && params.channelConfig?.enabled === false) {

23+

logDebug(`[discord-preflight] drop: channel disabled`);

24+

logVerbose(

25+

`Blocked discord channel ${params.messageChannelId} (channel disabled, ${params.channelMatchMeta})`,

26+

);

27+

return { allowed: false, channelAllowlistConfigured: false, channelAllowed: false };

28+

}

29+30+

const groupDmAllowed =

31+

params.isGroupDm &&

32+

resolveGroupDmAllow({

33+

channels: params.groupDmChannels,

34+

channelId: params.messageChannelId,

35+

channelName: params.displayChannelName,

36+

channelSlug: params.displayChannelSlug,

37+

});

38+

if (params.isGroupDm && !groupDmAllowed) {

39+

return { allowed: false, channelAllowlistConfigured: false, channelAllowed: false };

40+

}

41+42+

const channelAllowlistConfigured =

43+

Boolean(params.guildInfo?.channels) && Object.keys(params.guildInfo?.channels ?? {}).length > 0;

44+

const channelAllowed = params.channelConfig?.allowed !== false;

45+

if (

46+

params.isGuildMessage &&

47+

!isDiscordGroupAllowedByPolicy({

48+

groupPolicy: params.groupPolicy,

49+

guildAllowlisted: Boolean(params.guildInfo),

50+

channelAllowlistConfigured,

51+

channelAllowed,

52+

})

53+

) {

54+

if (params.groupPolicy === "disabled") {

55+

logDebug(`[discord-preflight] drop: groupPolicy disabled`);

56+

logVerbose(`discord: drop guild message (groupPolicy: disabled, ${params.channelMatchMeta})`);

57+

} else if (!channelAllowlistConfigured) {

58+

logDebug(`[discord-preflight] drop: groupPolicy allowlist, no channel allowlist configured`);

59+

logVerbose(

60+

`discord: drop guild message (groupPolicy: allowlist, no channel allowlist, ${params.channelMatchMeta})`,

61+

);

62+

} else {

63+

logDebug(

64+

`[discord] Ignored message from channel ${params.messageChannelId} (not in guild allowlist). Add to guilds.<guildId>.channels to enable.`,

65+

);

66+

logVerbose(

67+

`Blocked discord channel ${params.messageChannelId} not in guild channel allowlist (groupPolicy: allowlist, ${params.channelMatchMeta})`,

68+

);

69+

}

70+

return { allowed: false, channelAllowlistConfigured, channelAllowed };

71+

}

72+73+

if (params.isGuildMessage && params.channelConfig?.allowed === false) {

74+

logDebug(`[discord-preflight] drop: channelConfig.allowed===false`);

75+

logVerbose(

76+

`Blocked discord channel ${params.messageChannelId} not in guild channel allowlist (${params.channelMatchMeta})`,

77+

);

78+

return { allowed: false, channelAllowlistConfigured, channelAllowed };

79+

}

80+

if (params.isGuildMessage) {

81+

logDebug(`[discord-preflight] pass: channel allowed`);

82+

logVerbose(`discord: allow channel ${params.messageChannelId} (${params.channelMatchMeta})`);

83+

}

84+85+

return { allowed: true, channelAllowlistConfigured, channelAllowed };

86+

}