@yangfan1998/dsh-qqbot-plus 0.1.1 → 0.1.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 CHANGED
@@ -10,7 +10,12 @@
10
10
 
11
11
  它是 **bundle**,不是 QQ 网关的 fork。网关仍然是 `@zaofan/dsh-qqbot`,可以独立升级。
12
12
 
13
- > 当前版本:`0.1.0`。已发布到 npm;本地也可以 `npm pack` 后安装。
13
+ 本机另外还有 9 个自写插件(热榜 / 论文 / QQ 音乐 / token 用量 / 视频生成 / 群聊心跳等),
14
+ 它们不发布到 npm,只放在 profile 的 `plugins/` 目录;清单见 [STATUS.md](./STATUS.md)。
15
+
16
+ > 当前版本:`0.1.2`(仓库)。npm 上最新已发布为 `0.1.1`,`0.1.2` 尚未发布成功(本机 npm 登录态失效)。
17
+ >
18
+ > 本机实际部署状态(桌面版托管、插件清单、已知问题)见 [STATUS.md](./STATUS.md)。
14
19
 
15
20
  ---
16
21
 
@@ -186,6 +191,7 @@ B 站会限流匿名请求;工具内部做了节流,并缓存匿名 `buvid3`
186
191
 
187
192
  - `extensions/inbound/bili-card-url.mjs` — 从 QQ 小程序卡片的 raw 数据里提取 B 站 URL。只接受 URL,不接受裸 `BV...`,因为 QQ message id 里可能刚好包含假 BV。
188
193
  - `extensions/outbound/abs-image-paths.mjs` — 发图前把 markdown 里的相对图片路径改成绝对路径。
194
+ - `extensions/outbound/random-sticker.mjs` — 回复发完后按概率从正式图库补一张表情包;只作用于群聊,默认 15% 概率、同一会话 10 分钟冷却。
189
195
 
190
196
  复制到 QQ 机器人的数据根:
191
197
 
@@ -200,6 +206,15 @@ cp "$PKG_DIR/extensions/outbound/abs-image-paths.mjs" "$DATA_ROOT/.qqbot-extensi
200
206
 
201
207
  `abs-image-paths` 默认用 `process.cwd()` 解析相对路径;如果宿主 cwd 和 `im-qqbot.cwd` 不一致,设置 `QQBOT_CWD`。
202
208
 
209
+ `random-sticker` 可调:
210
+
211
+ ```bash
212
+ QQBOT_STICKER_PROB=0.15 # 每次回复补图概率
213
+ QQBOT_STICKER_COOLDOWN_MIN=10 # 同一会话最短间隔(分钟)
214
+ ```
215
+
216
+ 它只从 `{dataRoot}/lib/library` 或 `{dataRoot}/表情包/lib/library` 里选图,不会用候选区/回收站的图。
217
+
203
218
  ---
204
219
 
205
220
  ## 不包含什么
@@ -16,5 +16,8 @@ the QQ bot's data root:
16
16
  - `abs-image-paths.mjs`: rewrites relative markdown image paths to absolute
17
17
  paths so the QQ uploader can find them. It resolves against `process.cwd()`;
18
18
  set `QQBOT_CWD` when the host cwd differs from `im-qqbot.cwd`.
19
+ - `random-sticker.mjs`: after a group reply, picks a sticker from the formal
20
+ `lib/library` with a configurable probability (`QQBOT_STICKER_PROB`, default
21
+ 0.15) and per-peer cooldown (`QQBOT_STICKER_COOLDOWN_MIN`, default 10).
19
22
 
20
23
  Reload extensions with `/tools-reload` (or restart the bot).
