qq-bot-roost 1.1.11 → 1.1.13

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/web/app.js CHANGED
@@ -342,11 +342,11 @@ async function deleteBot(id) {
342
342
  * 二维码内容是官方给的一个 URL,我们本地画成二维码(web/vendor/qrcode.js)。
343
343
  * 密钥(bindKey)留在服务端,前端只拿到 taskId。
344
344
  *
345
- * 两个入口共用这套逻辑,区别只在「扫完之后把值填哪」:
346
- * · `new` —— 新建机器人弹窗:填进 #nbAppId / #nbSecret,等用户补个 ID 再创建;
347
- * · `cfg` —— 配置页的连接凭证:填进 cfgForm,AppSecret 被重置、或者整只机器人
348
- * 换账号时用,点「保存设置」才生效(自动保存会在用户没反应过来时重连一次,
349
- * 扫码本来就可能是误点,不该顺带把在线连接掐掉)。
345
+ * 三个入口共用这套逻辑,区别只在「扫完之后把值填哪」:
346
+ * · `new` —— 新建机器人弹窗:填进 #nbAppId / #nbSecret,等用户补个 ID 再创建;
347
+ * · `cfg` —— 配置页的连接凭证:拿到新凭证即自动保存+上线(旧密钥已作废,
348
+ * 不落盘就用旧票据连不上),见 QR_SLOTS.cfg.onDone;
349
+ * · `setup` —— 首次启动引导:拿到凭证即保存到当前机器人并上线,见 QR_SLOTS.setup.onDone。
350
350
  *
351
351
  * 同一时刻只允许一个扫码任务:换位置扫会先把上一个收掉,免得两个 interval
352
352
  * 抢同一个 taskId、或者把结果填到已经关掉的弹窗里。
@@ -368,20 +368,44 @@ const QR_SLOTS = {
368
368
  },
369
369
  cfg: {
370
370
  box: '#cfgQr', code: '#cfgQrCode', tip: '#cfgQrTip', btn: '#cfgQrStart',
371
- hint: '用手机 QQ 扫码,确认后自动填到上面,再点「保存设置」生效',
372
- onDone(r) {
371
+ hint: '用手机 QQ 扫码,确认后自动保存新凭证并尝试上线',
372
+ async onDone(r) {
373
373
  const f = $('#cfgForm');
374
+ if (!f) return;
374
375
  f.appId.value = r.appId || '';
375
376
  // 扫码给的是完整的一对,直接覆盖输入框;留空会被后端当成「不修改」
376
377
  f.appSecret.value = r.appSecret || '';
378
+ const code = $('#cfgQrCode');
379
+ if (code) code.innerHTML = '';
377
380
  /**
378
- * 二维码已经用完了,留着只是一块黑白方块:清掉图纸,让提示单独留着,
379
- * 这样用户视线落在「点保存设置」上,而不是再扫一次。
381
+ * 只有走到这里(/qr/poll 返回 done、拿到新凭证)旧密钥才真正作废:
382
+ * 二维码还没扫、或还在 pending 时旧凭证依然有效,机器人照常在线,
383
+ * 所以 startQr 里不做任何破坏性动作。拿到新凭证后必须立刻保存并上线,
384
+ * 否则机器人会一直拿已失效的旧票据连不上。
380
385
  */
381
- const code = $('#cfgQrCode');
386
+ $('#cfgQrTip').textContent = `✓ 已拿到 AppID ${r.appId},正在保存并尝试上线…`;
387
+ const saved = await saveCfgForm({ fromQr: true });
388
+ if (saved) await tryOnlineAfterQr();
389
+ else {
390
+ const tip = $('#cfgQrTip');
391
+ if (tip) tip.textContent = '凭证没保存上,这张二维码已失效;请重新扫码或手动填写';
392
+ }
393
+ },
394
+ },
395
+ setup: {
396
+ box: '#setupQr', code: '#setupQrCode', tip: '#setupQrTip', btn: '#setupQrStart',
397
+ hint: '用手机 QQ 扫码,确认后自动配置并上线',
398
+ async onDone(r) {
399
+ const appId = $('#setupAppId');
400
+ const secret = $('#setupSecret');
401
+ if (appId) appId.value = r.appId || '';
402
+ if (secret) secret.value = r.appSecret || '';
403
+ const code = $('#setupQrCode');
382
404
  if (code) code.innerHTML = '';
383
- $('#cfgQrTip').textContent = `✓ 已换成 AppID ${r.appId},点「保存设置」生效`;
384
- $('#cfgSaveTop')?.focus();
405
+ const tip = $('#setupQrTip');
406
+ if (tip) tip.textContent = `✓ 已拿到 AppID ${r.appId},正在配置并上线…`;
407
+ const ok = await saveSetupCredentials(r.appId, r.appSecret, tip);
408
+ if (ok) markSetupDone('凭证已保存,机器人已上线。可以进入面板了。');
385
409
  },
386
410
  },
387
411
  };
@@ -463,7 +487,7 @@ async function pollQr() {
463
487
  if (r.status === 'pending') return;
464
488
  stopQrPoll();
465
489
  qrTaskId = '';
466
- if (r.status === 'done') els.s.onDone(r);
490
+ if (r.status === 'done') await els.s.onDone(r);
467
491
  else tip.textContent = r.message || '二维码失效了,重新生成一个';
468
492
  } catch (e) {
469
493
  stopQrPoll();
@@ -2462,7 +2486,22 @@ function bindAutoSave() {
2462
2486
 
2463
2487
  $('#cfgForm').addEventListener('submit', async (e) => {
2464
2488
  e.preventDefault();
2465
- const f = e.target;
2489
+ if (await saveCfgForm()) {
2490
+ const msg = $('#cfgMsgTop');
2491
+ setTimeout(() => { if (msg) msg.textContent = ''; }, 4000);
2492
+ }
2493
+ });
2494
+
2495
+ /**
2496
+ * 保存配置页表单。手动点「保存凭证」和扫码拿到新凭证后都走这里,
2497
+ * 保证「填进输入框」和「真正落盘」是同一条路径,不出现两套逻辑分叉。
2498
+ *
2499
+ * fromQr=true 时凭据刚刚失效(旧 AppSecret 已被扫码重置),消息要交给
2500
+ * tryOnlineAfterQr() 收尾,所以这里不设「4 秒后清空」。
2501
+ */
2502
+ async function saveCfgForm({ fromQr = false } = {}) {
2503
+ const f = $('#cfgForm');
2504
+ if (!f) return false;
2466
2505
  const lines = (v) => v.split(/[\n,]/).map((s) => s.trim()).filter(Boolean);
2467
2506
  const payload = {
2468
2507
  appId: f.appId.value.trim(),
@@ -2514,17 +2553,19 @@ $('#cfgForm').addEventListener('submit', async (e) => {
2514
2553
  };
2515
2554
 
2516
2555
  const btn = f.querySelector('button[type=submit]');
2517
- btn.disabled = true;
2556
+ if (btn) btn.disabled = true;
2518
2557
  $('#cfgMsgTop').textContent = '保存中…';
2519
2558
  try {
2520
2559
  const r = await api('/api/config', { method: 'PUT', body: JSON.stringify(payload) });
2521
2560
  // 后端在填完 AppID / AppSecret 后会把占位名换成官方昵称,这里同步显示
2522
2561
  const renamed = r?.name && r.name !== botById(CURRENT_BOT)?.name;
2523
2562
  // 换连接方式要重启才生效,后端会带 restartRequired + message,原样转达
2524
- $('#cfgMsgTop').textContent = r?.message
2525
- ? r.message
2526
- : (renamed ? `已保存,机器人昵称同步为「${r.name}」` : '已保存') +
2527
- (payload.appId ? '' : '(AppID 为空)');
2563
+ $('#cfgMsgTop').textContent = fromQr
2564
+ ? '新凭证已保存,正在尝试上线…'
2565
+ : r?.message
2566
+ ? r.message
2567
+ : (renamed ? `已保存,机器人昵称同步为「${r.name}」` : '已保存') +
2568
+ (payload.appId ? '' : '(AppID 为空)');
2528
2569
  f.appSecret.value = '';
2529
2570
  /**
2530
2571
  * 这份表单**包含 intents**,所以保存成功后要把「已应用值」跟上,
@@ -2533,21 +2574,237 @@ $('#cfgForm').addEventListener('submit', async (e) => {
2533
2574
  */
2534
2575
  intentsApplied = Number(payload.intents) || 0;
2535
2576
  renderIntentsDirty();
2536
- // 扫码换凭证的那条提示到此为止:凭证已落盘,再挂着「点保存设置」就是误导
2577
+ // 提示到此为止:凭证已落盘,再挂着「点保存设置」就是误导
2537
2578
  resetQr();
2538
2579
  clearCfgDirty();
2539
- setTimeout(() => ($('#cfgMsgTop').textContent = ''), 4000);
2540
2580
  await loadBots();
2541
- pollStatus();
2581
+ await pollStatus();
2582
+ return true;
2542
2583
  } catch (err) {
2543
2584
  $('#cfgMsgTop').textContent = '保存失败: ' + err.message;
2585
+ return false;
2544
2586
  } finally {
2545
- btn.disabled = false;
2587
+ if (btn) btn.disabled = false;
2546
2588
  }
2547
- });
2589
+ }
2590
+
2591
+ /**
2592
+ * 扫码换凭证后尝试上线。
2593
+ *
2594
+ * 旧密钥在拿到新凭证那一刻就作废了,网关可能还挂着用旧票据建立的连接,
2595
+ * 所以先下线清掉旧连接和实例锁,再用新凭证上线(offline 在已离线时是空操作)。
2596
+ * 上线失败不吞:后端给的 error 写回凭证区消息,状态区也会同步刷新。
2597
+ */
2598
+ async function tryOnlineAfterQr() {
2599
+ const msg = $('#cfgMsgTop');
2600
+ const ok = await bringBotOnline();
2601
+ if (msg) {
2602
+ msg.textContent = ok
2603
+ ? '凭证已保存,机器人已上线'
2604
+ : '凭证已保存,但上线失败(详见状态区)';
2605
+ const text = msg.textContent;
2606
+ setTimeout(() => { if (msg.textContent === text) msg.textContent = ''; }, 6000);
2607
+ }
2608
+ return ok;
2609
+ }
2610
+
2611
+ /**
2612
+ * 让当前(或第一只)机器人重新上线:先下线清掉旧票据连接和实例锁,再上线。
2613
+ * 配置页扫码、首次引导都走这里——上线结果由调用方决定怎么显示。
2614
+ * 返回 true/false,不吞错误(细节在状态区 / 机器人 error 字段里)。
2615
+ */
2616
+ async function bringBotOnline() {
2617
+ const botId = CURRENT_BOT || BOTS[0]?.id;
2618
+ if (!botId) return false;
2619
+ const id = encodeURIComponent(botId);
2620
+ try {
2621
+ await api(`/api/bots/${id}/offline`, { method: 'POST', body: '{}' });
2622
+ } catch { /* 本来就离线,忽略 */ }
2623
+ try {
2624
+ const r = await api(`/api/bots/${id}/online`, { method: 'POST', body: '{}' });
2625
+ if (r?.state === 'error' || r?.online === false) {
2626
+ throw new Error(r?.error || '连接失败');
2627
+ }
2628
+ await pollStatus();
2629
+ await loadBots();
2630
+ return true;
2631
+ } catch (e) {
2632
+ await pollStatus();
2633
+ await loadBots();
2634
+ return false;
2635
+ }
2636
+ }
2637
+
2638
+ /**
2639
+ * 首次引导:只提交 AppID / AppSecret(后端是增量保存,其它字段不动),
2640
+ * 然后上线。二维码扫完后也走这里,和手填共用同一条落盘路径。
2641
+ */
2642
+ async function saveSetupCredentials(appId, appSecret, tipEl) {
2643
+ if (!appId || !appSecret) {
2644
+ if (tipEl) tipEl.textContent = 'AppID 和 AppSecret 都要填';
2645
+ return false;
2646
+ }
2647
+ try {
2648
+ const r = await api('/api/config', {
2649
+ method: 'PUT',
2650
+ body: JSON.stringify({ appId, appSecret }),
2651
+ });
2652
+ if (r?.name && botById(CURRENT_BOT)) {
2653
+ // 昵称可能从占位名换成了官方名,刷新一下列表
2654
+ await loadBots();
2655
+ }
2656
+ const ok = await bringBotOnline();
2657
+ if (!ok && tipEl) tipEl.textContent = '凭证已保存,但上线失败;稍后可在「配置」页重试';
2658
+ return ok;
2659
+ } catch (e) {
2660
+ if (tipEl) tipEl.textContent = '保存失败:' + errText(e);
2661
+ return false;
2662
+ }
2663
+ }
2664
+
2665
+ /* ---------------- 首次启动引导 ---------------- */
2666
+
2667
+ /**
2668
+ * 引导是否该出现:只要当前机器人(或第一只)还没有 AppID,每次打开面板都弹。
2669
+ * 之前用 localStorage 记「跳过」标记,点过「稍后再说」就再也不弹——
2670
+ * 但引导的前提本就是「没填凭证」,跳过标记会让它和需求脱节:
2671
+ * 用户没配好就再也进不来引导。所以这里只看 AppID,不记任何标记。
2672
+ */
2673
+ function setupNeeded() {
2674
+ const bot = botById(CURRENT_BOT) || BOTS[0];
2675
+ // 全新安装:main 机器人配置在,但没有 AppID → 需要引导
2676
+ return Boolean(bot) && !bot.appId;
2677
+ }
2678
+
2679
+ // 引导弹层显示期间锁住背景滚动,关掉时恢复原值
2680
+ let setupBodyOverflow = null;
2681
+ let setupBodyPadRight = null;
2682
+
2683
+ function showSetup() {
2684
+ const mask = $('#setupMask');
2685
+ if (!mask) return;
2686
+ mask.hidden = false;
2687
+ /*
2688
+ * 滚轮落在遮罩(弹层以外的半透明区域)时,浏览器会去滚后面的面板。
2689
+ * 锁住 body 从根上掐断这种穿透;滚动条消失会让页面变宽,补一段 padding
2690
+ * 免得弹层位置跟着跳。原值在 hideSetup() 里还原。
2691
+ */
2692
+ if (setupBodyOverflow === null) {
2693
+ setupBodyOverflow = document.body.style.overflow;
2694
+ setupBodyPadRight = document.body.style.paddingRight;
2695
+ const gap = window.innerWidth - document.documentElement.clientWidth;
2696
+ if (gap > 0) document.body.style.paddingRight = `${gap}px`;
2697
+ document.body.style.overflow = 'hidden';
2698
+ }
2699
+ // 已有凭证的提示语按是否有 bot 调整
2700
+ const lead = $('#setupLead');
2701
+ if (lead) {
2702
+ lead.textContent = '还没有连接凭证。扫码最省事(手机 QQ 扫一下就有 AppID / AppSecret),'
2703
+ + '也可以手动填。配置好会自动保存并尝试上线。';
2704
+ }
2705
+ }
2706
+
2707
+ function hideSetup() {
2708
+ resetQr();
2709
+ const mask = $('#setupMask');
2710
+ if (mask) mask.hidden = true;
2711
+ if (setupBodyOverflow !== null) {
2712
+ document.body.style.overflow = setupBodyOverflow;
2713
+ document.body.style.paddingRight = setupBodyPadRight;
2714
+ setupBodyOverflow = null;
2715
+ setupBodyPadRight = null;
2716
+ }
2717
+ }
2718
+
2719
+ function skipSetup() {
2720
+ // 只是关掉弹层,不记跳过标记:没填 AppID 下次打开还会弹
2721
+ hideSetup();
2722
+ }
2723
+
2724
+ function markSetupDone(message) {
2725
+ // 配置已落盘,appId 会随 loadBots() 更新,setupNeeded() 自然不再成立
2726
+ const lead = $('#setupLead');
2727
+ if (lead) lead.textContent = '✓ ' + message;
2728
+ const err = $('#setupErr');
2729
+ if (err) err.hidden = true;
2730
+ // 成功后清掉输入框里的密钥,别留在 DOM 里
2731
+ const secret = $('#setupSecret');
2732
+ if (secret) secret.value = '';
2733
+ /*
2734
+ * 以前这里 setTimeout(hideSetup, 1200) 自动关弹层——用户还没看清
2735
+ * 「已上线」就被弹走,也没机会用第 2 步设公网访问。现在停在成功态,
2736
+ * 由用户自己点「完成,进入面板」才关。
2737
+ */
2738
+ const done = $('#setupDone');
2739
+ if (done) done.focus();
2740
+ }
2741
+
2742
+ function bindSetup() {
2743
+ // 手填保存
2744
+ $('#setupCredSave')?.addEventListener('click', async () => {
2745
+ const appId = $('#setupAppId')?.value.trim();
2746
+ const secret = $('#setupSecret')?.value.trim();
2747
+ const err = $('#setupErr');
2748
+ if (!appId || !secret) {
2749
+ if (err) { err.textContent = '请先填 AppID 和 AppSecret'; err.hidden = false; }
2750
+ return;
2751
+ }
2752
+ const btn = $('#setupCredSave');
2753
+ if (btn) btn.disabled = true;
2754
+ if (err) err.hidden = true;
2755
+ const ok = await saveSetupCredentials(appId, secret, err);
2756
+ if (btn) btn.disabled = false;
2757
+ if (ok) markSetupDone('凭证已保存,机器人已上线。可以进入面板了。');
2758
+ });
2759
+
2760
+ // 扫码
2761
+ $('#setupQrStart')?.addEventListener('click', () => startQr('setup'));
2762
+
2763
+ // 公网选项显隐
2764
+ $('#setupPublic')?.addEventListener('change', (e) => {
2765
+ const fields = $('#setupPublicFields');
2766
+ if (fields) fields.hidden = !e.target.checked;
2767
+ });
2768
+
2769
+ // 保存访问方式(webui 全局配置,增量提交;重启才生效)
2770
+ $('#setupNetSave')?.addEventListener('click', async () => {
2771
+ const key = $('#setupAccessKey')?.value.trim() || '';
2772
+ const host = $('#setupHost')?.value.trim() || '0.0.0.0';
2773
+ const port = Number($('#setupPort')?.value) || 15207;
2774
+ const err = $('#setupErr');
2775
+ if (!key) {
2776
+ if (err) { err.textContent = '对外服务必须设置访问密钥'; err.hidden = false; }
2777
+ return;
2778
+ }
2779
+ const btn = $('#setupNetSave');
2780
+ if (btn) btn.disabled = true;
2781
+ if (err) err.hidden = true;
2782
+ try {
2783
+ await api('/api/config', {
2784
+ method: 'PUT',
2785
+ body: JSON.stringify({ webui: { host, port, accessKey: key } }),
2786
+ });
2787
+ if (err) {
2788
+ err.textContent = '已保存。重启框架后生效:用局域网 / 公网地址加 ?key=你的密钥 访问面板。';
2789
+ err.hidden = false;
2790
+ err.classList.add('setup-ok');
2791
+ }
2792
+ const access = $('#setupAccessKey');
2793
+ if (access) access.value = '';
2794
+ } catch (e) {
2795
+ if (err) { err.textContent = '保存失败:' + errText(e); err.hidden = false; }
2796
+ } finally {
2797
+ if (btn) btn.disabled = false;
2798
+ }
2799
+ });
2800
+
2801
+ $('#setupSkip')?.addEventListener('click', skipSetup);
2802
+ $('#setupDone')?.addEventListener('click', skipSetup);
2803
+ }
2548
2804
 
2549
2805
  // 除连接凭证 / 事件订阅外的设置:改动即存
2550
2806
  bindAutoSave();
2807
+ bindSetup();
2551
2808
 
2552
2809
  /* ---------------- 通知:SMTP 邮箱配置 ---------------- */
2553
2810
 
@@ -7042,10 +7299,51 @@ function msgClass(text) {
7042
7299
  return '';
7043
7300
  }
7044
7301
 
7045
- function logLine(e) {
7302
+ /**
7303
+ * 视图层折叠:只把**连续相同**的 `[ext-bridge]` INFO 合成一行 ×N。
7304
+ * 思路照 pino-quiet(缓冲上一条,相同计数,不同才落新行),
7305
+ * 但只作用在展示层——logBuf 仍存每一条原始日志,搜索/过滤不受影响。
7306
+ */
7307
+ function foldKeyOf(e) {
7308
+ if (e?.level !== 'info' || !String(e.msg ?? '').startsWith('[ext-bridge] ')) return null;
7309
+ return `info|${e.tag ?? ''}|${e.msg}`;
7310
+ }
7311
+
7312
+ function bumpFold(el, e) {
7313
+ const n = Number(el.dataset.foldCount || 1) + 1;
7314
+ el.dataset.foldCount = String(n);
7315
+ const time = el.querySelector('.t');
7316
+ if (time) time.textContent = e.time;
7317
+ let badge = el.querySelector('.log-fold');
7318
+ if (!badge) {
7319
+ badge = document.createElement('span');
7320
+ badge.className = 'log-fold';
7321
+ el.appendChild(badge);
7322
+ }
7323
+ badge.textContent = `×${n}`;
7324
+ el.title = `连续 ${n} 条相同日志 · 首次 ${el.dataset.firstTime ?? e.time} · 最近 ${e.time}`;
7325
+ }
7326
+
7327
+ /** 追加一行;跟上一行是同类折叠日志就只更新计数 */
7328
+ function pushFolded(e) {
7329
+ const key = foldKeyOf(e);
7330
+ const last = logView.lastElementChild;
7331
+ if (key && last?.dataset.foldKey === key) {
7332
+ bumpFold(last, e);
7333
+ return;
7334
+ }
7335
+ logView.appendChild(logLine(e, key));
7336
+ }
7337
+
7338
+ function logLine(e, foldKey = null) {
7046
7339
  const el = document.createElement('div');
7047
7340
  el.className = `log-line ${e.level}`;
7048
7341
  el.dataset.level = e.level;
7342
+ if (foldKey) {
7343
+ el.dataset.foldKey = foldKey;
7344
+ el.dataset.foldCount = '1';
7345
+ el.dataset.firstTime = e.time;
7346
+ }
7049
7347
 
7050
7348
  const lv = `<span class="lv">${LEVEL_LABEL[e.level] ?? e.level}</span>`;
7051
7349
  const tag = e.tag ? `<span class="tag ${tagClass(e.tag)}">${escapeHtml(e.tag)}</span>` : '';
@@ -7109,7 +7407,7 @@ function renderLogs() {
7109
7407
  const atBottom = logView.scrollTop + logView.clientHeight >= logView.scrollHeight - 40;
7110
7408
  logView.innerHTML = '';
7111
7409
  for (const e of logBuf) {
7112
- if (logMatches(e)) logView.appendChild(logLine(e));
7410
+ if (logMatches(e)) pushFolded(e);
7113
7411
  }
7114
7412
  if ($('#autoScroll').checked && atBottom) logView.scrollTop = logView.scrollHeight;
7115
7413
  }
@@ -7122,9 +7420,8 @@ function appendLog(e) {
7122
7420
  if (logView.firstElementChild && logView.children.length > 600) logView.firstElementChild.remove();
7123
7421
  }
7124
7422
  if (!logMatches(e)) return;
7125
- const el = logLine(e);
7126
7423
  const atBottom = logView.scrollTop + logView.clientHeight >= logView.scrollHeight - 40;
7127
- logView.appendChild(el);
7424
+ pushFolded(e);
7128
7425
  if ($('#autoScroll').checked && atBottom) logView.scrollTop = logView.scrollHeight;
7129
7426
  }
7130
7427
 
@@ -7197,6 +7494,9 @@ function connectStream() {
7197
7494
 
7198
7495
  await loadBots(); // 先确定当前机器人,后面的请求都会带上 ?bot=
7199
7496
  await pollStatus();
7497
+ // 首次启动:没有凭证就自动进入引导(扫码 / 手填 + 可选公网),
7498
+ // 用户跳过过则不再自动弹。放在 loadBots 之后才知道有没有 AppID。
7499
+ if (setupNeeded()) showSetup();
7200
7500
  await initLogs();
7201
7501
  connectStream();
7202
7502
  initTheme();
package/web/index.html CHANGED
@@ -896,8 +896,9 @@ curl 'https://bot.q.qq.com/cgi-bin/v2/info/list_bots' \
896
896
  <!--
897
897
  扫码换凭证:AppSecret 会被重置、或者整只机器人换了账号时,
898
898
  与其去 q.qq.com 后台翻两个值再复制,不如扫一下。
899
- 和「新建机器人」用的是同一个官方绑定接口,区别只是扫完**不建新机器人**,
900
- 把 AppID / AppSecret 填进当前这张表单里——仍然要点「保存设置」才生效。
899
+ 和「新建机器人」用的是同一个官方绑定接口,区别只是扫完**不建新机器人**。
900
+ 只有拿到新凭证那一刻旧密钥才失效,所以扫到后会自动保存并尝试上线;
901
+ 二维码还没扫 / 还在等待扫码时,旧凭证依然有效,不会动现有连接。
901
902
  -->
902
903
  <div class="nb-qr" id="cfgQr" hidden>
903
904
  <div class="nb-qr-code" id="cfgQrCode"></div>
@@ -2057,6 +2058,76 @@ curl 'https://bot.q.qq.com/cgi-bin/v2/info/list_bots' \
2057
2058
  </div>
2058
2059
  </div>
2059
2060
 
2061
+ <!-- 首次启动引导:没有 AppID 时自动弹出,扫码或手填凭证即可开始 -->
2062
+ <div class="modal-mask" id="setupMask" hidden>
2063
+ <div class="modal wide" role="dialog" aria-modal="true" aria-labelledby="setupTitle">
2064
+ <h3 class="modal-title" id="setupTitle">欢迎使用栖 · 先配置一只机器人</h3>
2065
+ <p class="setup-lead" id="setupLead">
2066
+ 还没有连接凭证。扫码最省事(手机 QQ 扫一下就有 AppID / AppSecret),也可以手动填。
2067
+ 配置好会自动保存并尝试上线。
2068
+ </p>
2069
+
2070
+ <div class="setup-step">
2071
+ <div class="setup-step-title">1 · 连接凭证</div>
2072
+ <div class="nb-qr-wrap">
2073
+ <button class="btn primary" id="setupQrStart" type="button">扫码获取凭证</button>
2074
+ <i class="nb-qr-hint">推荐:不用去 q.qq.com 手动建机器人</i>
2075
+ </div>
2076
+ <div class="nb-qr" id="setupQr" hidden>
2077
+ <div class="nb-qr-code" id="setupQrCode"></div>
2078
+ <div class="nb-qr-tip" id="setupQrTip"></div>
2079
+ </div>
2080
+ <div class="nb-or">或者手动填(已有机器人、或扫码用不了时)</div>
2081
+ <div class="bot-form">
2082
+ <label>
2083
+ <span>AppID</span>
2084
+ <input id="setupAppId" placeholder="q.qq.com 开发设置里的 AppID" autocomplete="off">
2085
+ </label>
2086
+ <label>
2087
+ <span>AppSecret</span>
2088
+ <input id="setupSecret" type="password" placeholder="AppSecret" autocomplete="off">
2089
+ </label>
2090
+ </div>
2091
+ <button class="btn" id="setupCredSave" type="button" style="margin-top:8px">保存凭证并上线</button>
2092
+ <div class="bot-form-err" id="setupErr" hidden></div>
2093
+ </div>
2094
+
2095
+ <div class="setup-step">
2096
+ <div class="setup-step-title">2 · 面板访问方式(可选)</div>
2097
+ <label class="setup-check">
2098
+ <input type="checkbox" id="setupPublic">
2099
+ <span>允许局域网 / 公网访问面板</span>
2100
+ </label>
2101
+ <div id="setupPublicFields" hidden>
2102
+ <p class="setup-note">
2103
+ 对外服务必须设置访问密钥,否则任何人都能接管面板(含装插件 = 执行任意代码)。
2104
+ 改监听地址和密钥都要<b>重启框架</b>才会生效;重启后用下面的地址加 <code>?key=你的密钥</code> 访问。
2105
+ </p>
2106
+ <div class="bot-form">
2107
+ <label>
2108
+ <span>访问密钥</span>
2109
+ <input id="setupAccessKey" type="password" placeholder="设一个长随机串" autocomplete="new-password">
2110
+ </label>
2111
+ <label>
2112
+ <span>监听地址</span>
2113
+ <input id="setupHost" value="0.0.0.0" autocomplete="off">
2114
+ </label>
2115
+ <label>
2116
+ <span>端口</span>
2117
+ <input id="setupPort" type="number" value="15207">
2118
+ </label>
2119
+ </div>
2120
+ <button class="btn" id="setupNetSave" type="button" style="margin-top:8px">保存访问方式</button>
2121
+ </div>
2122
+ </div>
2123
+
2124
+ <div class="modal-actions">
2125
+ <button class="btn btn-ghost" id="setupSkip">稍后再说</button>
2126
+ <button class="btn primary" id="setupDone">完成,进入面板</button>
2127
+ </div>
2128
+ </div>
2129
+ </div>
2130
+
2060
2131
  <!-- 插件设置:配置 + 玩家数据 -->
2061
2132
  <div class="modal-mask" id="pluginPanelMask" hidden>
2062
2133
  <div class="modal wide" role="dialog" aria-modal="true" aria-labelledby="ppTitle">
package/web/style.css CHANGED
@@ -1045,6 +1045,16 @@ label.switch.small { font-size: 12.5px; color: var(--muted); }
1045
1045
  .log-line .m.msg-err { color: var(--err); font-weight: 500; }
1046
1046
  .log-line .m.msg-cmd { color: var(--c-violet); }
1047
1047
 
1048
+ /* 连续相同日志的折叠计数(只有 [ext-bridge] INFO 会带这个徽标)。
1049
+ 复用既有变量,不新增 CSS 变量:webui-contract 对变量定义做双向比对。 */
1050
+ .log-line .log-fold {
1051
+ flex: none;
1052
+ font-size: 10.5px; font-weight: 600;
1053
+ line-height: 17px; padding: 0 5px; border-radius: 4px;
1054
+ background: var(--panel-3); color: var(--muted);
1055
+ font-variant-numeric: tabular-nums;
1056
+ }
1057
+
1048
1058
  @media (max-width: 860px) {
1049
1059
  .topbar { flex-wrap: wrap; height: auto; padding: 10px 14px; gap: 10px; }
1050
1060
  /**
@@ -3180,3 +3190,28 @@ input.ap-range {
3180
3190
  .media-meta { flex: 1; min-width: 0; }
3181
3191
  .media-name { font-size: 13px; font-weight: 500; margin-bottom: 4px; word-break: break-all; }
3182
3192
  .media-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
3193
+
3194
+ /* 首次启动引导(#setupMask):复用弹层与表单样式,这里只补它独有的几块 */
3195
+ /*
3196
+ * 引导内容(二维码 + 手填 + 面板访问方式)高过一屏时必须让弹层自己滚。
3197
+ * .modal.wide 只设了 max-height 没有 overflow,内容超高会溢出到背景,
3198
+ * 结果是滚轮滚了后面的面板、弹层本身却不动——这里补上滚动容器,
3199
+ * overscroll-behavior 阻止滚到顶/底时把滚动链传给 body。
3200
+ */
3201
+ #setupMask .modal.wide { overflow-y: auto; overscroll-behavior: contain; }
3202
+ /* flex column 默认会压缩子项,二维码被压扁后滚动高度算不准 */
3203
+ #setupMask .modal.wide > * { flex-shrink: 0; }
3204
+ .setup-lead { margin: 0 0 16px; font-size: 13px; line-height: 1.7; color: var(--text-2); }
3205
+ .setup-step {
3206
+ padding: 14px; margin-bottom: 14px;
3207
+ border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel-2);
3208
+ }
3209
+ .setup-step-title { font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 10px; }
3210
+ .setup-check { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13px; color: var(--text); }
3211
+ .setup-check input { width: 16px; height: 16px; accent-color: var(--primary); }
3212
+ .setup-note {
3213
+ margin: 10px 0; padding: 10px 12px; font-size: 12px; line-height: 1.7;
3214
+ color: var(--text-2); background: var(--panel-3); border-radius: var(--radius-sm);
3215
+ }
3216
+ .setup-note code { font-family: var(--font-mono, monospace); color: var(--primary); }
3217
+ .bot-form-err.setup-ok { color: var(--success, #2e7d32); }