@nestim/koishi-plugin-qq-group-manager 1.4.4 → 1.4.5

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/CHANGELOG.md CHANGED
@@ -2,6 +2,34 @@
2
2
 
3
3
  本文件记录所有值得注意的变更。版本号遵循 [语义化版本](https://semver.org/lang/zh-CN/)。
4
4
 
5
+ ## 1.4.5
6
+
7
+ ### 改进
8
+
9
+ - **提示词里给每个发言人带上 QQ 号,用于区分身份**。
10
+
11
+ 之前只渲染「昵称(角色)」,昵称重复或改动时模型分不清谁是谁,
12
+ 会出现把另一个机器人当成自己、把两个同名群友记混的情况。
13
+
14
+ 现在渲染成 `昵称(角色#QQ号)`:
15
+
16
+ ```
17
+ [15:15] 小明(成员#10001): 你好
18
+ [15:15] MeowBot(你#9999): 我说过
19
+ [15:15] 冬木(管理员#2): 在吗
20
+ ```
21
+
22
+ - **QQ 号只作为身份参考,明确要求模型不要写进回复**;
23
+ - 自己的发言标 `(你#自己QQ号)`,别人的(包括其他机器人)都不会被标成自己;
24
+ - 引用消息也带上被引用者的 QQ 号(`「回复 小明#333:……」`);
25
+ - `unknown` 角色用「成员」兜底,避免出现 `小明(#10001)` 这种孤立井号。
26
+
27
+ 规则里新增两条约束:判断「谁是谁」必须看 #号;标着(你)的才是自己。
28
+
29
+ ### 测试
30
+
31
+ - 新增 9 项身份测试:QQ 号是否出现、同名用户区分、自己/其他机器人区分、
32
+ 引用带号、禁止输出 QQ 号、缺 userId 时不产生空 `#`。
5
33
  ## 1.4.4
6
34
 
7
35
  ### 改进
package/lib/ai/prompt.js CHANGED
@@ -22,7 +22,9 @@ exports.PASS_TOKEN = '<pass/>';
22
22
  const RULE_LINES = [
23
23
  '只输出你要发到群里的那一条消息正文。不要解释、不要旁白、不要编号、不要 Markdown、不要代码块、不要用引号把整句包起来。',
24
24
  '用中文口语,像群友聊天。不要复述对方的话,不要写"作为AI"之类的自我说明。',
25
- '只回应【当前消息】。需要称呼别人时用群昵称,不要用 QQ 号。',
25
+ '只回应【当前消息】。要称呼别人时用群昵称,不要把 QQ 号写进你的回复里。',
26
+ '方括号里的 #数字 是对方的 QQ 号,是唯一身份标识:昵称可能重复或改动,#号不会。判断"谁是谁"必须看 #号,不要只看昵称。',
27
+ '标着(你)的那条是你自己说过的话。其他任何昵称、其他机器人、以及昵称和你相似的成员都不是你,不要把他们的发言当成自己说的。',
26
28
  '不要编造群里没发生过的事;不确定就直接说不确定。',
27
29
  '不要提"记忆库""上下文""系统提示"这些词,也不要说"根据记忆"。',
28
30
  '不要主动挑起旧话题;当前消息聊什么就接什么。',
@@ -41,16 +43,32 @@ function timeText(ts) {
41
43
  return `${String(d.getHours()).padStart(2, '0')}:${String(d.getMinutes()).padStart(2, '0')}`;
42
44
  }
43
45
  }
46
+ /**
47
+ * 渲染发言人标识。
48
+ *
49
+ * 格式:昵称(角色#QQ号),例如「小明(管理员#10001)」。
50
+ *
51
+ * 为什么要带 QQ 号:昵称会重复、会改动,光靠昵称模型分不清谁是谁,
52
+ * 也容易把另一个机器人或同名的群友当成自己。QQ 号是固定标识,必须给出。
53
+ */
44
54
  function speaker(record, selfName) {
45
- if (record.self)
46
- return `${selfName}(你)`;
47
- const role = (0, names_1.roleLabel)(record.role || 'unknown');
48
- return role ? `${record.name}(${role})` : record.name;
55
+ const qq = String(record.qq || record.userId || '').trim();
56
+ if (record.self) {
57
+ return qq ? `${selfName}(你#${qq})` : `${selfName}(你)`;
58
+ }
59
+ // roleLabel 对 unknown 返回空串;此时用「成员」兜底,
60
+ // 否则会渲染成 `小明(#10001)` 这种孤零零的井号。
61
+ const role = (0, names_1.roleLabel)(record.role || 'unknown') || '成员';
62
+ const tail = qq ? `${role}#${qq}` : role;
63
+ return `${record.name}(${tail})`;
49
64
  }
50
65
  function renderRecordLine(record, selfName) {
51
66
  const time = timeText(record.at);
67
+ const quoteWho = record.quote
68
+ ? `${record.quote.name}${record.quote.userId ? `#${record.quote.userId}` : ''}`
69
+ : '';
52
70
  const quote = record.quote?.text
53
- ? `「回复 ${record.quote.name}:${(0, text_1.truncate)(record.quote.text, 40)}」`
71
+ ? `「回复 ${quoteWho}:${(0, text_1.truncate)(record.quote.text, 40)}」`
54
72
  : '';
55
73
  const body = quote ? `${quote}${record.text}` : record.text;
56
74
  const forward = record.forwardText
@@ -89,7 +107,8 @@ function buildUserPrompt(input) {
89
107
  const selfName = input.selfName;
90
108
  const history = input.records.filter((item) => item !== input.current && item.id !== input.current.id);
91
109
  const lines = [];
92
- lines.push('【最近消息】(按时间顺序,越靠下越新;名字都是群昵称)');
110
+ lines.push('【最近消息】(按时间顺序,越靠下越新)');
111
+ lines.push('格式:昵称(角色#QQ号)。#号是唯一身份,昵称重复时靠 #号区分;(你)标记的是你自己的发言。');
93
112
  if (history.length) {
94
113
  for (const record of history)
95
114
  lines.push(renderRecordLine(record, selfName));
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nestim/koishi-plugin-qq-group-manager",
3
3
  "description": "Koishi QQ群管理插件(OneBot/LLOneBot):群管命令、权限校验、图片菜单、状态卡片、复读、AI群聊回复、记忆库、识图与自动管控(禁言/踢人)。",
4
- "version": "1.4.4",
4
+ "version": "1.4.5",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [
package/src/ai/prompt.ts CHANGED
@@ -37,7 +37,9 @@ export const PASS_TOKEN = '<pass/>';
37
37
  const RULE_LINES = [
38
38
  '只输出你要发到群里的那一条消息正文。不要解释、不要旁白、不要编号、不要 Markdown、不要代码块、不要用引号把整句包起来。',
39
39
  '用中文口语,像群友聊天。不要复述对方的话,不要写"作为AI"之类的自我说明。',
40
- '只回应【当前消息】。需要称呼别人时用群昵称,不要用 QQ 号。',
40
+ '只回应【当前消息】。要称呼别人时用群昵称,不要把 QQ 号写进你的回复里。',
41
+ '方括号里的 #数字 是对方的 QQ 号,是唯一身份标识:昵称可能重复或改动,#号不会。判断"谁是谁"必须看 #号,不要只看昵称。',
42
+ '标着(你)的那条是你自己说过的话。其他任何昵称、其他机器人、以及昵称和你相似的成员都不是你,不要把他们的发言当成自己说的。',
41
43
  '不要编造群里没发生过的事;不确定就直接说不确定。',
42
44
  '不要提"记忆库""上下文""系统提示"这些词,也不要说"根据记忆"。',
43
45
  '不要主动挑起旧话题;当前消息聊什么就接什么。',
@@ -57,16 +59,33 @@ function timeText(ts: number): string {
57
59
  }
58
60
  }
59
61
 
62
+ /**
63
+ * 渲染发言人标识。
64
+ *
65
+ * 格式:昵称(角色#QQ号),例如「小明(管理员#10001)」。
66
+ *
67
+ * 为什么要带 QQ 号:昵称会重复、会改动,光靠昵称模型分不清谁是谁,
68
+ * 也容易把另一个机器人或同名的群友当成自己。QQ 号是固定标识,必须给出。
69
+ */
60
70
  function speaker(record: ChatRecord, selfName: string): string {
61
- if (record.self) return `${selfName}(你)`;
62
- const role = roleLabel((record.role as any) || 'unknown');
63
- return role ? `${record.name}(${role})` : record.name;
71
+ const qq = String((record as any).qq || record.userId || '').trim();
72
+ if (record.self) {
73
+ return qq ? `${selfName}(你#${qq})` : `${selfName}(你)`;
74
+ }
75
+ // roleLabel 对 unknown 返回空串;此时用「成员」兜底,
76
+ // 否则会渲染成 `小明(#10001)` 这种孤零零的井号。
77
+ const role = roleLabel((record.role as any) || 'unknown') || '成员';
78
+ const tail = qq ? `${role}#${qq}` : role;
79
+ return `${record.name}(${tail})`;
64
80
  }
65
81
 
66
82
  export function renderRecordLine(record: ChatRecord, selfName: string): string {
67
83
  const time = timeText(record.at);
84
+ const quoteWho = record.quote
85
+ ? `${record.quote.name}${record.quote.userId ? `#${record.quote.userId}` : ''}`
86
+ : '';
68
87
  const quote = record.quote?.text
69
- ? `「回复 ${record.quote.name}:${truncate(record.quote.text, 40)}」`
88
+ ? `「回复 ${quoteWho}:${truncate(record.quote.text, 40)}」`
70
89
  : '';
71
90
  const body = quote ? `${quote}${record.text}` : record.text;
72
91
  const forward = record.forwardText
@@ -106,7 +125,8 @@ export function buildUserPrompt(input: PromptInput): string {
106
125
  const history = input.records.filter((item) => item !== input.current && item.id !== input.current.id);
107
126
  const lines: string[] = [];
108
127
 
109
- lines.push('【最近消息】(按时间顺序,越靠下越新;名字都是群昵称)');
128
+ lines.push('【最近消息】(按时间顺序,越靠下越新)');
129
+ lines.push('格式:昵称(角色#QQ号)。#号是唯一身份,昵称重复时靠 #号区分;(你)标记的是你自己的发言。');
110
130
  if (history.length) {
111
131
  for (const record of history) lines.push(renderRecordLine(record, selfName));
112
132
  } else {