koishi-plugin-sy-bot 0.0.9 → 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.
@@ -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");
@@ -272,7 +273,10 @@ async function getAiChatResult({ config, user_query, ctx }) {
272
273
  console.log("Gemini调用结果:\n", data);
273
274
  const { content } = data.candidates[0];
274
275
  logger.info("提取AI请求结果content:\n", content);
275
- logger.info("过滤后的parts回复列表:\n", data.candidates[0].content.parts.filter((part) => part.text));
276
+ logger.info(
277
+ "过滤后的parts回复列表:\n",
278
+ data.candidates[0].content.parts.filter((part) => part.text)
279
+ );
276
280
  const result = content.parts.filter((part) => part.text).map((part) => part.text).join("");
277
281
  logger.info("AI回复的文字:", result);
278
282
  return result;
@@ -327,7 +331,10 @@ async function getAiImgUnderstandMultiple({
327
331
  BODY
328
332
  );
329
333
  logger.info("axios 接口返回的数据 data: \n", data);
330
- logger.info("过滤后的parts回复列表:\n", data.candidates[0].content.parts.filter((part) => part.text));
334
+ logger.info(
335
+ "过滤后的parts回复列表:\n",
336
+ data.candidates[0].content.parts.filter((part) => part.text)
337
+ );
331
338
  const text = data.candidates[0].content.parts.filter((part) => part.text).map((p) => p.text).join("");
332
339
  logger.info("解析出的text:", text);
333
340
  return text;
@@ -367,9 +374,15 @@ async function sendOnlyText({ session, ctx, config, query }) {
367
374
  logger.info("开始渲染markdown...");
368
375
  const h_ans_img = await textToImage(ctx, raw_answer);
369
376
  logger.info("markdown渲染完毕!");
370
- session.send(
371
- /* @__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"
372
- );
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
+ }
373
386
  } catch (err) {
374
387
  return "调用 textToImage 报错:" + (err instanceof Error ? err.message : String(err));
375
388
  }
@@ -402,17 +415,36 @@ async function sendNotOnlyText({
402
415
  logger.info("开始渲染markdown,执行textToImage");
403
416
  const h_ans_img = await textToImage(ctx, raw_answer);
404
417
  logger.info("渲染完毕,返回图片结果!");
405
- session.send(
406
- /* @__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"
407
- );
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
+ }
408
429
  }
409
430
  __name(sendNotOnlyText, "sendNotOnlyText");
431
+ function getSessionScene(session) {
432
+ return session.event._data.data.message_scene;
433
+ }
434
+ __name(getSessionScene, "getSessionScene");
410
435
 
411
436
  // src/commands/ask.tsx
412
437
  function registerAsk(ctx, config) {
413
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);
414
442
  try {
415
- const logger = ctx.logger("sy-bot");
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);
416
448
  const messageElements = session.event.message.elements;
417
449
  const quoteElements = session.event.message.quote?.elements;
418
450
  const quoteRealText = getElementsText(quoteElements);
@@ -423,7 +455,12 @@ function registerAsk(ctx, config) {
423
455
  const finalImages = [...quoteImages, ...messageImages];
424
456
  logger.info("用户输入的图像:", finalImages);
425
457
  logger.info("用户输入的文字:", finalText);
426
- 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
+ }
427
464
  logger.info("发送表情响应");
428
465
  if (finalImages.length > 0) {
429
466
  logger.info("用户发送了图片,调用图片理解api...");
@@ -443,11 +480,11 @@ function registerAsk(ctx, config) {
443
480
  logger.info("sendOnlyText执行结束");
444
481
  }
445
482
  } catch (err) {
446
- const logger = ctx.logger("sy-bot");
447
- logger.error("ask 命令执行错误:", err);
483
+ const logger2 = ctx.logger("sy-bot");
484
+ logger2.error("ask 命令执行错误:", err);
448
485
  return "oops!出了点叉子!";
449
486
  } finally {
450
- await finishEmoji(session);
487
+ if (getSessionScene(session) == "group") await finishEmoji(session);
451
488
  }
452
489
  });
453
490
  }
@@ -575,13 +612,16 @@ __name(registerTables, "registerTables");
575
612
 
576
613
  // src/index.ts
577
614
  var name = "sy-bot";
615
+ var usage = "考研群答疑机器人";
578
616
  var inject = {
579
617
  required: ["database", "puppeteer"]
580
618
  };
581
619
  var Config = import_koishi3.Schema.object({
582
- api: import_koishi3.Schema.string().required(),
583
- model: import_koishi3.Schema.string().required(),
584
- 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号)")
585
625
  });
586
626
  function apply(ctx, config) {
587
627
  registerCommand(ctx, config);
@@ -593,5 +633,6 @@ __name(apply, "apply");
593
633
  Config,
594
634
  apply,
595
635
  inject,
596
- name
636
+ name,
637
+ usage
597
638
  });
@@ -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<void>;
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.9",
4
+ "version": "0.0.10",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [
@@ -13,7 +13,8 @@
13
13
  "dev": "cd ../.. && npm run dev",
14
14
  "build": "cd ../.. && npm run build",
15
15
  "v": "cd ../.. && npm run build && npm run bump",
16
- "pub": "cd ../.. && npm run pub"
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
  }