// 矩阵跑完后的定向补测,只针对三个悬而未决的点: // 1) 服务端合并转发的 node.content 形态(段数组 vs JSON 字符串)——上一轮传字符串被当字面文本渲染 // 2) get_forward_msg 的正确参数名(穷举常见命名,拿到成功结构或全部失败证据) // 3) 语音能力旁证:send_group_ai_record(NapCat 官方 TTS)能否成功,用于区分 // 「record 段不可用」与「NapCat 运行环境缺解码器」 // 默认 dry-run,--yes 才真实发送。凭据只从环境变量读取。 import fs from 'node:fs'; import path from 'node:path'; const WS_URL = process.env.NAPCAT_WS_URL || 'ws://192.168.5.32:16099'; const TOKEN = process.env.NAPCAT_WS_TOKEN; const GROUP = Number(process.env.PROBE_GROUP || 933280401); const FRIEND = Number(process.env.PROBE_FRIEND || 2161656029); const SELF = Number(process.env.PROBE_SELF || 3575608514); const DO_WRITE = process.argv.includes('--yes'); const OUT_DIR = process.env.PROBE_OUT || 'local'; if (!TOKEN) { console.error('缺少环境变量 NAPCAT_WS_TOKEN。凭据不得硬编码。'); process.exit(1); } const stamp = new Date().toISOString().replace(/[:.]/g, '-'); fs.mkdirSync(OUT_DIR, { recursive: true }); const OUT = path.join(OUT_DIR, `followup-${stamp}.jsonl`); const say = (...a) => console.log(...a); const pending = new Map(); let opened = false; let authed = false; const events = []; const ws = new WebSocket(`${WS_URL.replace(/\/$/, '')}/?access_token=${encodeURIComponent(TOKEN)}`); ws.onopen = () => { opened = true; }; ws.onmessage = (ev) => { let o; try { o = JSON.parse(String(ev.data)); } catch { return; } if (o.echo && pending.has(o.echo)) { pending.get(o.echo).resolve(o); pending.delete(o.echo); return; } if (o.post_type === 'meta_event' && o.meta_event_type === 'lifecycle') { authed = true; return; } if (o.post_type === 'meta_event') return; events.push({ el: Date.now(), data: o }); fs.appendFileSync(OUT, JSON.stringify({ kind: 'event', t: new Date().toISOString(), data: o }) + '\n'); }; for (let i = 0; i < 100 && !opened; i++) await new Promise((r) => setTimeout(r, 100)); if (!opened) { console.error('连接超时'); process.exit(1); } for (let i = 0; i < 100 && !authed; i++) await new Promise((r) => setTimeout(r, 100)); say('认证=' + authed); if (!authed && DO_WRITE) { console.error('未确认认证,中止。'); process.exit(2); } const api = (action, params, ms = 30000) => new Promise((resolve) => { const echo = `fu-${action}-${Date.now()}-${Math.random().toString(36).slice(2, 6)}`; const to = setTimeout(() => { pending.delete(echo); resolve({ __timeout: true }); }, ms); pending.set(echo, { resolve: (o) => { clearTimeout(to); resolve(o); }, to }); ws.send(JSON.stringify({ action, params, echo })); }); const nodeArr = (label) => [ { type: 'node', data: { type: 'node', user_id: String(SELF), nickname: '雪珂', content: [{ type: 'text', data: { text: `${label}-A` } }] } }, { type: 'node', data: { type: 'node', user_id: String(FRIEND), nickname: '小王', content: [{ type: 'text', data: { text: `${label}-B` } }] } }, ]; const JOBS = [ { id: 'fwd_group_content_arr', desc: 'send_group_forward_msg + node.content 为段数组', action: 'send_group_forward_msg', params: () => ({ group_id: GROUP, messages: nodeArr('数组形') }) }, { id: 'fwd_seg_parallel', desc: '并列 node 段(第19章已证明生效,作为对照基准)', action: 'send_group_msg', params: () => ({ group_id: GROUP, message: [ ...nodeArr('并列段'), { type: 'text', data: { text: '[QLf:fwd_seg_parallel]' } }] }) }, { id: 'ai_record_group', desc: 'send_group_ai_record(官方 TTS 语音,群)', action: 'send_group_ai_record', params: () => ({ group_id: GROUP, character: 'lucy-voice-houge', text: 'QLinker 语音能力旁证' }) }, ]; say(`\n模式=${DO_WRITE ? '真实发送' : 'DRY-RUN'}\n`); const sent = {}; for (const j of JOBS) { if (!DO_WRITE) { say(`${j.id.padEnd(22)} [计划] ${j.desc}`); continue; } const t0 = Date.now(); const r = await api(j.action, j.params()); if (j.action.includes('ai_record')) { const rec = { id: j.id, desc: j.desc, retcode: r.__timeout ? 'TIMEOUT' : r.retcode, message: r.message ?? r.wording ?? '', data_preview: typeof r.data === 'string' ? r.data.slice(0, 90) : JSON.stringify(r.data)?.slice(0, 120) }; fs.appendFileSync(OUT, JSON.stringify({ kind: 'result', ...rec }) + '\n'); say(`${j.id.padEnd(22)} retcode=${String(rec.retcode).padEnd(7)} ${String(rec.message).slice(0, 50)} data=${String(rec.data_preview).slice(0, 70)}`); continue; } const mid = r?.data?.message_id; sent[j.id] = mid; await new Promise((r2) => setTimeout(r2, 5000)); const hasArrLabel = (e) => (Array.isArray(e.data.message) ? e.data.message : []) .some((s) => s.type === 'json' && String(s.data?.data || '').includes('数组形')); const hasMark = (e) => String(e.data.raw_message || '').includes('[QLf:' + j.id + ']'); const ev = events.find((e) => e.el >= t0 && (hasArrLabel(e) || hasMark(e))); const jsonSeg = (Array.isArray(ev?.data?.message) ? ev.data.message : []).find((s) => s.type === 'json'); let detail = {}; try { detail = JSON.parse(jsonSeg.data.data)?.meta?.detail || {}; } catch {} const rec = { id: j.id, desc: j.desc, retcode: r.__timeout ? 'TIMEOUT' : r.retcode, message: r.message ?? r.wording ?? '', message_id: mid ?? null, real_seq: ev?.data?.real_seq ?? null, tsum: detail.tsum ?? null, news: JSON.stringify(detail.news ?? '').slice(0, 300), resid: detail.resid ?? null, uniseq: detail.uniseq ?? null }; fs.appendFileSync(OUT, JSON.stringify({ kind: 'result', ...rec }) + '\n'); say(`${j.id.padEnd(22)} retcode=${String(rec.retcode).padEnd(6)} seq=${String(rec.real_seq ?? '-').padEnd(6)} tsum=${rec.tsum ?? '-'} news=${rec.news.slice(0, 110)}`); } // get_forward_msg 参数名穷举(只读) say('\n--- get_forward_msg 参数穷举 ---'); const MID = sent.fwd_seg_parallel || 497853103; const PARAM_SETS = [ { message_id: MID }, { message_id: String(MID) }, { message_id: MID, group_id: GROUP }, { id: String(MID) }, ]; for (const p of PARAM_SETS) { const r = await api('get_forward_msg', p); const okFlag = r.retcode === 0; say(`${JSON.stringify(p).slice(0, 60).padEnd(62)} retcode=${String(r.retcode).padEnd(6)} ${okFlag ? 'OK ' + JSON.stringify(r.data).slice(0, 120) : String(r.message).slice(0, 60)}`); fs.appendFileSync(OUT, JSON.stringify({ kind: 'get_forward_msg', id: 'get_forward_msg', retcode: r.retcode, message: r.message ?? '', params: p, resp: r }) + '\n'); } // resid/uniseq 形式:从刚采到的事件里取 let resid = null, uniseq = null; for (const e of events) { const j = (e.data.message || []).find?.((s) => s.type === 'json'); if (!j) continue; try { const d = JSON.parse(j.data.data)?.meta?.detail || {}; if (d.resid) { resid = d.resid; uniseq = d.uniseq; break; } } catch {} } if (resid) { for (const p of [ { resid, uniseq }, { id: uniseq, resid }, { message_id: MID, resid, uniseq, group_id: GROUP }, ]) { const r = await api('get_forward_msg', p); say(`${'resid/uniseq:' + JSON.stringify(p).slice(0, 45).padEnd(50)} retcode=${String(r.retcode).padEnd(6)} ${r.retcode === 0 ? 'OK ' + JSON.stringify(r.data).slice(0, 120) : String(r.message).slice(0, 55)}`); fs.appendFileSync(OUT, JSON.stringify({ kind: 'get_forward_msg', id: 'get_forward_msg', retcode: r.retcode, message: r.message ?? '', params: p, resp: r }) + '\n'); } } else say('未从事件里取到 resid,跳过 resid/uniseq 组合'); // 文件上传通知:延长等待,确认是否真的完全无通知事件 say('\n--- 群文件上传后的通知观测(等待 20s)---'); if (DO_WRITE) { const t0 = Date.now(); const up = await api('upload_group_file', { group_id: GROUP, file: 'base64://' + Buffer.from('QLinker 通知观测文件\n', 'utf8').toString('base64'), name: `qlinker-notify-${stamp}.txt` }); say(`upload_group_file retcode=${up.retcode} ${String(up.message).slice(0, 60)}`); fs.appendFileSync(OUT, JSON.stringify({ kind: 'upload', resp: up }) + '\n'); await new Promise((r) => setTimeout(r, 20000)); const during = events.filter((e) => e.el >= t0); say(`20s 内收到事件 ${during.length} 条:` + (during.map((e) => e.data.notice_type || e.data.request_type || e.data.post_type).join(',') || '(无)')); } say('\n结果 -> ' + OUT); try { ws.close(); } catch {} process.exit(0);