mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-01 20:31:19 +00:00
* refactor: move Discord channel implementation to extensions/discord/src/ Move all Discord source files from src/discord/ to extensions/discord/src/, following the extension migration pattern. Source files in src/discord/ are replaced with re-export shims. Channel-plugin files from src/channels/plugins/*/discord* are similarly moved and shimmed. - Copy all .ts source files preserving subdirectory structure (monitor/, voice/) - Move channel-plugin files (actions, normalize, onboarding, outbound, status-issues) - Fix all relative imports to use correct paths from new location - Create re-export shims at original locations for backward compatibility - Delete test files from shim locations (tests live in extension now) - Update tsconfig.plugin-sdk.dts.json rootDir from "src" to "." to accommodate extension files outside src/ - Update write-plugin-sdk-entry-dts.ts to match new declaration output paths * fix: add importOriginal to thread-bindings session-meta mock for extensions test * style: fix formatting in thread-bindings lifecycle test
100 lines
2.9 KiB
TypeScript
100 lines
2.9 KiB
TypeScript
import fs from "node:fs/promises";
|
|
import os from "node:os";
|
|
import path from "node:path";
|
|
import type { DiscordMessagePreflightContext } from "./message-handler.preflight.js";
|
|
import { createNoopThreadBindingManager } from "./thread-bindings.js";
|
|
|
|
export async function createBaseDiscordMessageContext(
|
|
overrides: Record<string, unknown> = {},
|
|
): Promise<DiscordMessagePreflightContext> {
|
|
const dir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-discord-"));
|
|
const storePath = path.join(dir, "sessions.json");
|
|
return {
|
|
cfg: { messages: { ackReaction: "👀" }, session: { store: storePath } },
|
|
discordConfig: {},
|
|
accountId: "default",
|
|
token: "token",
|
|
runtime: { log: () => {}, error: () => {} },
|
|
guildHistories: new Map(),
|
|
historyLimit: 0,
|
|
mediaMaxBytes: 1024,
|
|
textLimit: 4000,
|
|
sender: { label: "user" },
|
|
replyToMode: "off",
|
|
ackReactionScope: "group-mentions",
|
|
groupPolicy: "open",
|
|
data: { guild: { id: "g1", name: "Guild" } },
|
|
client: { rest: {} },
|
|
message: {
|
|
id: "m1",
|
|
channelId: "c1",
|
|
timestamp: new Date().toISOString(),
|
|
attachments: [],
|
|
},
|
|
messageChannelId: "c1",
|
|
author: {
|
|
id: "U1",
|
|
username: "alice",
|
|
discriminator: "0",
|
|
globalName: "Alice",
|
|
},
|
|
channelInfo: { name: "general" },
|
|
channelName: "general",
|
|
isGuildMessage: true,
|
|
isDirectMessage: false,
|
|
isGroupDm: false,
|
|
commandAuthorized: true,
|
|
baseText: "hi",
|
|
messageText: "hi",
|
|
wasMentioned: false,
|
|
shouldRequireMention: true,
|
|
canDetectMention: true,
|
|
effectiveWasMentioned: true,
|
|
shouldBypassMention: false,
|
|
threadChannel: null,
|
|
threadParentId: undefined,
|
|
threadParentName: undefined,
|
|
threadParentType: undefined,
|
|
threadName: undefined,
|
|
displayChannelSlug: "general",
|
|
guildInfo: null,
|
|
guildSlug: "guild",
|
|
channelConfig: null,
|
|
baseSessionKey: "agent:main:discord:guild:g1",
|
|
route: {
|
|
agentId: "main",
|
|
channel: "discord",
|
|
accountId: "default",
|
|
sessionKey: "agent:main:discord:guild:g1",
|
|
mainSessionKey: "agent:main:main",
|
|
},
|
|
threadBindings: createNoopThreadBindingManager("default"),
|
|
...overrides,
|
|
} as unknown as DiscordMessagePreflightContext;
|
|
}
|
|
|
|
export function createDiscordDirectMessageContextOverrides(): Record<string, unknown> {
|
|
return {
|
|
data: { guild: null },
|
|
channelInfo: null,
|
|
channelName: undefined,
|
|
isGuildMessage: false,
|
|
isDirectMessage: true,
|
|
isGroupDm: false,
|
|
shouldRequireMention: false,
|
|
canDetectMention: false,
|
|
effectiveWasMentioned: false,
|
|
displayChannelSlug: "",
|
|
guildInfo: null,
|
|
guildSlug: "",
|
|
baseSessionKey: "agent:main:discord:direct:u1",
|
|
route: {
|
|
agentId: "main",
|
|
channel: "discord",
|
|
accountId: "default",
|
|
sessionKey: "agent:main:discord:direct:u1",
|
|
mainSessionKey: "agent:main:main",
|
|
},
|
|
};
|
|
}
|