mirror of
https://github.com/moltbot/moltbot.git
synced 2026-04-24 07:01:49 +00:00
fix(regression): align irc send helper runtime usage
This commit is contained in:
@@ -40,6 +40,22 @@ vi.mock("./protocol.js", async () => {
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("openclaw/plugin-sdk/config-runtime", async (importOriginal) => {
|
||||
const original = (await importOriginal()) as Record<string, unknown>;
|
||||
return {
|
||||
...original,
|
||||
resolveMarkdownTableMode: hoisted.resolveMarkdownTableMode,
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("openclaw/plugin-sdk/text-runtime", async (importOriginal) => {
|
||||
const original = (await importOriginal()) as Record<string, unknown>;
|
||||
return {
|
||||
...original,
|
||||
convertMarkdownTables: hoisted.convertMarkdownTables,
|
||||
};
|
||||
});
|
||||
|
||||
import { sendMessageIrc } from "./send.js";
|
||||
|
||||
describe("sendMessageIrc cfg threading", () => {
|
||||
@@ -111,4 +127,33 @@ describe("sendMessageIrc cfg threading", () => {
|
||||
direction: "outbound",
|
||||
});
|
||||
});
|
||||
|
||||
it("sends with provided cfg even when the runtime store is not initialized", async () => {
|
||||
const providedCfg = {
|
||||
channels: {
|
||||
irc: {
|
||||
host: "irc.example.com",
|
||||
nick: "openclaw",
|
||||
},
|
||||
},
|
||||
} as unknown as CoreConfig;
|
||||
const client = {
|
||||
isReady: vi.fn(() => true),
|
||||
sendPrivmsg: vi.fn(),
|
||||
} as unknown as IrcClient;
|
||||
hoisted.record.mockImplementation(() => {
|
||||
throw new Error("IRC runtime not initialized");
|
||||
});
|
||||
|
||||
const result = await sendMessageIrc("#room", "hello", {
|
||||
cfg: providedCfg,
|
||||
client,
|
||||
});
|
||||
|
||||
expect(hoisted.loadConfig).not.toHaveBeenCalled();
|
||||
expect(client.sendPrivmsg).toHaveBeenCalledWith("#room", "hello");
|
||||
expect(result.target).toBe("#room");
|
||||
expect(result.messageId).toEqual(expect.any(String));
|
||||
expect(result.messageId.length).toBeGreaterThan(0);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { resolveMarkdownTableMode } from "openclaw/plugin-sdk/config-runtime";
|
||||
import { convertMarkdownTables } from "openclaw/plugin-sdk/text-runtime";
|
||||
import { resolveIrcAccount } from "./accounts.js";
|
||||
import type { IrcClient } from "./client.js";
|
||||
import { connectIrcClient } from "./client.js";
|
||||
@@ -20,6 +22,20 @@ export type SendIrcResult = {
|
||||
target: string;
|
||||
};
|
||||
|
||||
function recordIrcOutboundActivity(accountId: string): void {
|
||||
try {
|
||||
getIrcRuntime().channel.activity.record({
|
||||
channel: "irc",
|
||||
accountId,
|
||||
direction: "outbound",
|
||||
});
|
||||
} catch (error) {
|
||||
if (!(error instanceof Error) || error.message !== "IRC runtime not initialized") {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function resolveTarget(to: string, opts?: SendIrcOptions): string {
|
||||
const fromArg = normalizeIrcMessagingTarget(to);
|
||||
if (fromArg) {
|
||||
@@ -51,12 +67,12 @@ export async function sendMessageIrc(
|
||||
}
|
||||
|
||||
const target = resolveTarget(to, opts);
|
||||
const tableMode = runtime.channel.text.resolveMarkdownTableMode({
|
||||
const tableMode = resolveMarkdownTableMode({
|
||||
cfg,
|
||||
channel: "irc",
|
||||
accountId: account.accountId,
|
||||
});
|
||||
const prepared = runtime.channel.text.convertMarkdownTables(text.trim(), tableMode);
|
||||
const prepared = convertMarkdownTables(text.trim(), tableMode);
|
||||
const payload = opts.replyTo ? `${prepared}\n\n[reply:${opts.replyTo}]` : prepared;
|
||||
|
||||
if (!payload.trim()) {
|
||||
@@ -76,11 +92,7 @@ export async function sendMessageIrc(
|
||||
transient.quit("sent");
|
||||
}
|
||||
|
||||
runtime.channel.activity.record({
|
||||
channel: "irc",
|
||||
accountId: account.accountId,
|
||||
direction: "outbound",
|
||||
});
|
||||
recordIrcOutboundActivity(account.accountId);
|
||||
|
||||
return {
|
||||
messageId: makeIrcMessageId(),
|
||||
|
||||
Reference in New Issue
Block a user