@@ -0,0 +1,96 @@
1
+ /**
2
+ * random-sticker.mjs — 回复发完后,按概率自动补一张表情包。
3
+ *
4
+ * 用 fork 的出站 turnEnd 阶段:正文已经发完,补图走先被动后主动通道,
5
+ * 不阻塞正文。只从 {dataRoot}/lib/library 里选「正式库」的图。
6
+ *
7
+ * 环境变量:
8
+ * QQBOT_STICKER_PROB=0.15 每次回复补图概率
9
+ * QQBOT_STICKER_COOLDOWN_MIN=10 同一会话最短间隔(分钟)
10
+ */
11
+ import { readdir, stat } from 'node:fs/promises'
12
+ import { join, extname } from 'node:path'
13
+
14
+ export const name = 'random-sticker'
15
+
16
+ const IMAGE_EXT = new Set(['.jpg', '.jpeg', '.png', '.gif', '.webp'])
17
+ const PROB = Math.max(0, Math.min(1, Number(process.env.QQBOT_STICKER_PROB ?? 0.15)))
18
+ const COOLDOWN_MS = Math.max(0, Number(process.env.QQBOT_STICKER_COOLDOWN_MIN ?? 10)) * 60_000
19
+ const RECENT_KEEP = 8
20
+
21
+ /** peerId -> last sent ms */
22
+ const lastSentAt = new Map()
23
+ /** 最近发过的文件,避免连续重复 */
24
+ const recent = []
25
+
26
+ async function listLibrary(dataRoot) {
27
+ const candidates = [
28
+ join(String(dataRoot || ''), 'lib', 'library'),
29
+ join(String(dataRoot || ''), '表情包', 'lib', 'library'),
30
+ join(process.cwd(), '表情包', 'lib', 'library'),
31
+ ]
32
+ for (const dir of candidates) {
33
+ if (!dir || dir.includes('undefined')) continue
34
+ let entries
35
+ try {
36
+ entries = await readdir(dir, { withFileTypes: true })
37
+ } catch {
38
+ continue
39
+ }
40
+ const out = []
41
+ for (const e of entries) {
42
+ if (!e.isFile()) continue
43
+ const ext = extname(e.name).toLowerCase()
44
+ if (!IMAGE_EXT.has(ext)) continue
45
+ const path = join(dir, e.name)
46
+ try {
47
+ const info = await stat(path)
48
+ if (info.isFile() && info.size > 0 && info.size <= 10 * 1024 * 1024) out.push(path)
49
+ } catch { /* skip */ }
50
+ }
51
+ if (out.length > 0) return out
52
+ }
53
+ return []
54
+ }
55
+
56
+ function pick(files) {
57
+ if (files.length === 0) return null
58
+ const fresh = files.filter((p) => !recent.includes(p))
59
+ const pool = fresh.length > 0 ? fresh : files
60
+ return pool[Math.floor(Math.random() * pool.length)] ?? null
61
+ }
62
+
63
+ export async function onOutbound(ctx, next) {
64
+ try {
65
+ if (ctx.phase !== 'turnEnd' || !ctx.isLastChunk) return next()
66
+ if (ctx.kind === 'media' || ctx.kind === 'card' || ctx.kind === 'forward') return next()
67
+ const scope = String(ctx.target?.scope ?? '')
68
+ if (scope && scope !== 'group') return next()
69
+ const text = String(ctx.text ?? '').trim()
70
+ if (!text || text.length < 2) return next()
71
+ if (/\[MEDIA:|!\[|qqbot-media:|\[表情/.test(text)) return next()
72
+
73
+ const peer = String(ctx.target?.peerId ?? '')
74
+ const now = Date.now()
75
+ const last = lastSentAt.get(peer) ?? 0
76
+ if (last && now - last < COOLDOWN_MS) return next()
77
+ if (Math.random() >= PROB) return next()
78
+
79
+ const files = await listLibrary(ctx.dataRoot)
80
+ const path = pick(files)
81
+ if (!path) return next()
82
+ lastSentAt.set(peer, now)
83
+ recent.push(path)
84
+ while (recent.length > RECENT_KEEP) recent.shift()
85
+
86
+ ctx.background(async () => {
87
+ try {
88
+ const ok = await ctx.sendMedia({ path })
89
+ if (!ok) ctx.note?.('random-sticker: sendMedia returned false')
90
+ } catch (e) {
91
+ ctx.logger?.warn?.(`[random-sticker] send failed: ${e instanceof Error ? e.message : String(e)}`)
92
+ }
93
+ })
94
+ } catch { /* 出站扩展永远不能影响正文 */ }
95
+ return next()
96
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yangfan1998/dsh-qqbot-plus",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "One-install DeepSeek Harness QQ bot bundle: @zaofan/dsh-qqbot gateway plus vision, Edge TTS and Bilibili reading tools.",
5
5
  "type": "module",
6
6
  "main": "index.js",