mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 12:17:40 +00:00
refactor(discord): reuse preflight param types
This commit is contained in:
@@ -1,9 +1,6 @@
|
|||||||
import type { Client } from "@buape/carbon";
|
import type { Client } from "@buape/carbon";
|
||||||
import type { HistoryEntry } from "../../auto-reply/reply/history.js";
|
|
||||||
import type { ReplyToMode } from "../../config/config.js";
|
|
||||||
import type { RuntimeEnv } from "../../runtime.js";
|
|
||||||
import type { DiscordGuildEntryResolved } from "./allow-list.js";
|
|
||||||
import type { DiscordMessageEvent, DiscordMessageHandler } from "./listeners.js";
|
import type { DiscordMessageEvent, DiscordMessageHandler } from "./listeners.js";
|
||||||
|
import type { DiscordMessagePreflightParams } from "./message-handler.preflight.types.js";
|
||||||
import { hasControlCommand } from "../../auto-reply/command-detection.js";
|
import { hasControlCommand } from "../../auto-reply/command-detection.js";
|
||||||
import {
|
import {
|
||||||
createInboundDebouncer,
|
createInboundDebouncer,
|
||||||
@@ -14,29 +11,14 @@ import { preflightDiscordMessage } from "./message-handler.preflight.js";
|
|||||||
import { processDiscordMessage } from "./message-handler.process.js";
|
import { processDiscordMessage } from "./message-handler.process.js";
|
||||||
import { resolveDiscordMessageText } from "./message-utils.js";
|
import { resolveDiscordMessageText } from "./message-utils.js";
|
||||||
|
|
||||||
type LoadedConfig = ReturnType<typeof import("../../config/config.js").loadConfig>;
|
type DiscordMessageHandlerParams = Omit<
|
||||||
type DiscordConfig = NonNullable<
|
DiscordMessagePreflightParams,
|
||||||
import("../../config/config.js").OpenClawConfig["channels"]
|
"ackReactionScope" | "groupPolicy" | "data" | "client"
|
||||||
>["discord"];
|
>;
|
||||||
|
|
||||||
export function createDiscordMessageHandler(params: {
|
export function createDiscordMessageHandler(
|
||||||
cfg: LoadedConfig;
|
params: DiscordMessageHandlerParams,
|
||||||
discordConfig: DiscordConfig;
|
): DiscordMessageHandler {
|
||||||
accountId: string;
|
|
||||||
token: string;
|
|
||||||
runtime: RuntimeEnv;
|
|
||||||
botUserId?: string;
|
|
||||||
guildHistories: Map<string, HistoryEntry[]>;
|
|
||||||
historyLimit: number;
|
|
||||||
mediaMaxBytes: number;
|
|
||||||
textLimit: number;
|
|
||||||
replyToMode: ReplyToMode;
|
|
||||||
dmEnabled: boolean;
|
|
||||||
groupDmEnabled: boolean;
|
|
||||||
groupDmChannels?: Array<string | number>;
|
|
||||||
allowFrom?: Array<string | number>;
|
|
||||||
guildEntries?: Record<string, DiscordGuildEntryResolved>;
|
|
||||||
}): DiscordMessageHandler {
|
|
||||||
const groupPolicy = params.discordConfig?.groupPolicy ?? "open";
|
const groupPolicy = params.discordConfig?.groupPolicy ?? "open";
|
||||||
const ackReactionScope = params.cfg.messages?.ackReactionScope ?? "group-mentions";
|
const ackReactionScope = params.cfg.messages?.ackReactionScope ?? "group-mentions";
|
||||||
const debounceMs = resolveInboundDebounceMs({ cfg: params.cfg, channel: "discord" });
|
const debounceMs = resolveInboundDebounceMs({ cfg: params.cfg, channel: "discord" });
|
||||||
|
|||||||
Reference in New Issue
Block a user