koishi-plugin-sy-bot 0.0.8 → 0.0.10
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/commands/Session.d.ts +112 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.js +60 -20
- package/lib/utils/utils.d.ts +5 -1
- package/package.json +6 -4
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
declare const Session: {
|
|
2
|
+
id: number;
|
|
3
|
+
sn: number;
|
|
4
|
+
event: {
|
|
5
|
+
selfId: string;
|
|
6
|
+
platform: string;
|
|
7
|
+
timestamp: number;
|
|
8
|
+
_type: string;
|
|
9
|
+
_data: {
|
|
10
|
+
time: number;
|
|
11
|
+
self_id: number;
|
|
12
|
+
event_type: string;
|
|
13
|
+
data: {
|
|
14
|
+
message_scene: string;
|
|
15
|
+
peer_id: number;
|
|
16
|
+
message_seq: number;
|
|
17
|
+
sender_id: number;
|
|
18
|
+
time: number;
|
|
19
|
+
segments: {
|
|
20
|
+
type: string;
|
|
21
|
+
data: {
|
|
22
|
+
text: string;
|
|
23
|
+
};
|
|
24
|
+
}[];
|
|
25
|
+
group: {
|
|
26
|
+
group_id: number;
|
|
27
|
+
group_name: string;
|
|
28
|
+
member_count: number;
|
|
29
|
+
max_member_count: number;
|
|
30
|
+
};
|
|
31
|
+
group_member: {
|
|
32
|
+
user_id: number;
|
|
33
|
+
nickname: string;
|
|
34
|
+
sex: string;
|
|
35
|
+
group_id: number;
|
|
36
|
+
card: string;
|
|
37
|
+
title: string;
|
|
38
|
+
level: number;
|
|
39
|
+
role: string;
|
|
40
|
+
join_time: number;
|
|
41
|
+
last_sent_time: number;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
type: string;
|
|
46
|
+
message: {
|
|
47
|
+
elements: {
|
|
48
|
+
type: string;
|
|
49
|
+
attrs: {
|
|
50
|
+
content: string;
|
|
51
|
+
};
|
|
52
|
+
children: any[];
|
|
53
|
+
}[];
|
|
54
|
+
content: string;
|
|
55
|
+
id: string;
|
|
56
|
+
};
|
|
57
|
+
channel: {
|
|
58
|
+
id: string;
|
|
59
|
+
type: number;
|
|
60
|
+
name: string;
|
|
61
|
+
};
|
|
62
|
+
user: {
|
|
63
|
+
id: string;
|
|
64
|
+
avatar: string;
|
|
65
|
+
name: string;
|
|
66
|
+
};
|
|
67
|
+
guild: {
|
|
68
|
+
id: string;
|
|
69
|
+
name: string;
|
|
70
|
+
avatar: string;
|
|
71
|
+
};
|
|
72
|
+
member: {
|
|
73
|
+
user: {
|
|
74
|
+
id: string;
|
|
75
|
+
name: string;
|
|
76
|
+
avatar: string;
|
|
77
|
+
};
|
|
78
|
+
nick: string;
|
|
79
|
+
avatar: string;
|
|
80
|
+
joinedAt: number;
|
|
81
|
+
roles: string[];
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
locales: any[];
|
|
85
|
+
_stripped: {
|
|
86
|
+
hasAt: boolean;
|
|
87
|
+
content: string;
|
|
88
|
+
appel: boolean;
|
|
89
|
+
atSelf: boolean;
|
|
90
|
+
prefix: string;
|
|
91
|
+
};
|
|
92
|
+
guild: {
|
|
93
|
+
permissions: any[];
|
|
94
|
+
locales: any[];
|
|
95
|
+
platform: string;
|
|
96
|
+
id: string;
|
|
97
|
+
};
|
|
98
|
+
channel: {
|
|
99
|
+
permissions: any[];
|
|
100
|
+
locales: any[];
|
|
101
|
+
platform: string;
|
|
102
|
+
id: string;
|
|
103
|
+
};
|
|
104
|
+
user: {
|
|
105
|
+
id: number;
|
|
106
|
+
flag: number;
|
|
107
|
+
authority: number;
|
|
108
|
+
permissions: any[];
|
|
109
|
+
locales: any[];
|
|
110
|
+
};
|
|
111
|
+
scope: string;
|
|
112
|
+
};
|
package/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Context, Schema } from "koishi";
|
|
2
2
|
export declare const name = "sy-bot";
|
|
3
|
+
export declare const usage = "\u8003\u7814\u7FA4\u7B54\u7591\u673A\u5668\u4EBA";
|
|
3
4
|
export declare const inject: {
|
|
4
5
|
required: string[];
|
|
5
6
|
};
|
|
@@ -7,6 +8,8 @@ export interface Config {
|
|
|
7
8
|
api: string;
|
|
8
9
|
model: string;
|
|
9
10
|
prompt: string;
|
|
11
|
+
guild: string;
|
|
12
|
+
user: string;
|
|
10
13
|
}
|
|
11
14
|
export declare const Config: Schema<Config>;
|
|
12
15
|
export declare function apply(ctx: Context, config: Config): void;
|
package/lib/index.js
CHANGED
|
@@ -33,7 +33,8 @@ __export(src_exports, {
|
|
|
33
33
|
Config: () => Config,
|
|
34
34
|
apply: () => apply,
|
|
35
35
|
inject: () => inject,
|
|
36
|
-
name: () => name
|
|
36
|
+
name: () => name,
|
|
37
|
+
usage: () => usage
|
|
37
38
|
});
|
|
38
39
|
module.exports = __toCommonJS(src_exports);
|
|
39
40
|
var import_koishi3 = require("koishi");
|
|
@@ -176,8 +177,7 @@ ${hljsCss}
|
|
|
176
177
|
logger.info("视口设置成功");
|
|
177
178
|
logger.info("开始加载内容...");
|
|
178
179
|
await page.setContent(html, {
|
|
179
|
-
waitUntil: "
|
|
180
|
-
timeout: 3e4
|
|
180
|
+
waitUntil: "networkidle0"
|
|
181
181
|
});
|
|
182
182
|
logger.info("内容加载成功");
|
|
183
183
|
logger.info("开始设置body...");
|
|
@@ -273,7 +273,10 @@ async function getAiChatResult({ config, user_query, ctx }) {
|
|
|
273
273
|
console.log("Gemini调用结果:\n", data);
|
|
274
274
|
const { content } = data.candidates[0];
|
|
275
275
|
logger.info("提取AI请求结果content:\n", content);
|
|
276
|
-
logger.info(
|
|
276
|
+
logger.info(
|
|
277
|
+
"过滤后的parts回复列表:\n",
|
|
278
|
+
data.candidates[0].content.parts.filter((part) => part.text)
|
|
279
|
+
);
|
|
277
280
|
const result = content.parts.filter((part) => part.text).map((part) => part.text).join("");
|
|
278
281
|
logger.info("AI回复的文字:", result);
|
|
279
282
|
return result;
|
|
@@ -328,7 +331,10 @@ async function getAiImgUnderstandMultiple({
|
|
|
328
331
|
BODY
|
|
329
332
|
);
|
|
330
333
|
logger.info("axios 接口返回的数据 data: \n", data);
|
|
331
|
-
logger.info(
|
|
334
|
+
logger.info(
|
|
335
|
+
"过滤后的parts回复列表:\n",
|
|
336
|
+
data.candidates[0].content.parts.filter((part) => part.text)
|
|
337
|
+
);
|
|
332
338
|
const text = data.candidates[0].content.parts.filter((part) => part.text).map((p) => p.text).join("");
|
|
333
339
|
logger.info("解析出的text:", text);
|
|
334
340
|
return text;
|
|
@@ -368,9 +374,15 @@ async function sendOnlyText({ session, ctx, config, query }) {
|
|
|
368
374
|
logger.info("开始渲染markdown...");
|
|
369
375
|
const h_ans_img = await textToImage(ctx, raw_answer);
|
|
370
376
|
logger.info("markdown渲染完毕!");
|
|
371
|
-
session
|
|
372
|
-
|
|
373
|
-
|
|
377
|
+
if (getSessionScene(session) == "group") {
|
|
378
|
+
session.send(
|
|
379
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("quote", { id: session.event.message.id }) + /* @__PURE__ */ (0, import_jsx_runtime.jsx)("at", { id: session.event.user.id }) + h_ans_img + "\n"
|
|
380
|
+
);
|
|
381
|
+
} else if (getSessionScene(session) == "friend") {
|
|
382
|
+
session.send(h_ans_img + "\n");
|
|
383
|
+
} else {
|
|
384
|
+
return "意外的回话类型!";
|
|
385
|
+
}
|
|
374
386
|
} catch (err) {
|
|
375
387
|
return "调用 textToImage 报错:" + (err instanceof Error ? err.message : String(err));
|
|
376
388
|
}
|
|
@@ -403,17 +415,36 @@ async function sendNotOnlyText({
|
|
|
403
415
|
logger.info("开始渲染markdown,执行textToImage");
|
|
404
416
|
const h_ans_img = await textToImage(ctx, raw_answer);
|
|
405
417
|
logger.info("渲染完毕,返回图片结果!");
|
|
406
|
-
session
|
|
407
|
-
|
|
408
|
-
|
|
418
|
+
if (getSessionScene(session) == "group") {
|
|
419
|
+
session.send(
|
|
420
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("quote", { id: session.event.message.id }) + /* @__PURE__ */ (0, import_jsx_runtime.jsx)("at", { id: session.event.user.id }) + h_ans_img + "\n"
|
|
421
|
+
);
|
|
422
|
+
} else if (getSessionScene(session) == "friend") {
|
|
423
|
+
session.send(
|
|
424
|
+
h_ans_img + "\n"
|
|
425
|
+
);
|
|
426
|
+
} else {
|
|
427
|
+
return "意外的会话类型";
|
|
428
|
+
}
|
|
409
429
|
}
|
|
410
430
|
__name(sendNotOnlyText, "sendNotOnlyText");
|
|
431
|
+
function getSessionScene(session) {
|
|
432
|
+
return session.event._data.data.message_scene;
|
|
433
|
+
}
|
|
434
|
+
__name(getSessionScene, "getSessionScene");
|
|
411
435
|
|
|
412
436
|
// src/commands/ask.tsx
|
|
413
437
|
function registerAsk(ctx, config) {
|
|
414
438
|
ctx.command("ask", "哈基米?哈基米~").action(async ({ session }) => {
|
|
439
|
+
const logger = ctx.logger("sy-bot");
|
|
440
|
+
logger.info("本次会话的类型: ", getSessionScene(session));
|
|
441
|
+
logger.info("会话用户: ", session.event.user.id);
|
|
415
442
|
try {
|
|
416
|
-
|
|
443
|
+
if (session.event.guild?.id != config.guild && session.event.user.id !== config.user) {
|
|
444
|
+
logger.info("非目标请求,请检查群id和qq号,会话拒绝~");
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
logger.info("本次 session: \n", session);
|
|
417
448
|
const messageElements = session.event.message.elements;
|
|
418
449
|
const quoteElements = session.event.message.quote?.elements;
|
|
419
450
|
const quoteRealText = getElementsText(quoteElements);
|
|
@@ -424,7 +455,12 @@ function registerAsk(ctx, config) {
|
|
|
424
455
|
const finalImages = [...quoteImages, ...messageImages];
|
|
425
456
|
logger.info("用户输入的图像:", finalImages);
|
|
426
457
|
logger.info("用户输入的文字:", finalText);
|
|
427
|
-
await startEmoji(session);
|
|
458
|
+
if (getSessionScene(session) == "group") await startEmoji(session);
|
|
459
|
+
else if (getSessionScene(session) == "friend") {
|
|
460
|
+
session.send("思考中...");
|
|
461
|
+
} else {
|
|
462
|
+
return "意外的回话类型!";
|
|
463
|
+
}
|
|
428
464
|
logger.info("发送表情响应");
|
|
429
465
|
if (finalImages.length > 0) {
|
|
430
466
|
logger.info("用户发送了图片,调用图片理解api...");
|
|
@@ -444,11 +480,11 @@ function registerAsk(ctx, config) {
|
|
|
444
480
|
logger.info("sendOnlyText执行结束");
|
|
445
481
|
}
|
|
446
482
|
} catch (err) {
|
|
447
|
-
const
|
|
448
|
-
|
|
483
|
+
const logger2 = ctx.logger("sy-bot");
|
|
484
|
+
logger2.error("ask 命令执行错误:", err);
|
|
449
485
|
return "oops!出了点叉子!";
|
|
450
486
|
} finally {
|
|
451
|
-
await finishEmoji(session);
|
|
487
|
+
if (getSessionScene(session) == "group") await finishEmoji(session);
|
|
452
488
|
}
|
|
453
489
|
});
|
|
454
490
|
}
|
|
@@ -576,13 +612,16 @@ __name(registerTables, "registerTables");
|
|
|
576
612
|
|
|
577
613
|
// src/index.ts
|
|
578
614
|
var name = "sy-bot";
|
|
615
|
+
var usage = "考研群答疑机器人";
|
|
579
616
|
var inject = {
|
|
580
617
|
required: ["database", "puppeteer"]
|
|
581
618
|
};
|
|
582
619
|
var Config = import_koishi3.Schema.object({
|
|
583
|
-
api: import_koishi3.Schema.string().required(),
|
|
584
|
-
model: import_koishi3.Schema.string().required(),
|
|
585
|
-
prompt: import_koishi3.Schema.string()
|
|
620
|
+
api: import_koishi3.Schema.string().required().description("青云☁️ Gemini API(必填)"),
|
|
621
|
+
model: import_koishi3.Schema.string().required().description("模型名称(必填)"),
|
|
622
|
+
prompt: import_koishi3.Schema.string().description("预设系统提示词(可以留空)"),
|
|
623
|
+
guild: import_koishi3.Schema.string().description("在目标群聊启用,留空表示广播所有群聊(填入QQ群号)"),
|
|
624
|
+
user: import_koishi3.Schema.string().required().description("在目标用户启用(填入管理员QQ号)")
|
|
586
625
|
});
|
|
587
626
|
function apply(ctx, config) {
|
|
588
627
|
registerCommand(ctx, config);
|
|
@@ -594,5 +633,6 @@ __name(apply, "apply");
|
|
|
594
633
|
Config,
|
|
595
634
|
apply,
|
|
596
635
|
inject,
|
|
597
|
-
name
|
|
636
|
+
name,
|
|
637
|
+
usage
|
|
598
638
|
});
|
package/lib/utils/utils.d.ts
CHANGED
|
@@ -37,5 +37,9 @@ export declare function sendNotOnlyText({ ctx, config, session, url_list, query,
|
|
|
37
37
|
session: any;
|
|
38
38
|
url_list: any;
|
|
39
39
|
query: any;
|
|
40
|
-
}): Promise<
|
|
40
|
+
}): Promise<string>;
|
|
41
41
|
export declare function cutBeginAsk(str: any): any;
|
|
42
|
+
declare const SessionScene: readonly ["group", "friend"];
|
|
43
|
+
type SessionScene = (typeof SessionScene)[number];
|
|
44
|
+
export declare function getSessionScene(session: Session): SessionScene;
|
|
45
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "koishi-plugin-sy-bot",
|
|
3
3
|
"description": "考研群答疑Bot,接入Gemini。",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.10",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
7
7
|
"files": [
|
|
@@ -12,8 +12,9 @@
|
|
|
12
12
|
"scripts": {
|
|
13
13
|
"dev": "cd ../.. && npm run dev",
|
|
14
14
|
"build": "cd ../.. && npm run build",
|
|
15
|
-
"
|
|
16
|
-
"pub": "cd ../.. && npm run pub"
|
|
15
|
+
"v": "cd ../.. && npm run build && npm run bump",
|
|
16
|
+
"pub": "cd ../.. && npm run pub",
|
|
17
|
+
"login": "cd ../.. && npm login"
|
|
17
18
|
},
|
|
18
19
|
"keywords": [
|
|
19
20
|
"chatbot",
|
|
@@ -29,6 +30,7 @@
|
|
|
29
30
|
"axios": "^1.13.2",
|
|
30
31
|
"highlight": "^0.2.4",
|
|
31
32
|
"highlight.js": "^11.11.1",
|
|
32
|
-
"markdown-it": "^14.1.0"
|
|
33
|
+
"markdown-it": "^14.1.0",
|
|
34
|
+
"node-cron": "^4.2.1"
|
|
33
35
|
}
|
|
34
36
|
}
|