mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 15:54:32 +00:00
refactor: unify inbound debounce policy and split gateway/models helpers
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
import type { Client } from "@buape/carbon";
|
||||
import { hasControlCommand } from "../../auto-reply/command-detection.js";
|
||||
import {
|
||||
createInboundDebouncer,
|
||||
resolveInboundDebounceMs,
|
||||
} from "../../auto-reply/inbound-debounce.js";
|
||||
createChannelInboundDebouncer,
|
||||
shouldDebounceTextInbound,
|
||||
} from "../../channels/inbound-debounce-policy.js";
|
||||
import { resolveOpenProviderRuntimeGroupPolicy } from "../../config/runtime-group-policy.js";
|
||||
import { danger } from "../../globals.js";
|
||||
import type { DiscordMessageEvent, DiscordMessageHandler } from "./listeners.js";
|
||||
@@ -33,10 +32,12 @@ export function createDiscordMessageHandler(
|
||||
params.discordConfig?.ackReactionScope ??
|
||||
params.cfg.messages?.ackReactionScope ??
|
||||
"group-mentions";
|
||||
const debounceMs = resolveInboundDebounceMs({ cfg: params.cfg, channel: "discord" });
|
||||
|
||||
const debouncer = createInboundDebouncer<{ data: DiscordMessageEvent; client: Client }>({
|
||||
debounceMs,
|
||||
const { debouncer } = createChannelInboundDebouncer<{
|
||||
data: DiscordMessageEvent;
|
||||
client: Client;
|
||||
}>({
|
||||
cfg: params.cfg,
|
||||
channel: "discord",
|
||||
buildKey: (entry) => {
|
||||
const message = entry.data.message;
|
||||
const authorId = entry.data.author?.id;
|
||||
@@ -57,17 +58,15 @@ export function createDiscordMessageHandler(
|
||||
if (!message) {
|
||||
return false;
|
||||
}
|
||||
if (message.attachments && message.attachments.length > 0) {
|
||||
return false;
|
||||
}
|
||||
if (hasDiscordMessageStickers(message)) {
|
||||
return false;
|
||||
}
|
||||
const baseText = resolveDiscordMessageText(message, { includeForwarded: false });
|
||||
if (!baseText.trim()) {
|
||||
return false;
|
||||
}
|
||||
return !hasControlCommand(baseText, params.cfg);
|
||||
return shouldDebounceTextInbound({
|
||||
text: baseText,
|
||||
cfg: params.cfg,
|
||||
hasMedia: Boolean(
|
||||
(message.attachments && message.attachments.length > 0) ||
|
||||
hasDiscordMessageStickers(message),
|
||||
),
|
||||
});
|
||||
},
|
||||
onFlush: async (entries) => {
|
||||
const last = entries.at(-1);
|
||||
|
||||
Reference in New Issue
Block a user