dsh-qqbot-muu 0.1.3 → 0.1.4

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.
@@ -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')
@@ -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":1793544038429}
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.4",
4
4
  "description": "独立的 DSH QQ 桌宠助手插件:统一记忆库/印象卡、人格注入、表情包视觉打标、三形态桌宠+公网受限链接、逐帧视频流水线、B站运营(自持底盘,零 @zaofan 依赖)",
5
5
  "type": "module",
6
6
  "main": "./entry.js",