koishi-plugin-cocoyyy-console 1.2.2-alpha.3 → 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js
CHANGED
|
@@ -1827,6 +1827,7 @@ __name(parseSegments, "parseSegments");
|
|
|
1827
1827
|
function parseOneBotForwardNodes(nodes, depth = 0) {
|
|
1828
1828
|
const allTexts = [];
|
|
1829
1829
|
const allImageUrls = [];
|
|
1830
|
+
logger.info("[parseOneBotForwardNodes Info]:Depth [" + depth + "], parse node count : " + nodes.length);
|
|
1830
1831
|
for (const node of nodes) {
|
|
1831
1832
|
const sender = node?.sender?.nickname ?? String(node?.sender?.user_id ?? "未知");
|
|
1832
1833
|
const segments = node?.message ?? node?.content ?? [];
|
|
@@ -1847,47 +1848,23 @@ function extractForwardId(elements, content) {
|
|
|
1847
1848
|
}
|
|
1848
1849
|
__name(extractForwardId, "extractForwardId");
|
|
1849
1850
|
async function checkShitOrNot(session, parttern_msg, config) {
|
|
1850
|
-
chatHistory = [];
|
|
1851
|
-
chatHistory.push({ role: "system", content: [{ type: "text", text: parttern_msg }] });
|
|
1852
|
-
const quoteContent = session.quote.content;
|
|
1853
|
-
logger.info("[checkShitOrNot Info]: 引用消息内容: " + quoteContent);
|
|
1854
|
-
const { imageUrls, text } = extractImageAndText(quoteContent);
|
|
1855
|
-
if (!text && imageUrls.length === 0) {
|
|
1856
|
-
logger.warn("[checkShitOrNot Warn]: 引用消息中未发现文本或图片");
|
|
1857
|
-
return "引用消息中未发现文本或图片";
|
|
1858
|
-
}
|
|
1859
|
-
logger.info("[checkShitOrNot Info]: 提取图片 URL: " + imageUrls.join(", "));
|
|
1860
|
-
const targetContent = [
|
|
1861
|
-
...text ? [{ type: "text", text }] : [],
|
|
1862
|
-
...imageUrls.map((url) => ({ type: "image_url", image_url: { url } }))
|
|
1863
|
-
];
|
|
1864
|
-
chatHistory.push({ role: "user", content: targetContent });
|
|
1865
|
-
const { err: err2, resp: resp2 } = await callOpenRouter(config.api_url, config.api_key, config.api_model, chatHistory);
|
|
1866
|
-
if (err2 != null) {
|
|
1867
|
-
logger.error("[checkShitOrNot Error]: " + err2);
|
|
1868
|
-
return null;
|
|
1869
|
-
}
|
|
1870
|
-
return resp2;
|
|
1871
|
-
}
|
|
1872
|
-
__name(checkShitOrNot, "checkShitOrNot");
|
|
1873
|
-
async function checkShitOrNot_v2(session, parttern_msg, config) {
|
|
1874
1851
|
chatHistory = [];
|
|
1875
1852
|
chatHistory.push({ role: "system", content: [{ type: "text", text: parttern_msg }] });
|
|
1876
1853
|
const quoteContent = session.quote.content;
|
|
1877
1854
|
const quoteElements = session.quote.elements ?? [];
|
|
1878
|
-
logger.info("[
|
|
1879
|
-
logger.info("[
|
|
1855
|
+
logger.info("[checkShitOrNot Info]: 引用消息内容: " + quoteContent);
|
|
1856
|
+
logger.info("[checkShitOrNot Info]: quoteElements 长度: " + quoteElements.length);
|
|
1880
1857
|
let imageUrls = [];
|
|
1881
1858
|
let text = "";
|
|
1882
1859
|
let isForward = false;
|
|
1883
1860
|
const forwardId = extractForwardId(quoteElements, quoteContent);
|
|
1884
1861
|
if (forwardId) {
|
|
1885
1862
|
isForward = true;
|
|
1886
|
-
logger.info("[
|
|
1863
|
+
logger.info("[checkShitOrNot Info]: 检测到转发聊天记录,ID: " + forwardId);
|
|
1887
1864
|
const forwardEl = quoteElements.find((el) => el.type === "forward");
|
|
1888
1865
|
const attrContent = Array.isArray(forwardEl?.attrs?.content) ? forwardEl.attrs.content : [];
|
|
1889
1866
|
if (attrContent.length > 0) {
|
|
1890
|
-
logger.info("[
|
|
1867
|
+
logger.info("[checkShitOrNot Info]: 从 attrs.content 提取转发内容,共 " + attrContent.length + " 条");
|
|
1891
1868
|
const extracted = parseOneBotForwardNodes(attrContent);
|
|
1892
1869
|
imageUrls = extracted.imageUrls;
|
|
1893
1870
|
text = extracted.text;
|
|
@@ -1898,10 +1875,10 @@ async function checkShitOrNot_v2(session, parttern_msg, config) {
|
|
|
1898
1875
|
text = extracted.text;
|
|
1899
1876
|
}
|
|
1900
1877
|
if (!text && imageUrls.length === 0) {
|
|
1901
|
-
logger.warn("[
|
|
1878
|
+
logger.warn("[checkShitOrNot Warn]: 引用消息中未发现文本或图片");
|
|
1902
1879
|
return isForward ? "转发聊天记录中未发现可分析的文本或图片" : "引用消息中未发现文本或图片";
|
|
1903
1880
|
}
|
|
1904
|
-
logger.info("[
|
|
1881
|
+
logger.info("[checkShitOrNot Info]: 提取文本长度: " + text.length + ",图片数: " + imageUrls.length);
|
|
1905
1882
|
const displayText = isForward ? `以下是转发聊天记录的内容:
|
|
1906
1883
|
|
|
1907
1884
|
${text}` : text;
|
|
@@ -1912,12 +1889,12 @@ ${text}` : text;
|
|
|
1912
1889
|
chatHistory.push({ role: "user", content: targetContent });
|
|
1913
1890
|
const { err: err2, resp: resp2 } = await callOpenRouter(config.api_url, config.api_key, config.api_model, chatHistory);
|
|
1914
1891
|
if (err2 != null) {
|
|
1915
|
-
logger.error("[
|
|
1892
|
+
logger.error("[checkShitOrNot Error]: " + err2);
|
|
1916
1893
|
return null;
|
|
1917
1894
|
}
|
|
1918
1895
|
return resp2;
|
|
1919
1896
|
}
|
|
1920
|
-
__name(
|
|
1897
|
+
__name(checkShitOrNot, "checkShitOrNot");
|
|
1921
1898
|
|
|
1922
1899
|
// src/services/son_func/shit_or_not_command.ts
|
|
1923
1900
|
var local_config = null;
|
|
@@ -1964,26 +1941,6 @@ son判断模式列表:
|
|
|
1964
1941
|
think_flag = false;
|
|
1965
1942
|
}
|
|
1966
1943
|
});
|
|
1967
|
-
ctx.command("sonv2 <参数>", "判定是否为史").action(async ({ session }, ...args) => {
|
|
1968
|
-
if (!dev_mode) {
|
|
1969
|
-
if (!is_at_bot_quote(session)) return "请提供正确格式,如: [引用消息] @bot son [判断模式]";
|
|
1970
|
-
}
|
|
1971
|
-
if (think_flag) return "请等待思考结果";
|
|
1972
|
-
const parttern = args?.[0];
|
|
1973
|
-
if (!parttern) return "请提供正确判断模式,如: [引用消息] @bot son [判断模式]";
|
|
1974
|
-
if (!local_config) return "未加载配置文件,请查看日志";
|
|
1975
|
-
const parttern_msg = local_config.shit_or_not?.prompts[parttern];
|
|
1976
|
-
if (!parttern_msg) return "未找到判断模式,请查看日志";
|
|
1977
|
-
await session.send("已收到,正在品鉴中...");
|
|
1978
|
-
think_flag = true;
|
|
1979
|
-
try {
|
|
1980
|
-
let exec = await checkShitOrNot_v2(session, parttern_msg, ai_config);
|
|
1981
|
-
if (exec == null) return "品鉴失败,请查看日志";
|
|
1982
|
-
return exec;
|
|
1983
|
-
} finally {
|
|
1984
|
-
think_flag = false;
|
|
1985
|
-
}
|
|
1986
|
-
});
|
|
1987
1944
|
}
|
|
1988
1945
|
__name(registerShitOrNotCommands, "registerShitOrNotCommands");
|
|
1989
1946
|
function extractAtId(content) {
|
|
@@ -2,5 +2,4 @@ import { Session } from 'koishi';
|
|
|
2
2
|
import { AiAPIConfig } from '../../config/config';
|
|
3
3
|
declare function ocrImage(buffer: Buffer): Promise<string>;
|
|
4
4
|
declare function checkShitOrNot(session: Session, parttern_msg: string, config: AiAPIConfig): Promise<string>;
|
|
5
|
-
|
|
6
|
-
export { checkShitOrNot, checkShitOrNot_v2, ocrImage };
|
|
5
|
+
export { checkShitOrNot, ocrImage };
|