dsh-qqbot-muu 0.1.3 → 0.1.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/README.md CHANGED
@@ -32,7 +32,7 @@
32
32
  | 🧠 **记得住人** | 两层记忆 + 类海马体检索,A 群的坏情绪不带去 B 群 |
33
33
  | 💬 **说人话** | 人格与世界书注入,语气被日常一点点养出来 |
34
34
  | 🖼 **会用表情包** | 本地视觉模型打标,情绪到位自己发一张 |
35
- | 🐋 **桌宠** | 三形态小蓝住在你桌面上,还能开成公网链接给指定的人看 |
35
+ | 🐋 **桌宠** | 四形态住在你桌面上:小蓝三套形象 + 原生大肥鱼,可开成公网链接给指定的人看 |
36
36
  | 🎬 **会出片** | 文案→分镜→出图质检→配音→字幕→成片,主人说「通过」才发 |
37
37
  | 📢 **会运营** | B 站扫码登录、发动态、AI 写评论草稿、数据留档 |
38
38
  | 🔒 **数据主权** | 一切落在本机;导出/彻底删除都有接口,还有审计日志 |
@@ -81,10 +81,11 @@ TTS 分段合成 + 句间呼吸 + ffmpeg 人声后处理,全篇语速平稳不
81
81
 
82
82
  </details>
83
83
 
84
- ### 🐋 桌宠(三形态)
85
- 小蓝以三种形态住在桌面上:**原版少女 / 女仆装立绘 / Q 版 de 娘**,
84
+ ### 🐋 桌宠(四形态)
85
+ 四个形态住在桌面上:**原版少女 / 女仆装立绘 / Q 版 de 娘** 三个自绘形象,加上 dsh-pet 原生的 **MuU 大肥鱼**(16 个动作全套:写代码、三球抛接、女仆舞……)。
86
86
  浮窗一键切换、动作按钮直接让她挥手/开心/说话/被拎起;「⏻ 开关」整体显隐。
87
87
  还能发布成**限制人数的公网链接**:访问码登录 + 单席位 + 可重置踢人 + 防爆破限速,
88
+ 网页端同样能切形态、发整活动作、按住拎起——桌面桌宠同步做出动作;
88
89
  本机不开任何入站端口(本机连接器主动外连云端代答),dsh token 全程不出你的电脑。
89
90
 
90
91
  <details>
@@ -112,10 +113,20 @@ B 站扫码登录(Cookie 只落本机)、分享卡片、发/删动态、AI
112
113
 
113
114
  ## 🚀 快速开始(初次下载看这里)
114
115
 
