dsh-onebot-genji 0.17.0 → 0.17.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/README.md +1 -2
- package/lib/bridge.js +4 -3
- package/lib/card-relay.js +6 -4
- package/lib/index.js +0 -19
- package/lib/outbound.js +28 -89
- package/lib/prompt.js +3 -4
- package/lib/stickers.js +0 -5
- package/lib/types/bridge.d.ts +0 -3
- package/lib/types/card-relay.d.ts +4 -2
- package/lib/types/outbound.d.ts +4 -5
- package/lib/types/stickers.d.ts +0 -3
- package/package.json +1 -1
- package/lib/sticker-tag.js +0 -84
- package/lib/types/sticker-tag.d.ts +0 -47
package/README.md
CHANGED
|
@@ -23,7 +23,7 @@ dsh plugin --profile web add dsh-onebot-genji
|
|
|
23
23
|
| **表情包库** | 一套完整的表情包管理:新图自动收进「未审核」,审核时才让模型看图写描述和标签,不点不跑、不占显存;已审核的图可一键「重新识别」重跑识别,描述和标签点一下就能改 |
|
|
24
24
|
| **主动搭话** | 内置在插件里(`lib/proactive.js`),按空闲时长、间隔、每日上限、安静时段自己找话题;开关和阈值全在设置页「行为 → 私聊」,生成走当前会话模型 |
|
|
25
25
|
| **回合形式掷骰** | 每个回合按概率决定这一轮用文字、语音条还是表情包;语音/表情的开关与概率都是设置项(默认 10% / 39%) |
|
|
26
|
-
| **气泡切分** | 正文按换行 / 句末标点自动切成多条气泡,条与条之间按字数算随机停顿(0.4–2.2
|
|
26
|
+
| **气泡切分** | 正文按换行 / 句末标点自动切成多条气泡,条与条之间按字数算随机停顿(0.4–2.2 秒);列表项(`1.` `2、` `3)` 或 `-` `•` `*`)一行一条,不封顶;提问卡和命令卡片整段发一条 |
|
|
27
27
|
| **自带语音转写桥** | `lib/stt_cli.py` 打进包里,`sttEngine: auto` 探不到 whisper 时自动用它(只要 Python + `faster-whisper`),不用自己配脚本 |
|
|
28
28
|
| **群聊上下文** | 被 @ 或叫到唤醒词时,自动带上群里最近 N 条消息(「参考上下文条数」,默认 3,0 = 不带),被门控挡下的消息不会丢 |
|
|
29
29
|
| **QQ 空间说说** | 「QQ空间」页签里开关 + 每日上限 + 安静时段 + 可见范围;到点自己挑当天的事写一条说说发出去(默认关)。也可以让机器人手动发,带图 |
|
|
@@ -43,7 +43,6 @@ dsh plugin --profile web add dsh-onebot-genji
|
|
|
43
43
|
- **重新识别**:已审核的图每张下面有「重新识别」,重跑一遍识别并覆盖原有描述和标签,用来纠正老条目或者换了模型之后统一刷新。
|
|
44
44
|
- **改描述 / 标签**:把鼠标移到描述或标签那一行,右端出现铅笔,点开变输入框,回车保存。两行高度固定,长的自动省略。未审核的图不给改——审核时会自己识别一遍。
|
|
45
45
|
- **看图 / 删除**:点缩略图看原图(走 DSH 自己的大图查看器);「删除」会在索引里留一条墓碑,之后这张图不会再被自动收集。
|
|
46
|
-
- **正文表情包标签**:正文里写 <表情:关键词>(也认 <表情包:>、<sticker:>),插件把标签摘掉,按关键词从「已审核」里挑一张图单独发出去;匹配不上就当没写,标签不会漏到聊天里。反引号包住的写法原样保留。
|
|
47
46
|
- **索引自愈**:打开面板时会先对一遍索引和磁盘,文件没了的条目直接摘掉(显示「文件丢失」而不是一直转圈)。一次发现一半以上都读不到时按「库目录整体不可用」处理、索引原样保留——免得盘符没挂上就把 188 条清空。
|
|
48
47
|
|
|
49
48
|
## 语音转写(插件自带的桥)
|
package/lib/bridge.js
CHANGED
|
@@ -217,7 +217,6 @@ export class ChatBridge {
|
|
|
217
217
|
isStopping: () => this.stopping,
|
|
218
218
|
log: (level, message) => this.deps.log(level, message),
|
|
219
219
|
config: deps.config,
|
|
220
|
-
pickSticker: key => deps.stickerPick?.(key) ?? null,
|
|
221
220
|
// W1: outbound decision events ride the chat's initiating traceId; a
|
|
222
221
|
// write with no mapped trace (proactive tool sends) starts a fresh one.
|
|
223
222
|
trace: (chatId, event) => {
|
|
@@ -844,7 +843,7 @@ export class ChatBridge {
|
|
|
844
843
|
* T2-B2 adds onQuestionCall to record the outstanding batch. */
|
|
845
844
|
get cardRelayCtx() {
|
|
846
845
|
return {
|
|
847
|
-
sendToChat: (chatId, text) => this.sendToChat(chatId, text),
|
|
846
|
+
sendToChat: (chatId, text, options) => this.sendToChat(chatId, text, options),
|
|
848
847
|
log: (level, message) => this.deps.log(level, message),
|
|
849
848
|
onQuestionCall: (chatId, call) => {
|
|
850
849
|
this.activeQuestion.set(chatId, { ...call, askedAt: Date.now() });
|
|
@@ -1070,7 +1069,9 @@ export class ChatBridge {
|
|
|
1070
1069
|
get commandCtx() {
|
|
1071
1070
|
const bridge = this;
|
|
1072
1071
|
return {
|
|
1073
|
-
|
|
1072
|
+
// 命令输出都是排版好的卡片(/help、/doctor、/workspace 列表…),
|
|
1073
|
+
// 整段原样发一条:按句末标点切会把卡片拆散,也没法再断言整段文案。
|
|
1074
|
+
sendToChat: (chatId, text) => bridge.sendToChat(chatId, text, { noBubbleSplit: true }),
|
|
1074
1075
|
log: (level, message) => bridge.deps.log(level, message),
|
|
1075
1076
|
// T1 (#27): /steer 的命令确认文案取 notices.steerAccepted(自定义时)。
|
|
1076
1077
|
notices: bridge.deps.config.notices,
|
package/lib/card-relay.js
CHANGED
|
@@ -7,9 +7,10 @@ export function relayHostCards(ctx, chatId, content) {
|
|
|
7
7
|
if (call.type !== 'tool-call')
|
|
8
8
|
continue;
|
|
9
9
|
if (call.name === 'exit_plan_mode') {
|
|
10
|
-
const
|
|
11
|
-
if (
|
|
12
|
-
|
|
10
|
+
const planText = renderPlanCard(call.arguments, ctx.log);
|
|
11
|
+
if (planText !== undefined) {
|
|
12
|
+
// 计划书同样按行排版,整张一条发。
|
|
13
|
+
ctx.sendToChat(chatId, planText, { noBubbleSplit: true }).catch((error) => {
|
|
13
14
|
ctx.log('warn', 'plan card relay failed: ' + String(error));
|
|
14
15
|
});
|
|
15
16
|
}
|
|
@@ -26,7 +27,8 @@ export function relayHostCards(ctx, chatId, content) {
|
|
|
26
27
|
ctx.log('debug', 'question state update failed: ' + String(error));
|
|
27
28
|
}
|
|
28
29
|
}
|
|
29
|
-
|
|
30
|
+
// 提问卡整张一条发(卡是按行排版的,切开会把选项和标题拆散)。
|
|
31
|
+
ctx.sendToChat(chatId, renderQuestionCard(parsed), { noBubbleSplit: true }).catch((error) => {
|
|
30
32
|
ctx.log('warn', 'question card relay failed: ' + String(error));
|
|
31
33
|
});
|
|
32
34
|
}
|
package/lib/index.js
CHANGED
|
@@ -41,7 +41,6 @@ let ProactiveTalk;
|
|
|
41
41
|
let QzonePost;
|
|
42
42
|
let StickerStore;
|
|
43
43
|
let DEFAULT_STICKER_ROOT;
|
|
44
|
-
let pickStickerByTag;
|
|
45
44
|
try {
|
|
46
45
|
;
|
|
47
46
|
({ default: z } = await import('@deepseek-ai/schemastery'));
|
|
@@ -58,7 +57,6 @@ try {
|
|
|
58
57
|
({ ProactiveTalk } = await import('./proactive.js'));
|
|
59
58
|
({ QzonePost } = await import('./qzone.js'));
|
|
60
59
|
({ StickerStore, DEFAULT_STICKER_ROOT } = await import('./stickers.js'));
|
|
61
|
-
({ pickStickerByTag } = await import('./sticker-tag.js'));
|
|
62
60
|
({ resolveUserQuestions } = await import('./ask-tool.js'));
|
|
63
61
|
}
|
|
64
62
|
catch (error) {
|
|
@@ -563,23 +561,6 @@ export function apply(ctx, config) {
|
|
|
563
561
|
log('warn', '[stickers] 即时收集失败: ' + describeError(error));
|
|
564
562
|
}
|
|
565
563
|
},
|
|
566
|
-
// 2026-11-23 本地加:正文 `<表情:关键词>` 标签 → 已审核库里的一张图。
|
|
567
|
-
// 不设开关:匹配不上就静默跳过(没写等于没写),不会有副作用;
|
|
568
|
-
// 每次现读索引,跟面板刷新同一口径。
|
|
569
|
-
stickerPick: (key) => {
|
|
570
|
-
try {
|
|
571
|
-
const store = stickerStoreOf();
|
|
572
|
-
const items = store.list();
|
|
573
|
-
const file = pickStickerByTag(items, key, f => store.approvedPathOf(f));
|
|
574
|
-
if (file === null)
|
|
575
|
-
log('debug', '[stickers] 表情包标签没匹配上: ' + key);
|
|
576
|
-
return file;
|
|
577
|
-
}
|
|
578
|
-
catch (error) {
|
|
579
|
-
log('warn', '[stickers] 表情包标签解析失败: ' + describeError(error));
|
|
580
|
-
return null;
|
|
581
|
-
}
|
|
582
|
-
},
|
|
583
564
|
agents: ctx.agents,
|
|
584
565
|
sessions: ctx.sessions,
|
|
585
566
|
agentPresets: ctx.agentPresets,
|
package/lib/outbound.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* bridge-resident) keep working unchanged.
|
|
10
10
|
* @module dsh-onebot/outbound
|
|
11
11
|
*/
|
|
12
|
-
import { appendFile, mkdir
|
|
12
|
+
import { appendFile, mkdir } from 'node:fs/promises';
|
|
13
13
|
import { join } from 'node:path';
|
|
14
14
|
import { splitChatId } from './chat.js';
|
|
15
15
|
import { OneBotActionError, OneBotNotConnectedError } from './connection.js';
|
|
@@ -17,7 +17,6 @@ import { extractForwardBlocks, scanSensitive, stripMarkdown } from './split.js';
|
|
|
17
17
|
import { renderTextImage } from './t2i/index.js';
|
|
18
18
|
import { describeError } from './errors.js';
|
|
19
19
|
import { TRACE_REASONS } from './trace.js';
|
|
20
|
-
import { extractStickerTags } from './sticker-tag.js';
|
|
21
20
|
/**
|
|
22
21
|
* SnowLuma's send_msg validates text segments: `text === ''` is treated as a
|
|
23
22
|
* compatibility placeholder and a whitespace-only text still goes through
|
|
@@ -229,72 +228,40 @@ export function stripTrailingPeriod(text) {
|
|
|
229
228
|
return body;
|
|
230
229
|
return body.replace(/。\s*$/u, '');
|
|
231
230
|
}
|
|
232
|
-
|
|
231
|
+
// 2026-11-24 主人口述的最终规则:
|
|
232
|
+
// 1. 换行则分条
|
|
233
|
+
// 2. 遇到**句末**的标点(。!?… / ...)则分条(逗号顿号冒号分号都不切)
|
|
234
|
+
// 3. 遇到列表项(「1. 」「2、」「3) 」或「- 」「• 」「* 」开头)则分条
|
|
235
|
+
// 4. 去掉每条末尾的「。」
|
|
236
|
+
// 5. 相邻气泡之间按上一条的字数停顿 420~2200ms(见 bubbleGapMs)
|
|
237
|
+
// 原来那套「35 字以内不切」「不足 6 字的碎片吸附」「条数上限」全部取消:
|
|
238
|
+
// 上限一取消,就不再出现 join(' ') 把好几行拼成一坨的情况。
|
|
239
|
+
export function splitIntoBubbles(text) {
|
|
233
240
|
const raw = String(text ?? '');
|
|
234
241
|
if (raw.trim() === '')
|
|
235
242
|
return [];
|
|
236
243
|
const punctOnlyRe = /^[\p{P}\p{S}\s]+$/u;
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
const isItem = listCount >= 2 && itemRe.test(part);
|
|
252
|
-
// 2. 行内断句(列表项整行成一条)
|
|
253
|
-
const pieces = isItem || [...part].length <= sentenceCut
|
|
254
|
-
? [part]
|
|
255
|
-
: (() => {
|
|
256
|
-
// `~` 只在后面不是「路径/数字/英文」时才算句末:
|
|
257
|
-
// - `420~2200` 是范围(2026-11-20 主人抓过一次)
|
|
258
|
-
// - `~/.dsh/memory-daily/` 是家目录路径(2026-11-20 第二次抓到,
|
|
259
|
-
// 正文被从路径中间切成两条气泡),后面跟 / \ . _ - 或字母数字都不算句末。
|
|
260
|
-
// 行内还可能挤着「…。2. 自省复盘…3. 记忆图衰减…」这种编号(主人抓到过
|
|
261
|
-
// 「2、3 点没分条」),编号标记前也切一刀:`\s\d{1,2}[.、).]\s`。
|
|
262
|
-
const segs = part.split(/(?<=[。!?!?…])\s*|(?<=~)\s*(?![0-9A-Za-z/\\._-])|(?<=\s)(?=\d{1,2}\s*[.、).]\s)/)
|
|
263
|
-
.map((s) => s.trim()).filter(Boolean);
|
|
264
|
-
return segs.length > 0 ? segs : [part];
|
|
265
|
-
})();
|
|
266
|
-
// 3. 行内吸附合并(换行是硬边界,不跨行合并普通句子)
|
|
267
|
-
const line = [];
|
|
268
|
-
for (const s of pieces) {
|
|
269
|
-
const lastInLine = line[line.length - 1];
|
|
270
|
-
if (lastInLine !== undefined && shortMerge(lastInLine, s)) {
|
|
271
|
-
line[line.length - 1] = lastInLine + s;
|
|
244
|
+
const out = [];
|
|
245
|
+
// 1. 换行是硬边界
|
|
246
|
+
for (const line of raw.split(/\r?\n+/).map((s) => s.trim()).filter(Boolean)) {
|
|
247
|
+
// 2/3. 行内按**句末**标点切一刀(。!?!?… 以及英文省略号 ... 或 …);
|
|
248
|
+
// 逗号、顿号、冒号、分号不算句末,不切。行内挤着编号(「…。2. 自省复盘…
|
|
249
|
+
// 3. 记忆图衰减…」)时编号标记前也切一刀。
|
|
250
|
+
const segs = line
|
|
251
|
+
.split(/(?<=[。!?!?…])\s*|(?<=\.{2,})\s*|(?<=\s)(?=\d{1,2}\s*[.、).]\s)/)
|
|
252
|
+
.map((s) => s.trim())
|
|
253
|
+
.filter(Boolean);
|
|
254
|
+
for (const seg of segs.length > 0 ? segs : [line]) {
|
|
255
|
+
// 纯标点段(单独一个「!」)并到上一条,免得发出空气泡
|
|
256
|
+
if (out.length > 0 && punctOnlyRe.test(seg)) {
|
|
257
|
+
out[out.length - 1] += seg;
|
|
272
258
|
}
|
|
273
259
|
else {
|
|
274
|
-
|
|
260
|
+
out.push(seg);
|
|
275
261
|
}
|
|
276
262
|
}
|
|
277
|
-
// 4. 跨行只吸附纯标点行(「真的假的」+「!」)
|
|
278
|
-
if (line.length > 0 && merged.length > 0 && punctOnlyRe.test(line[0])) {
|
|
279
|
-
merged[merged.length - 1] += line.shift();
|
|
280
|
-
}
|
|
281
|
-
merged.push(...line);
|
|
282
263
|
}
|
|
283
|
-
|
|
284
|
-
return [];
|
|
285
|
-
// 4. 上限控制
|
|
286
|
-
// 2026-11-23 主人抓到的 bug:「两句说明 + 1~4 四个编号 + 一句收尾」一共 7 行,
|
|
287
|
-
// 却只按 listCount=4 放宽到 4 条 —— 超出的 2、3、4 和收尾被 join(' ') 拼成
|
|
288
|
-
// 一条。列表演示里说明行常常比编号项多,所以把实际行数(merged.length)
|
|
289
|
-
// 也纳入判据。
|
|
290
|
-
// 2026-11-23 晚 主人第二次要求:**编号列表不封顶**(之前封 8,我写 10 条
|
|
291
|
-
// 对比项被压成 8 条,他又看到「没分条」)。带编号的列表一律一行一条,
|
|
292
|
-
// 有几行出几条;不带编号的普通聊天照旧只有 maxBubbles(避免一句话刷屏)。
|
|
293
|
-
const limit = listCount >= 2 ? merged.length : maxBubbles;
|
|
294
|
-
const out = merged.length > limit
|
|
295
|
-
? [...merged.slice(0, limit - 1), merged.slice(limit - 1).join(' ')]
|
|
296
|
-
: merged;
|
|
297
|
-
// 2026-11-22 主人要求:每条气泡末尾的「。」剥掉(问号叹号不动);剥成空的丢掉。
|
|
264
|
+
// 4. 每条末尾的「。」剥掉(问号叹号不动);剥成空的丢掉。
|
|
298
265
|
return out.map(stripTrailingPeriod).filter((s) => s.trim() !== '');
|
|
299
266
|
}
|
|
300
267
|
/** 气泡停顿:按字数算的基准参数(2026-11-20 主人要求「按每条字数来,别固定 1500ms」)。 */
|
|
@@ -518,14 +485,7 @@ export class OutboundPipeline {
|
|
|
518
485
|
// T9 (#2): the model may echo the <user_message> boundary that
|
|
519
486
|
// wrapUserMessage injected — strip the markers before delivery so both
|
|
520
487
|
// the t2i card and the plain-text branch stay clean.
|
|
521
|
-
const
|
|
522
|
-
// 2026-11-23 本地加:正文表情包标签(`<表情:得意>`)。摘掉标签拿到关键词,
|
|
523
|
-
// 关键词交给 ctx.pickSticker 去「已审核」库里找图;匹配不上就当没写。
|
|
524
|
-
// 没接 pickSticker(测试装配 / 关掉开关)= 连正则都不跑,正文原样。
|
|
525
|
-
const tagged = this.ctx.pickSticker === undefined
|
|
526
|
-
? { text: leaked, keys: [] }
|
|
527
|
-
: extractStickerTags(leaked);
|
|
528
|
-
const clean = tagged.text;
|
|
488
|
+
const clean = stripBoundaryLeakage(body);
|
|
529
489
|
// T2 (PR port): 整条只有括号旁白——拦在卡片之前,直接不发
|
|
530
490
|
//(asideOnlySilentEnabled 独立开关,默认关闭不拦)。
|
|
531
491
|
if (this.ctx.config.asideOnlySilentEnabled === true && nodes.length === 0 && isAsideOnly(clean)) {
|
|
@@ -580,7 +540,7 @@ export class OutboundPipeline {
|
|
|
580
540
|
// 气泡切分(2026-11-19 按 issue #6):换行/长句 → 多条独立气泡,
|
|
581
541
|
// 最多 4 条。首条立即发,其后按 800–1500ms 随机停顿营造打字呼吸感;
|
|
582
542
|
// 引用只挂在第一条。
|
|
583
|
-
const bubbles = splitIntoBubbles(plain);
|
|
543
|
+
const bubbles = options.noBubbleSplit === true ? [plain] : splitIntoBubbles(plain);
|
|
584
544
|
for (let i = 0; i < bubbles.length; i += 1) {
|
|
585
545
|
if (i > 0)
|
|
586
546
|
await new Promise((resolve) => setTimeout(resolve, bubbleGapMs(bubbles[i - 1])));
|
|
@@ -598,27 +558,6 @@ export class OutboundPipeline {
|
|
|
598
558
|
this.ctx.trace?.(chatId, { stage: 'outbound', ok: false, reason: TRACE_REASONS.outboundEmptyText });
|
|
599
559
|
}
|
|
600
560
|
}
|
|
601
|
-
// 表情包标签落成真图:正文全发完之后再发,一条一个(标签本来就是
|
|
602
|
-
// 「这句说完贴一张」,插在句子中间反而打断)。找不到图的静默跳过。
|
|
603
|
-
for (const key of tagged.keys) {
|
|
604
|
-
const file = await this.ctx.pickSticker?.(key);
|
|
605
|
-
if (file === undefined || file === null || file === '')
|
|
606
|
-
continue;
|
|
607
|
-
try {
|
|
608
|
-
const info = await stat(file);
|
|
609
|
-
if (info.size > this.ctx.config.maxImageBytes) {
|
|
610
|
-
this.ctx.log('warn', '表情包超出发图上限,跳过: ' + file);
|
|
611
|
-
continue;
|
|
612
|
-
}
|
|
613
|
-
const data = await readFile(file);
|
|
614
|
-
const id = await this.sendMsg(chatId, [{ type: 'image', data: { file: 'base64://' + data.toString('base64') } }], {});
|
|
615
|
-
if (id !== undefined)
|
|
616
|
-
ids.push(id);
|
|
617
|
-
}
|
|
618
|
-
catch (error) {
|
|
619
|
-
this.ctx.log('warn', '表情包发送失败(跳过): ' + describeError(error));
|
|
620
|
-
}
|
|
621
|
-
}
|
|
622
561
|
this.ctx.trace?.(chatId, { stage: 'outbound', ok: true, reason: '回复已发送', data: { segments: ids.length } });
|
|
623
562
|
return ids;
|
|
624
563
|
});
|
package/lib/prompt.js
CHANGED
|
@@ -66,10 +66,9 @@ export function buildPlatformPrompt(restrictedMembers, extra = '', memoryText =
|
|
|
66
66
|
text += '你正在通过 QQ 与用户对话(OneBot/NapCat 通道)。规则:\n';
|
|
67
67
|
text += '- QQ 不渲染 Markdown:请输出纯文本。用「1. 2. 3.」编号或「- 」列表;行内代码用反引号包住即可(会原样显示)。\n';
|
|
68
68
|
text += '- 需要发送图片时用 qq_send_image(本地路径或 URL);文件用 qq_send_file;语音 qq_send_voice;视频 qq_send_video。\n';
|
|
69
|
-
// 2026-11-23
|
|
70
|
-
//
|
|
71
|
-
//
|
|
72
|
-
text += '- 想发表情包时,在正文里写 `<表情:关键词>`(例:`<表情:得意>`、`<表情:无语>`)。插件会把这个标签摘掉,按关键词去「已审核」表情包里找最贴的一张单独发出去;找不到就当没写,不会报错、也不会把标签发到 QQ。表情包**不要**用 qq_send_image 发(那是发截图/生成图用的)。\n';
|
|
69
|
+
// 2026-11-23 晚(主人复看后否掉):正文 `<表情:关键词>` 标签整条链已删——
|
|
70
|
+
// 每轮掷骰提示本来就规定「从已审核里挑一张、用 qq_send_image 发」,
|
|
71
|
+
// 标签在真实使用里轮不到,留着只是多一套正则。
|
|
73
72
|
text += '- 想以「合并转发」卡片展示多条消息(代码+说明、分步报告)时,用 qq_send_forward。\n';
|
|
74
73
|
// 本地加(2026-11-18,2026-11-19 改):qq_send_segments 已下线,招呼走 qq_send_text,
|
|
75
74
|
// 它和正文同一套自动分气泡逻辑。
|
package/lib/stickers.js
CHANGED
|
@@ -212,11 +212,6 @@ export class StickerStore {
|
|
|
212
212
|
pathOf(item) {
|
|
213
213
|
return join(this.dirOf(item), item.file);
|
|
214
214
|
}
|
|
215
|
-
/** 2026-11-23 本地加:按文件名拼「已审核」目录下的绝对路径。
|
|
216
|
-
* 表情包标签只从这里挑图(未审核的不进聊天),所以不用先拿到记录。 */
|
|
217
|
-
approvedPathOf(file) {
|
|
218
|
-
return join(this.approvedDir, file);
|
|
219
|
-
}
|
|
220
215
|
/** 面板列表用:把记录整理成平面数组(不读图片字节)。 */
|
|
221
216
|
list() {
|
|
222
217
|
const out = [];
|
package/lib/types/bridge.d.ts
CHANGED
|
@@ -356,9 +356,6 @@ export interface BridgeDeps {
|
|
|
356
356
|
/** 本地加(2026-11-20):把刚落盘的入站图片立刻收进表情包库「未审核」。
|
|
357
357
|
* 缺席(关掉自动收集 / 测试装配)= 零行为。 */
|
|
358
358
|
stickerCollect?: ((path: string) => void) | undefined;
|
|
359
|
-
/** 本地加(2026-11-23):正文 `<表情:关键词>` 标签 → 已审核库里的一张图
|
|
360
|
-
* (返回绝对路径,null = 没匹配上)。缺席 = 不做标签解析。 */
|
|
361
|
-
stickerPick?: ((key: string) => string | null) | undefined;
|
|
362
359
|
/** Log line callback (level, message). */
|
|
363
360
|
log(level: 'info' | 'warn' | 'error' | 'debug', message: string): void;
|
|
364
361
|
}
|
|
@@ -14,8 +14,10 @@ import type { ChatId } from './chat.js';
|
|
|
14
14
|
* bridge log (render failures are debug lines, relay failures warn lines).
|
|
15
15
|
* T2-B2 adds the optional onQuestionCall hook for the answer-bridge state. */
|
|
16
16
|
export interface CardRelayContext {
|
|
17
|
-
/** Outbound pipeline send (bridge facade). */
|
|
18
|
-
sendToChat(chatId: ChatId, text: string
|
|
17
|
+
/** Outbound pipeline send (bridge facade). `noBubbleSplit` 让卡片原样一条发出去。 */
|
|
18
|
+
sendToChat(chatId: ChatId, text: string, options?: {
|
|
19
|
+
noBubbleSplit?: boolean;
|
|
20
|
+
}): Promise<string[]>;
|
|
19
21
|
/** Bridge log line callback. */
|
|
20
22
|
log(level: 'info' | 'warn' | 'error' | 'debug', message: string): void;
|
|
21
23
|
/** T2-B2: called once per relayed ask_user_question call with the parsed batch. */
|
package/lib/types/outbound.d.ts
CHANGED
|
@@ -82,7 +82,7 @@ export declare function splitAtSegments(text: string): OutboundSegment[];
|
|
|
82
82
|
* 整条只有标点的不处理(免得把「。」自己清成空串)。
|
|
83
83
|
*/
|
|
84
84
|
export declare function stripTrailingPeriod(text: string): string;
|
|
85
|
-
export declare function splitIntoBubbles(text: string
|
|
85
|
+
export declare function splitIntoBubbles(text: string): string[];
|
|
86
86
|
/** 气泡停顿:按字数算的基准参数(2026-11-20 主人要求「按每条字数来,别固定 1500ms」)。 */
|
|
87
87
|
export declare const BUBBLE_GAP_BASE_MS = 380;
|
|
88
88
|
export declare const BUBBLE_GAP_PER_CHAR_MS = 68;
|
|
@@ -98,6 +98,9 @@ export declare function bubbleGapMs(prevText?: string, random?: () => number): n
|
|
|
98
98
|
/** Options for an explicit outbound send (from tools). */
|
|
99
99
|
export interface SendOptions {
|
|
100
100
|
replyTo?: string;
|
|
101
|
+
/** 2026-11-24:整段原样发一条,不切气泡。给结构化卡片(提问卡/计划书)用——
|
|
102
|
+
* 它们靠换行排版,切开会把「a) 选项」和标题拆散。 */
|
|
103
|
+
noBubbleSplit?: boolean;
|
|
101
104
|
/** Queue the send for resend on reconnect instead of failing while the
|
|
102
105
|
* connection is down. Only for model final replies; interim sends carry
|
|
103
106
|
* recall timers + bookkeeping and must never be replayed. */
|
|
@@ -170,10 +173,6 @@ export interface OutboundContext {
|
|
|
170
173
|
isStopping(): boolean;
|
|
171
174
|
/** Bridge log line callback. */
|
|
172
175
|
log(level: 'info' | 'warn' | 'error' | 'debug', message: string): void;
|
|
173
|
-
/** 本地加(2026-11-23):正文 `<表情:关键词>` 标签解析——按关键词在「已审核」
|
|
174
|
-
* 库里挑一张图,返回绝对路径;返回空 = 没匹配上(静默不发)。
|
|
175
|
-
* 缺席 = 不做标签解析,正文里的标签原样保留(测试装配 / 开关关掉)。 */
|
|
176
|
-
pickSticker?: (key: string) => Promise<string | null> | string | null;
|
|
177
176
|
/** W1: emit one outbound/queue decision event for a chat. The bridge owns
|
|
178
177
|
* the traceId resolution (chat-level association table; unmapped proactive
|
|
179
178
|
* writes mint a fresh id) — absent = tracing off, zero cost. */
|
package/lib/types/stickers.d.ts
CHANGED
|
@@ -151,9 +151,6 @@ export declare class StickerStore {
|
|
|
151
151
|
save(): void;
|
|
152
152
|
dirOf(item: StickerRecord): string;
|
|
153
153
|
pathOf(item: StickerRecord): string;
|
|
154
|
-
/** 2026-11-23 本地加:按文件名拼「已审核」目录下的绝对路径。
|
|
155
|
-
* 表情包标签只从这里挑图(未审核的不进聊天),所以不用先拿到记录。 */
|
|
156
|
-
approvedPathOf(file: string): string;
|
|
157
154
|
/** 面板列表用:把记录整理成平面数组(不读图片字节)。 */
|
|
158
155
|
list(): StickerItemView[];
|
|
159
156
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-onebot-genji",
|
|
3
|
-
"version": "0.17.
|
|
3
|
+
"version": "0.17.2",
|
|
4
4
|
"description": "由 InsaneGenji 维护的 QQ 通道分叉(fork 自 dsh-onebot-qq@0.11.0):在 OneBot 11 / NapCat 通道基础上加了表情包库(未审核/已审核、模型看图写标签、重新识别)、主动搭话、QQ 空间说说、回合形式掷骰(语音条、表情包概率)、正文气泡切分、群聊上下文与自带语音转写桥。仓库 github.com/InsaneGenji/dsh-onebot-genji,上游 github.com/mario841859784/dsh-onebot .",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dsh",
|
package/lib/sticker-tag.js
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 正文表情包标签(2026-11-23 主人批准的最小版):
|
|
3
|
-
* 借鉴 aurabot 的 `<sticker:标签>` 协议,但只借「用标签代替挑文件」这一点。
|
|
4
|
-
*
|
|
5
|
-
* 模型在正文里写 `<表情:得意>`(也认 `<sticker:得意>` / `<表情包:得意>`),
|
|
6
|
-
* 出站时把标签摘掉,按关键词去「已审核」库里找一张最贴的图,作为独立消息
|
|
7
|
-
* 发出去;匹配不上就当作没写——**绝不报错、绝不把标签原样发到 QQ**。
|
|
8
|
-
*
|
|
9
|
-
* 为什么不整段照搬 aurabot:它把 `|||` 分气泡、`<voice>`、`<reply:`、`[沉默]`
|
|
10
|
-
* 全塞进正文,全靠正则切。我们已经有 splitIntoBubbles、掷骰语音条、[[reply:]]
|
|
11
|
-
* 和 [[不回]],再叠一层只会互相打架;真正省事的只有表情包这一条。
|
|
12
|
-
* @module dsh-onebot/sticker-tag
|
|
13
|
-
*/
|
|
14
|
-
/** 正文里的表情包标签:`<表情:关键词>` / `<sticker:关键词>` / `<表情包:关键词>`。
|
|
15
|
-
* 关键词里不认尖括号和换行,长度给个上限免得太贪。 */
|
|
16
|
-
export const STICKER_TAG_RE = /<[ \t]*(?:表情包|表情|sticker)[ \t]*[::][ \t]*([^<>\r\n]{1,40}?)[ \t]*>/gi;
|
|
17
|
-
/**
|
|
18
|
-
* 从正文里摘掉全部表情包标签。
|
|
19
|
-
*
|
|
20
|
-
* 只认完整成对形态 `<…:…>`;写成 `<表情:` 没收尾、或者正文里讨论这个语法
|
|
21
|
-
* 本身(带了反引号)时都不动——宁可少发一张图,也不要把半截标签发出去。
|
|
22
|
-
* 反引号包裹的整段(`` `<表情:得意>` ``)保留原样,那是说明文字不是指令。
|
|
23
|
-
*/
|
|
24
|
-
export function extractStickerTags(raw) {
|
|
25
|
-
const body = String(raw ?? '');
|
|
26
|
-
if (body === '' || !body.includes('<'))
|
|
27
|
-
return { text: body, keys: [] };
|
|
28
|
-
const keys = [];
|
|
29
|
-
const text = body.replace(STICKER_TAG_RE, (match, key, offset) => {
|
|
30
|
-
// 反引号内的原样保留:模型在解释这个语法时不该被吃掉。
|
|
31
|
-
const before = body.slice(0, offset);
|
|
32
|
-
const ticks = (before.match(/`/g) ?? []).length;
|
|
33
|
-
if (ticks % 2 === 1)
|
|
34
|
-
return match;
|
|
35
|
-
const trimmed = key.trim();
|
|
36
|
-
if (trimmed === '')
|
|
37
|
-
return '';
|
|
38
|
-
if (!keys.includes(trimmed))
|
|
39
|
-
keys.push(trimmed);
|
|
40
|
-
return '';
|
|
41
|
-
});
|
|
42
|
-
if (keys.length === 0)
|
|
43
|
-
return { text: body, keys: [] };
|
|
44
|
-
// 摘完标签常留下「一句话」和空行,收一下边角,但别动正文里的换行结构。
|
|
45
|
-
return { text: text.replace(/[ \t]{2,}/g, ' ').replace(/[ \t]+$/gm, '').replace(/\n{3,}/g, '\n\n').trim(), keys };
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* 按关键词在候选里挑一张。
|
|
49
|
-
*
|
|
50
|
-
* 打分口径(从高到低):标签完全等于关键词 > 标签包含关键词 > 描述包含关键词。
|
|
51
|
-
* 同分时按传入顺序(调用方传的是 addedAt 倒序,即新的优先)。只看 approved
|
|
52
|
-
* 且 exists 的条目——「未审核」不进聊天,磁盘上没了的也点不出来。
|
|
53
|
-
*
|
|
54
|
-
* @returns 命中条目的绝对路径,或 null(匹配不上就是没写)。
|
|
55
|
-
*/
|
|
56
|
-
export function pickStickerByTag(candidates, key, pathOf) {
|
|
57
|
-
const target = String(key ?? '').trim().toLowerCase();
|
|
58
|
-
if (target === '')
|
|
59
|
-
return null;
|
|
60
|
-
let bestScore = 0;
|
|
61
|
-
let bestFile = null;
|
|
62
|
-
for (const item of candidates) {
|
|
63
|
-
if (!item.approved || !item.exists || item.file === '')
|
|
64
|
-
continue;
|
|
65
|
-
let score = 0;
|
|
66
|
-
for (const tag of item.tags) {
|
|
67
|
-
const t = String(tag ?? '').trim().toLowerCase();
|
|
68
|
-
if (t === '')
|
|
69
|
-
continue;
|
|
70
|
-
if (t === target)
|
|
71
|
-
score = Math.max(score, 3);
|
|
72
|
-
else if (t.includes(target) || target.includes(t))
|
|
73
|
-
score = Math.max(score, 2);
|
|
74
|
-
}
|
|
75
|
-
const desc = String(item.description ?? '').toLowerCase();
|
|
76
|
-
if (desc !== '' && desc.includes(target))
|
|
77
|
-
score = Math.max(score, 1);
|
|
78
|
-
if (score > bestScore) {
|
|
79
|
-
bestScore = score;
|
|
80
|
-
bestFile = item.file;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
return bestFile === null ? null : pathOf(bestFile);
|
|
84
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 正文表情包标签(2026-11-23 主人批准的最小版):
|
|
3
|
-
* 借鉴 aurabot 的 `<sticker:标签>` 协议,但只借「用标签代替挑文件」这一点。
|
|
4
|
-
*
|
|
5
|
-
* 模型在正文里写 `<表情:得意>`(也认 `<sticker:得意>` / `<表情包:得意>`),
|
|
6
|
-
* 出站时把标签摘掉,按关键词去「已审核」库里找一张最贴的图,作为独立消息
|
|
7
|
-
* 发出去;匹配不上就当作没写——**绝不报错、绝不把标签原样发到 QQ**。
|
|
8
|
-
*
|
|
9
|
-
* 为什么不整段照搬 aurabot:它把 `|||` 分气泡、`<voice>`、`<reply:`、`[沉默]`
|
|
10
|
-
* 全塞进正文,全靠正则切。我们已经有 splitIntoBubbles、掷骰语音条、[[reply:]]
|
|
11
|
-
* 和 [[不回]],再叠一层只会互相打架;真正省事的只有表情包这一条。
|
|
12
|
-
* @module dsh-onebot/sticker-tag
|
|
13
|
-
*/
|
|
14
|
-
/** 正文里的表情包标签:`<表情:关键词>` / `<sticker:关键词>` / `<表情包:关键词>`。
|
|
15
|
-
* 关键词里不认尖括号和换行,长度给个上限免得太贪。 */
|
|
16
|
-
export declare const STICKER_TAG_RE: RegExp;
|
|
17
|
-
/** 摘标签的结果:`text` 是去掉标签后的正文,`keys` 是按出现顺序去重后的关键词。 */
|
|
18
|
-
export interface StickerTagParse {
|
|
19
|
-
text: string;
|
|
20
|
-
keys: string[];
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* 从正文里摘掉全部表情包标签。
|
|
24
|
-
*
|
|
25
|
-
* 只认完整成对形态 `<…:…>`;写成 `<表情:` 没收尾、或者正文里讨论这个语法
|
|
26
|
-
* 本身(带了反引号)时都不动——宁可少发一张图,也不要把半截标签发出去。
|
|
27
|
-
* 反引号包裹的整段(`` `<表情:得意>` ``)保留原样,那是说明文字不是指令。
|
|
28
|
-
*/
|
|
29
|
-
export declare function extractStickerTags(raw: string): StickerTagParse;
|
|
30
|
-
/** 匹配用的最小条目形状——只取 StickerStore.list() 里用得到的字段。 */
|
|
31
|
-
export interface StickerCandidate {
|
|
32
|
-
file: string;
|
|
33
|
-
tags: string[];
|
|
34
|
-
description: string;
|
|
35
|
-
approved: boolean;
|
|
36
|
-
exists: boolean;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* 按关键词在候选里挑一张。
|
|
40
|
-
*
|
|
41
|
-
* 打分口径(从高到低):标签完全等于关键词 > 标签包含关键词 > 描述包含关键词。
|
|
42
|
-
* 同分时按传入顺序(调用方传的是 addedAt 倒序,即新的优先)。只看 approved
|
|
43
|
-
* 且 exists 的条目——「未审核」不进聊天,磁盘上没了的也点不出来。
|
|
44
|
-
*
|
|
45
|
-
* @returns 命中条目的绝对路径,或 null(匹配不上就是没写)。
|
|
46
|
-
*/
|
|
47
|
-
export declare function pickStickerByTag(candidates: readonly StickerCandidate[], key: string, pathOf: (file: string) => string): string | null;
|