From 9356ae18bc75fff8361febe28289b6afdbfe2c8a Mon Sep 17 00:00:00 2001 From: cannorin Date: Tue, 24 Feb 2026 22:21:29 +0900 Subject: [PATCH] Refactor (5) --- index.ts | 16 +++++++++++----- lib/misskey.ts | 6 ++++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/index.ts b/index.ts index 8e28cdb..84b3e3f 100644 --- a/index.ts +++ b/index.ts @@ -1,10 +1,16 @@ import { parseArgs } from "node:util"; import { Stream } from "misskey-js"; import type { Note } from "misskey-js/entities.js"; -import { LlmSession, createGrammar, getModel, parseResponse } from "./lib/llm"; -import { expandReplyTree, getNotes, me, misskey } from "./lib/misskey"; -import { sleep } from "./lib/util"; import type { ChatHistoryItem, LLamaChatPromptOptions } from "node-llama-cpp"; +import { LlmSession, createGrammar, getModel, parseResponse } from "./lib/llm"; +import { + expandReplyTree, + getNotes, + me, + misskey, + sanitizeText, +} from "./lib/misskey"; +import { sleep } from "./lib/util"; const { values } = parseArgs({ args: Bun.argv, @@ -110,7 +116,7 @@ async function processPostJob() { if (values.test) return; await misskey.request("notes/create", { visibility: "public", - text: rephrased, + text: sanitizeText(rephrased), }); } } @@ -142,7 +148,7 @@ async function processReplyJob(job: Extract) { if (values.test) return; await misskey.request("notes/create", { visibility: job.visibility, - text: rephrased, + text: sanitizeText(rephrased), replyId: job.id, }); } diff --git a/lib/misskey.ts b/lib/misskey.ts index e0d1aab..496c70c 100644 --- a/lib/misskey.ts +++ b/lib/misskey.ts @@ -72,3 +72,9 @@ export async function expandReplyTree( } return { last: current, history: history.reverse() }; } + +export const sanitizeText = (text: string) => + text + .replaceAll(/(\r\n|\r|\n)\s+/g, "\n\n") // remove extra newlines + .replaceAll("@", "") // remove mentions + .replaceAll("#", ""); // remove hashtags