116
+ > **⏱ 只想要一条命令?** 装好 [DSH 桌面端](https://github.com/awesome-dsh-plugin/awesome-dsh-plugin)和 Node.js ≥ 22.5,然后 PowerShell 里执行:
117
+ >
118
+ > ```powershell
119
+ > dsh plugin add github:wuwo1979/dsh-qqbot-muu#main
120
+ > ```
121
+ >
122
+ > 重启 DSH 桌面端 → 浮窗出现「🧠 记忆 / 🐋 桌宠」页签 = 装好了,不用再看下面。
123
+ > 下面的分步教程是给想搞懂每一步的人准备的;卡住了直接跳 [新手常见问题](#-新手常见问题)。
124
+
115
125
  ### 0. 前置条件
116
126
 
117
127
  - **Node.js ≥ 22.5**(用到内置 `node:sqlite`)
118
128
  - **DSH 桌面端**([下载地址](https://github.com/awesome-dsh-plugin/awesome-dsh-plugin))
129
+ - **QQ 机器人凭据**:在 [QQ 开放平台](https://q.qq.com) 创建机器人拿到 `QQBOT_APPID` / `QQBOT_SECRET`(设置成环境变量或写进 bot 数据根的配置)
119
130
  - 可选增强(缺了会自动降级,不会带病跑):Python + Pillow(视频文字动效)、ffmpeg(音效与拼片)、Ollama(本地代答/打标/向量)
120
131
 
121
132
  ### 1. 安装插件(三选一)
@@ -152,6 +163,15 @@ ollama pull nomic-embed-text # 缺了自动退回关键词检索
152
163
  2. 浮窗出现「🧠 记忆 / 🔗 账号管理 / 🐋 桌宠」等页签 = 插件已挂载
153
164
  3. 群里 @ 她说句话,浮窗「聊天」页能看到消息 = 链路通了
154
165
 
166
+ ### 🆘 新手常见问题
167
+
168
+ | 症状 | 处理 |
169
+ |---|---|
170
+ | 重启后浮窗没有新页签 | 浮窗里按 `Ctrl+F5` 强刷;再不行确认插件目录名是 `dsh-qqbot-muu` |
171
+ | `dsh` 命令找不到 | dsh CLI 由 DSH 桌面端提供;先装桌面端并重开终端,或用上面的方式二/三 |
172
+ | 提示 `node:sqlite` 不可用 | Node 版本低于 22.5,去 nodejs.org 升级 LTS |
173
+ | 安装时提示数据目录 | `--data-root` 是你给 bot 的空文件夹,填一个新建目录即可 |
174
+
155
175
  ### 4. 常用入口
156
176
 
157
177
  | 想做什么 | 去哪里 |
@@ -195,6 +215,29 @@ overlay 体系保留作为备份与迁移工具。
195
215
 
196
216
  </details>
197
217
 
218
+ ## 🔒 访问控制(默认拒绝陌生人)
219
+
220
+ **装完默认谁都不回话**:`c2cMode` / `groupMode` 默认 `allowlist` 且白名单为空 → 任何私聊 / @ 都不进 AI,零 token 消耗(早期版本默认全开,v0.1.5 起改为安全默认)。
221
+
222
+ 三档可选(配置 `access` 段):
223
+
224
+ | 模式 | 行为 | 适合 |
225
+ |---|---|---|
226
+ | `allowlist`(默认) | 只回白名单内的会话 | 有外部用户时 |
227
+ | `open` | 任何人可用 | 只有自己在用的私人实例 |
228
+ | `disabled` | 完全关闭该通道 | 只要桌宠不要聊天 |
229
+
230
+ ```yaml
231
+ access:
232
+ c2cMode: allowlist
233
+ c2cAllow: ['你的用户openid'] # "*" = 全部放行
234
+ groupMode: allowlist
235
+ groupAllow: ['群openid']
236
+ ```
237
+
238
+ > 不知道 openid?试者在群里 @ 她一句,然后 `harness.log` 搜 `not in allowlist`,括号里就是;
239
+ > 拒绝时日志会打醒目提示(不会静默)。
240
+
198
241
  ## 🔒 隐私
199
242
 
200
243
  **仓库与 npm 包里不包含**:真实 openid / 群号 / 聊天记录 / B 站与抖音 Cookie / API Key /
@@ -244,9 +287,9 @@ submission/ 插件市场提交条目
244
287
 
245
288
  ## 市场收录
246
289
 
247
- - 条目:`submission/wuwo1979__dsh-qqbot-muu.yml`
248
- - 截图:`screenshots.json`(仓库根,全部为脱敏设计稿)
249
- - 本地预检:`node scripts/check-submission.mjs`
290
+ - 已收录于 [awesome-dsh-plugin](https://github.com/awesome-dsh-plugin/awesome-dsh-plugin)(DSH 桌面端内置插件市场的数据源)
291
+ - 条目:`submission/wuwo1979__dsh-qqbot-muu.yml`(本地预检:`node scripts/check-submission.mjs`)
292
+ - **更新机制**:市场不会自动跟随本仓库发版。每发一个新 Release,需要向上游仓库提 PR,把条目里的 `tarball:` 指到新版本——已随 v0.1.4 完成
250
293
 
251
294
  ## 致谢与许可
252
295
 
@@ -4496,6 +4496,7 @@ html += '<div class="dk-msg" style="font-size:11px;color:#888;line-height:1.6">
4496
4496
  + '</div>'
4497
4497
  html += '<div id="dk-pet-box"><div class="dk-msg" style="font-size:11px;color:#888">桌宠面板加载中…(宿主没启动时会提示原因,不会一直空着)</div></div>'
4498
4498
  html += '<div class="dk-msg" style="font-size:11px;color:#888;line-height:1.6;margin:4px 0 0">点动作按钮 = 桌面上的桌宠立刻做这个动作;右上按钮整体开关桌宠;手机/平板也能用网页版(见浮窗页脚地址)。</div>'
4499
+ html += '<div id="dk-invite" style="margin:8px 0 2px"><div class="dk-msg" style="font-size:11px;color:#888">邀请信息加载中…</div></div>'
4499
4500
  return html
4500
4501
  }
4501
4502
  function petRender() {
@@ -4541,8 +4542,56 @@ html += '<div class="dk-msg" style="font-size:11px;color:#888;line-height:1.6">
4541
4542
  if (box) box.innerHTML = '<div class="dk-msg" style="font-size:11px;color:#c66;line-height:1.6">🐋 ' + esc(msg)
4542
4543
  + '<br>桌宠动作/预览不可用;启动宿主(DSH Desktop)后本面板自动恢复。</div>'
4543
4544
  }
4545
+ // ── 邀请共享(2026-11-01 主人要求:密钥版/免密钥版两个入口,密钥可见可复制)──
4546
+ function inviteRender(d) {
4547
+ var el = panel && panel.querySelector('#dk-invite')
4548
+ if (!el) return
4549
+ if (!d || !d.ok) {
4550
+ el.innerHTML = '<div class="dk-msg" style="font-size:11px;color:#888">🔗 邀请共享不可用:' + esc((d && d.message) || '网关未部署') + '</div>'
4551
+ return
4552
+ }
4553
+ var free = d.freeMode === true
4554
+ var modeBtn = free
4555
+ ? '<button class="dk-btn" id="dk-inv-free" style="font-size:12px;padding:2px 10px;background:#fff2f0;border-color:#dba;color:#c66">🔒 关闭免密钥(恢复验码)</button>'
4556
+ : '<button class="dk-btn" id="dk-inv-free" style="font-size:12px;padding:2px 10px">🔓 免密钥邀请(限 1 人直进)</button>'
4557
+ el.innerHTML = '<div class="dk-msg" style="font-size:12px;font-weight:700;margin:2px 0">🔗 邀请共享桌宠 <span style="font-weight:400;color:#888;font-size:11px">(在线 ' + (d.seatsUsed == null ? '?' : d.seatsUsed) + '/' + esc(String(d.seatsMax == null ? 1 : d.seatsMax)) + ' 人)</span></div>'
4558
+ + '<div class="dk-msg" style="font-size:11px;color:#556;line-height:1.7;margin:2px 0;word-break:break-all">链接:<a href="' + esc(d.url) + '" target="_blank" rel="noopener">' + esc(d.url) + '</a><br>访问码:<b id="dk-inv-key">' + esc(d.key || '(免密钥模式无需访问码)') + '</b></div>'
4559
+ + '<div class="dk-row" style="gap:6px;flex-wrap:wrap;margin:4px 0">'
4560
+ + '<button class="dk-btn" id="dk-inv-copy" style="font-size:12px;padding:2px 10px">📋 复制有密钥邀请</button>'
4561
+ + modeBtn
4562
+ + '<button class="dk-btn" id="dk-inv-reset" style="font-size:12px;padding:2px 10px">♻️ 踢掉在线者</button>'
4563
+ + '</div>'
4564
+ + '<div class="dk-msg" style="font-size:11px;color:#99a;line-height:1.5;margin:2px 0 0">QQ 内打开受限时,请让对方长按链接选「浏览器打开」。免密钥模式下拿到链接即可进,仍限 1 人同时在线;随时可关闭恢复验码。</div>'
4565
+ el._data = d
4566
+ }
4567
+ function inviteRefresh() {
4568
+ fetch('/api/qqbot-settings/pet-share').then(function (r) { return r.json() }).then(function (d) { inviteRender(d) }).catch(function (e2) { inviteRender(null) })
4569
+ }
4570
+ function inviteCopy(d) {
4571
+ var t = '来看我的桌宠小蓝~(点右上角用浏览器打开)\n' + d.url + '\n访问码:' + (d.key || '(免密钥,直接进)')
4572
+ if (navigator.clipboard && navigator.clipboard.writeText) {
4573
+ navigator.clipboard.writeText(t).then(function () { petShareMsg('已复制邀请(链接+访问码),发给对方即可') }, function () { fallbackCopy(t) })
4574
+ } else fallbackCopy(t)
4575
+ }
4576
+ function fallbackCopy(t) {
4577
+ try {
4578
+ var ta = document.createElement('textarea'); ta.value = t; document.body.appendChild(ta); ta.select()
4579
+ document.execCommand('copy'); document.body.removeChild(ta)
4580
+ petShareMsg('已复制邀请(链接+访问码),发给对方即可')
4581
+ } catch (e2) { petShareMsg('复制失败,请手动选中链接与访问码') }
4582
+ }
4583
+ function petShareMsg(t) {
4584
+ var el = panel && panel.querySelector('#dk-invite')
4585
+ if (!el) return
4586
+ var m = el.querySelector('.dk-msg:last-child')
4587
+ if (m) { m.textContent = t; m.style.color = '#2c8'; setTimeout(function () { inviteRefresh() }, 2600) }
4588
+ }
4544
4589
  function petRefresh() {
4545
- fetch('/api/qqbot-settings/pet-anim').then(function (r) { return r.json() }).then(function (d) {
4590
+ // 2026-11-01:8s 超时 + 4s 自动重试(以前 fetch 挂死就永远卡「加载中」,赶上宿主重启必现)
4591
+ var ctl = (typeof AbortController === 'function') ? new AbortController() : null
4592
+ var timer = ctl && setTimeout(function () { try { ctl.abort() } catch (eRT) { } }, 8000)
4593
+ fetch('/api/qqbot-settings/pet-anim', ctl ? { signal: ctl.signal } : undefined).then(function (r) { return r.json() }).then(function (d) {
4594
+ if (timer) clearTimeout(timer)
4546
4595
  if (!d || !d.ok) { petError('桌宠接口没就绪(桌宠插件没跑起来)'); return }
4547
4596
  PET_STATE.form = (d.form && d.form.id) || 'xiaolan'
4548
4597
  PET_STATE.forms = d.forms || []
@@ -4551,12 +4600,18 @@ html += '<div class="dk-msg" style="font-size:11px;color:#888;line-height:1.6">
4551
4600
  var tg = panel && panel.querySelector('#dk-pet-toggle')
4552
4601
  if (tg) tg.textContent = (d.petOn === false) ? '⏻ 开启桌宠' : '⏻ 关闭桌宠'
4553
4602
  petRender()
4554
- }).catch(function () { petError('连不上桌宠服务(宿主没开?)') })
4603
+ }).catch(function () {
4604
+ if (timer) clearTimeout(timer)
4605
+ var box = panel && panel.querySelector('#dk-pet-box')
4606
+ if (box) box.innerHTML = '<div class="dk-msg" style="font-size:11px;color:#b8860b;line-height:1.6">🐋 宿主连接中…(4 秒后自动重试;启动 DSH Desktop 后本面板自动恢复)</div>'
4607
+ if (panel) setTimeout(petRefresh, 4000)
4608
+ })
4555
4609
  }
4556
4610
  function bindPetCompanion() {
4557
4611
  if (!panel || panel._petBound) return
4558
4612
  panel._petBound = 1
4559
4613
  petRefresh()
4614
+ inviteRefresh()
4560
4615
  // 事件委托挂 panel(仿 _modelsBound),body 重绘不丢
4561
4616
  panel.addEventListener('click', function (ev) {
4562
4617
  var t = ev.target
@@ -4590,6 +4645,33 @@ html += '<div class="dk-msg" style="font-size:11px;color:#888;line-height:1.6">
4590
4645
  }).catch(function () { if (t) t.disabled = false })
4591
4646
  return
4592
4647
  }
4648
+ // ── 邀请共享按钮(2026-11-01)──
4649
+ if (t.id === 'dk-inv-copy') {
4650
+ var inv = panel.querySelector('#dk-invite')
4651
+ if (inv && inv._data) inviteCopy(inv._data)
4652
+ return
4653
+ }
4654
+ if (t.id === 'dk-inv-free') {
4655
+ if (t.disabled) return
4656
+ t.disabled = true
4657
+ var turningFree = !(panel.querySelector('#dk-invite')._data && panel.querySelector('#dk-invite')._data.freeMode === true)
4658
+ apiPost('pet-share', { action: 'free-mode', on: turningFree }, 20000).then(function (d) {
4659
+ t.disabled = false
4660
+ petShareMsg((d && d.ok) ? (d.message || '已切换') : ('✗ ' + ((d && d.message) || '切换失败')))
4661
+ setTimeout(inviteRefresh, 1200)
4662
+ }).catch(function () { t.disabled = false })
4663
+ return
4664
+ }
4665
+ if (t.id === 'dk-inv-reset') {
4666
+ if (t.disabled) return
4667
+ t.disabled = true
4668
+ apiPost('pet-share', { action: 'reset-seat' }, 20000).then(function (d) {
4669
+ t.disabled = false
4670
+ petShareMsg((d && d.ok) ? (d.message || '已重置席位') : ('✗ ' + ((d && d.message) || '重置失败')))
4671
+ setTimeout(inviteRefresh, 1200)
4672
+ }).catch(function () { t.disabled = false })
4673
+ return
4674
+ }
4593
4675
  var nm = t.getAttribute('data-pet')
4594
4676
  var rnd = t.id === 'dk-pet-random'
4595
4677
  if (!nm && !rnd) return
@@ -6944,7 +7026,7 @@ html += '<div class="dk-msg" style="font-size:11px;color:#888;line-height:1.6">
6944
7026
  h.innerHTML = '<img src="data:image/png;base64,' + QQS_WHALE_B64 + '" alt="" style="width:22px;height:22px;border-radius:50%;object-fit:cover;flex:none;background:#e3f4ff"><span>QQ 群管理台</span>'
6945
7027
  + '<select class="qqs-sel" id="dk-ns" style="max-width:220px">' + (opts || '<option value="">无账号(去账号页添加)</option>') + '</select>'
6946
7028
  + '<span style="flex:1"></span>'
6947
- + '<span class="dk-msg" id="dk-headmsg" style="color:#888;font-size:12px">直连 QQ 官方 · 面板操作 = 主人直发 · v1101a</span>'
7029
+ + '<span class="dk-msg" id="dk-headmsg" style="color:#888;font-size:12px">直连 QQ 官方 · 面板操作 = 主人直发 · v1101c4</span>'
6948
7030
  + '<button class="dk-btn" id="dk-full" title="全屏/还原">⛶</button>'
6949
7031
  + '<button class="dk-btn" id="dk-close" title="收回成球">➖</button>'
6950
7032
  var fb = h.querySelector('#dk-full')
package/cordis.patch.yml CHANGED
@@ -25,9 +25,11 @@
25
25
  processingTimeoutMs: 120000
26
26
  historyLimit: 10
27
27
  access:
28
- c2cMode: open
28
+ # 安全默认:allowlist + 空白名单 = 拒绝所有陌生人(2026-11-02 市场合规)。
29
+ # 想全开:改 open;想精准放行:往 Allow 数组填 openid(harness.log 搜 "not in allowlist" 可取)
30
+ c2cMode: allowlist
29
31
  c2cAllow: []
30
- groupMode: open
32
+ groupMode: allowlist
31
33
  groupAllow: []
32
34
  debug: false
33
35
 
package/dist/config.js CHANGED
@@ -345,14 +345,14 @@ const ConfigSchemaRaw = Schema.object({
345
345
  .description('无上下文模式·智能判断(与 contextlessWindow 互斥): 让 AI 自己判断话题并自主压缩/丢弃上下文,只留它自己的备忘'),
346
346
  contextMemoMaxItems: Schema.number().default(20).description('备忘条数上限(超出自动丢最旧)'),
347
347
  access: Schema.object({
348
- c2cMode: Schema.union(['open', 'allowlist', 'disabled']).default('open').description('C2C访问模式'),
349
- c2cAllow: Schema.array(Schema.string()).default([]).description('C2C白名单'),
350
- groupMode: Schema.union(['open', 'allowlist', 'disabled']).default('open').description('群聊访问模式'),
351
- groupAllow: Schema.array(Schema.string()).default([]).description('群聊白名单'),
348
+ c2cMode: Schema.union(['open', 'allowlist', 'disabled']).default('allowlist').description('C2C访问模式(默认 allowlist:空白名单=拒绝所有陌生人,安全默认 2026-11-02 市场合规)'),
349
+ c2cAllow: Schema.array(Schema.string()).default([]).description('C2C白名单(用户 openid;"*"=全部)'),
350
+ groupMode: Schema.union(['open', 'allowlist', 'disabled']).default('allowlist').description('群聊访问模式(默认 allowlist)'),
351
+ groupAllow: Schema.array(Schema.string()).default([]).description('群白名单(群 openid;"*"=全部)'),
352
352
  }).default({
353
- c2cMode: 'open',
353
+ c2cMode: 'allowlist',
354
354
  c2cAllow: [],
355
- groupMode: 'open',
355
+ groupMode: 'allowlist',
356
356
  groupAllow: [],
357
357
  }).description('访问控制'),
358
358
  behavior: behaviorSchema,
@@ -134,14 +134,26 @@ pluginCtx) {
134
134
  // 2. 消息过滤:bot 回声 + 消息去重
135
135
  bot.use(messageFilter({ skipSelfEcho: false }));
136
136
  // 3. 访问控制(白名单/开放/禁用)
137
+ // 2026-11-02 安全修复:删除「空白名单回落 ['*']」——那会让 allowlist 模式形同虚设
138
+ // (装完任何 QQ 用户/群都能私聊或 @ 机器人)。现在空白名单 = 拒绝所有人,并打醒目日志指路。
139
+ for (const [label, mode, allow] of [
140
+ ['C2C(私聊)', config.access.c2cMode, config.access.c2cAllow],
141
+ ['群聊', config.access.groupMode, config.access.groupAllow],
142
+ ]) {
143
+ if (mode === 'allowlist' && allow.length === 0) {
144
+ logger.warn(`[访问控制] ${label} 为 allowlist 模式但白名单为空 → 所有${label}消息将被拒绝。` +
145
+ `放行方法:在配置 access 段把对应 Allow 数组填上 openid(可在 harness.log 搜 "not in allowlist" 拿到);` +
146
+ `或把 c2cMode/groupMode 显式设为 "open"(无门槛,任何人可用);"*" 通配符=全部放行。`);
147
+ }
148
+ }
137
149
  bot.use(accessPolicy({
138
150
  c2c: {
139
151
  mode: config.access.c2cMode,
140
- allow: config.access.c2cAllow.length > 0 ? config.access.c2cAllow : ['*'],
152
+ allow: config.access.c2cAllow,
141
153
  },
142
154
  group: {
143
155
  mode: config.access.groupMode,
144
- allow: config.access.groupAllow.length > 0 ? config.access.groupAllow : ['*'],
156
+ allow: config.access.groupAllow,
145
157
  },
146
158
  onBlock: (_mCtx, reason) => {
147
159
  if (config.debug) {
@@ -121,6 +121,7 @@ const PET_PAGE = `<!doctype html><html lang="zh-CN"><head><meta charset="utf-8">
121
121
  跨外网访问需自建隧道(默认不开,注意隐私);按钮控制的是这台电脑桌面上的桌宠本体。</footer>
122
122
  <script>
123
123
  var F=null;var V=document.getElementById('v');
124
+ function dirId(){if(F&&F.forms){for(var i=0;i<F.forms.length;i++){if(F.forms[i].active)return F.forms[i].id}}return (F&&F.form&&F.form.id)||'xiaolan'}
124
125
  function media(f,n){return '/api/qqbot-settings/pet-media?form='+encodeURIComponent(f)+'&name='+encodeURIComponent(n)}
125
126
  function post(b){return fetch('/api/qqbot-settings/pet-anim',{method:'POST',headers:{'content-type':'application/json'},body:JSON.stringify(b)}).then(function(r){return r.json()})}
126
127
  function esc(s){return String(s).replace(/[&<>"']/g,function(c){return{'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;',"'":'&#39;'}[c]})}
@@ -129,9 +130,9 @@ function render(){var f=F.form||'xiaolan';document.getElementById('title').textC
129
130
  document.getElementById('forms').innerHTML=fh;
130
131
  var ah='';for(var j=0;j<F.anims.length;j++){var a=F.anims[j];ah+='<button data-n="'+esc(a.name)+'">'+esc(a.label)+'</button>'}
131
132
  document.getElementById('anims').innerHTML=ah;
132
- if(!V.dataset.n)V.src=media(f,F.anims[0].name);
133
+ if(!V.dataset.n)V.src=media(dirId(),F.anims[0].name);
133
134
  Array.prototype.forEach.call(document.getElementById('forms').children,function(b){b.onclick=function(){st('切换中…');post({action:'switch-form',target:b.dataset.f}).then(function(r){st(r.ok?('已切换为『'+(r.label||b.dataset.f)+'』'):'切换失败');load()})}});
134
- Array.prototype.forEach.call(document.getElementById('anims').children,function(b){b.onclick=function(){st('做了动作:'+b.textContent);V.src=media(F.form.id||f,b.dataset.n);V.play&&V.play();post({name:b.dataset.n}).then(function(r){st(r.ok?('桌面已做『'+b.textContent+'』'):'触发失败')})}});
135
+ Array.prototype.forEach.call(document.getElementById('anims').children,function(b){b.onclick=function(){st('做了动作:'+b.textContent);V.src=media(dirId(),b.dataset.n);V.play&&V.play();post({name:b.dataset.n}).then(function(r){st(r.ok?('桌面已做『'+b.textContent+'』'):'触发失败')})}});
135
136
  }
136
137
  function st(t){document.getElementById('st').textContent=t}
137
138
  function load(){fetch('/api/qqbot-settings/pet-anim').then(function(r){return r.json()}).then(function(j){if(!j.ok)return st('桌宠接口没就绪');var changed=!F||F.form.id!==j.form.id;F={form:j.form,formLabel:j.form.label,formEmoji:j.form.emoji,forms:j.forms,anims:j.anims};if(changed){V.dataset.n='';V.removeAttribute('src')}render();st('当前形态:'+j.form.label+' · 每5秒自动同步')}).catch(function(){st('连不上桌宠服务(宿主没开?)')})}
@@ -166,7 +167,38 @@ botpoll();setInterval(botpoll,10000);
166
167
  load();setInterval(load,5000);
167
168
  </script></body></html>`;
168
169
 
169
- const PET_MEDIA_PETIDS = { xiaolan: 'xiaolan', muu: 'main' }; // 形态→dsh-pet petId 白名单
170
+ const PET_MEDIA_PETIDS = { xiaolan: 'xiaolan', classic: 'classic', de: 'de', muu: 'main' }; // 形态→dsh-pet petId 白名单
171
+
172
+ // ── 邀请共享(2026-11-01 主人要求:陪玩界面提供密钥/免密钥两个入口)──────────
173
+ const GATE_SEC = () => join(fileURLToPath(import.meta.url), '..', '..', '..', '..', 'pet-gate', 'secrets.json');
174
+ function readGateSecrets() {
175
+ try {
176
+ const j = JSON.parse(readFileSync(GATE_SEC(), 'utf8'));
177
+ return j && j.cloudUrl ? j : null;
178
+ } catch { return null; }
179
+ }
180
+ /** 云端管理通道(同 agent.mjs 的平台 cookie 引导):adminKey 只在本机内存 */
181
+ async function cloudAdmin(sec, path, bodyObj) {
182
+ // 2026-11-01 修 403:平台门要求每个请求都带 sharecode(否则「链接不完整」403)。
183
+ // ① admin URL 直接拼 sharecode(根治);② 引导请求 redirect:'manual',接住 302 那一跳种的
184
+ // 平台 cookie(原来默认跟随重定向,最终响应里没有 set-cookie,cookie 永远为空)。
185
+ const base = String(sec.cloudUrl || '').split('?')[0];
186
+ const sharecode = (String(sec.cloudUrl || '').split('sharecode=')[1] || '').split('&')[0];
187
+ let cookie = '';
188
+ try {
189
+ const boot = await fetch(`${base}/?sharecode=${sharecode}`, { redirect: 'manual', signal: AbortSignal.timeout(15000) });
190
+ const sc = boot.headers.getSetCookie ? boot.headers.getSetCookie() : [];
191
+ cookie = sc.map((c) => c.split(';')[0]).join('; ');
192
+ } catch { /* 门没过就直连 */ }
193
+ const sep = path.includes('?') ? '&' : '?';
194
+ const r = await fetch(`${base}${path}${sep}sharecode=${sharecode}`, {
195
+ method: 'POST',
196
+ headers: { 'x-admin-key': sec.adminKey, 'content-type': 'application/json', ...(cookie ? { cookie } : {}) },
197
+ body: JSON.stringify(bodyObj || {}),
198
+ signal: AbortSignal.timeout(15000),
199
+ });
200
+ return r.json().catch(() => ({ ok: false, message: `http-${r.status}` }));
201
+ }
170
202
 
171
203
  function attach(serverCtx) {
172
204
  try {
@@ -195,6 +227,7 @@ function attach(serverCtx) {
195
227
  active: id === form,
196
228
  })),
197
229
  anims: f.anims,
230
+ pool: (f.randomPool || []).map((x) => (typeof x === 'string' ? { name: x, label: x } : { name: x.name, label: x.label || x.name })),
198
231
  petOn,
199
232
  });
200
233
  }
@@ -262,10 +295,11 @@ function attach(serverCtx) {
262
295
  };
263
296
  try {
264
297
  const u = new URL(req.url, 'http://localhost');
265
- const form = u.searchParams.get('form') || 'xiaolan';
298
+ const form0 = u.searchParams.get('form') || 'xiaolan';
299
+ const form = form0 === 'main' ? 'muu' : form0; // 兼容:旧页面把大肥鱼的 petId(main) 当 form 传
266
300
  const name = (u.searchParams.get('name') || '').trim();
267
301
  const petId = PET_MEDIA_PETIDS[form];
268
- if (!petId || !name || name.length > 80) return notFound('需要 form(xiaolan|muu) 与 name');
302
+ if (!petId || !name || name.length > 80) return notFound('需要 form(xiaolan|classic|de|muu) 与 name');
269
303
  let ep = webEndpoint();
270
304
  if (!ep) return notFound('桌宿没启动');
271
305
  const call = (e2) => fetch(`http://127.0.0.1:${e2.port}/dsh-pet-7340/thumb/${encodeURIComponent(petId)}/${encodeURIComponent(name)}.webm?token=${encodeURIComponent(e2.token)}`, { signal: AbortSignal.timeout(10000) });
@@ -303,7 +337,48 @@ function attach(serverCtx) {
303
337
  });
304
338
  } catch { /* 重复注册等,忽略 */ }
305
339
 
306
- if (typeof dispose === 'function') console.log('[pet-panel] /api/qqbot-settings/pet-anim + /pet + /pet-media + /pet-status 已挂载(v5:状态文件+好感度榜+桌宠右键菜单)');
340
+ // ── 邀请共享:陪玩页「🔗 邀请」卡接口(密钥显示 + 免密钥开关 + 重置席位)──
341
+ try {
342
+ ws.register({
343
+ kind: 'exact',
344
+ path: '/api/qqbot-settings/pet-share',
345
+ handler: async (req, res) => {
346
+ try {
347
+ const sec = readGateSecrets();
348
+ if (!sec) return sendJson(res, 200, { ok: false, message: 'pet-gate/secrets.json 不存在(网关还没部署过)' });
349
+ if (req.method === 'GET') {
350
+ // 云端实时状态(免密钥开关/席位占用);拉不到就用本地 secrets 兜底
351
+ const live = sec.adminKey ? await cloudAdmin(sec, '/admin/status', {}).catch(() => null) : null;
352
+ return sendJson(res, 200, {
353
+ ok: true,
354
+ url: sec.cloudUrl || '',
355
+ key: sec.accessKey || '',
356
+ freeMode: live ? live.freeMode === true : sec.freeMode === true,
357
+ seatsUsed: live ? live.seatsUsed : null,
358
+ seatsMax: live ? live.seatsMax : (sec.seats || 1),
359
+ });
360
+ }
361
+ if (req.method === 'POST') {
362
+ const body = await readJsonBody(req).catch(() => ({}));
363
+ if (body.action === 'free-mode') {
364
+ const r = await cloudAdmin(sec, '/admin/free-mode', { on: body.on === true });
365
+ return sendJson(res, 200, r);
366
+ }
367
+ if (body.action === 'reset-seat') {
368
+ const r = await cloudAdmin(sec, '/admin/reset-seat', {});
369
+ return sendJson(res, 200, r);
370
+ }
371
+ return sendJson(res, 200, { ok: false, message: '需要 action: free-mode / reset-seat' });
372
+ }
373
+ return sendJson(res, 200, { ok: false });
374
+ } catch (e) {
375
+ return sendJson(res, 200, { ok: false, message: String((e && e.message) || e) });
376
+ }
377
+ },
378
+ });
379
+ } catch { /* 重复注册等,忽略 */ }
380
+
381
+ if (typeof dispose === 'function') console.log('[pet-panel] /api/qqbot-settings/pet-anim + /pet + /pet-media + /pet-status + /pet-share 已挂载(v6:邀请共享+四形态)');
307
382
  // 桌宠右键菜单「更多」里挂「变小蓝/变大肥鱼」(dsh-pet 官方第三方菜单扩展点,长轮询消费点击)
308
383
  ensurePetMenu();
309
384
  } catch (e) {
@@ -1 +1 @@
1
- {"form":"muu","at":1793537305295}
1
+ {"form":"muu","at":1793590644012}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-qqbot-muu",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "独立的 DSH QQ 桌宠助手插件:统一记忆库/印象卡、人格注入、表情包视觉打标、三形态桌宠+公网受限链接、逐帧视频流水线、B站运营(自持底盘,零 @zaofan 依赖)",
5
5
  "type": "module",
6
6
  "main": "./entry.js",