cortico-world-fish-sing 0.4.9 → 0.4.10
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/CHANGELOG.md +7 -0
- package/package.json +1 -1
- package/src/config.ts +2 -1
- package/src/deliver.ts +7 -1
- package/src/notify.ts +7 -1
- package/src/world.ts +5 -0
- package/tests/smoke.mjs +59 -52
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
格式参考 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/);版本号遵循语义化。
|
|
4
4
|
|
|
5
|
+
## [0.4.10] - 2026-11-02
|
|
6
|
+
|
|
7
|
+
### 修复
|
|
8
|
+
- **QQ 通知目标只填号码时静默失效**:`qqTarget` 写 `2587509374`(没有 `private:` 前缀)会被 `parseTarget` 判死,然后什么都不发、日志一条没有,看起来像"QQ 渠道坏了"。现在裸数字直接当私聊号处理;格式真的不对时也会 warn 一条「解析不了(要 group:/private:)」。
|
|
9
|
+
- 选模对比没发 QQ 时同样会 warn 说明原因(缺目标 / 缺 OneBot 地址),不再静默。
|
|
10
|
+
- `notify.qqTarget` 改为热更新字段(改完不用重启 Coo)。
|
|
11
|
+
|
|
5
12
|
## [0.4.9] - 2026-11-02
|
|
6
13
|
|
|
7
14
|
### 修复
|
package/package.json
CHANGED
package/src/config.ts
CHANGED
|
@@ -337,7 +337,8 @@ export function fishsingConfigGroups(): ConfigGroup[] {
|
|
|
337
337
|
[at('notify.qqTarget')]: {
|
|
338
338
|
type: 'string',
|
|
339
339
|
title: 'QQ 通知目标',
|
|
340
|
-
description: 'group:<群号> 或 private:<QQ
|
|
340
|
+
description: 'group:<群号> 或 private:<QQ号>(只填号码也行);留空 = 只用桌宠。',
|
|
341
|
+
'x-hot': true,
|
|
341
342
|
},
|
|
342
343
|
},
|
|
343
344
|
},
|
package/src/deliver.ts
CHANGED
|
@@ -87,9 +87,15 @@ export interface OneBotTarget {
|
|
|
87
87
|
label: string;
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
-
/** `group:123` / `private:456`;也接受 `群:123` / `私聊:456`(她有时候会这么写)。
|
|
90
|
+
/** `group:123` / `private:456`;也接受 `群:123` / `私聊:456`(她有时候会这么写)。
|
|
91
|
+
* 裸数字当成私聊 QQ 号——用户第一反应就是直接填号码,不能因为少个前缀就静默不发。 */
|
|
91
92
|
export function parseTarget(to: string): OneBotTarget | null {
|
|
92
93
|
const text = String(to || '').trim();
|
|
94
|
+
const bare = /^(\d{5,12})$/.exec(text);
|
|
95
|
+
if (bare) {
|
|
96
|
+
const id = Number(bare[1]);
|
|
97
|
+
return { action: 'send_private_msg', params: { user_id: id }, label: `私聊 ${id}` };
|
|
98
|
+
}
|
|
93
99
|
const m = /^(group|群|private|私聊)\s*[::]\s*(\d+)$/.exec(text);
|
|
94
100
|
if (!m) return null;
|
|
95
101
|
const isGroup = m[1] === 'group' || m[1] === '群';
|
package/src/notify.ts
CHANGED
|
@@ -36,7 +36,13 @@ export async function notify(deps: NotifyDeps, title: string, body = ''): Promis
|
|
|
36
36
|
const text = body ? `${title}\n${body}` : title;
|
|
37
37
|
|
|
38
38
|
const channel = deps.cfg.channel ?? 'auto';
|
|
39
|
-
const
|
|
39
|
+
const rawTarget = String(deps.cfg.qqTarget ?? '').trim();
|
|
40
|
+
const target = parseTarget(rawTarget);
|
|
41
|
+
if (channel === 'auto' && rawTarget && !target) {
|
|
42
|
+
// 这里以前是完全静默的:qqTarget 写了但格式不对 → 直接走桌宠,日志一条没有,
|
|
43
|
+
// 用户以为"QQ 渠道坏了"(0.4.9 的真实事故:填了裸号码没写 private:)。
|
|
44
|
+
deps.log.warn(`QQ 通知目标「${rawTarget}」解析不了(要 group:<群号> 或 private:<QQ号>),走桌宠`);
|
|
45
|
+
}
|
|
40
46
|
const wantQQ = channel === 'qq' || (channel === 'auto' && Boolean(target) && Boolean(deps.onebot.httpUrl));
|
|
41
47
|
if (wantQQ) {
|
|
42
48
|
if (target && deps.onebot.httpUrl) {
|
package/src/world.ts
CHANGED
|
@@ -417,6 +417,11 @@ export class FishSingWorld implements World {
|
|
|
417
417
|
} catch (e) {
|
|
418
418
|
this.host?.log.warn(`[fish-sing] 选模片段发 QQ 失败:${e instanceof Error ? e.message : String(e)}`);
|
|
419
419
|
}
|
|
420
|
+
} else {
|
|
421
|
+
// 别静默:用户会以为"QQ 渠道坏了",实际是配置缺一半
|
|
422
|
+
this.host?.log.warn(
|
|
423
|
+
`[fish-sing] 选模片段没发 QQ:${!obTarget ? 'qqTarget 没配或格式不对(要 group:/private: 前缀)' : 'OneBot HTTP 地址没配'}`,
|
|
424
|
+
);
|
|
420
425
|
}
|
|
421
426
|
}
|
|
422
427
|
this.host?.log.info(`[fish-sing] 选模对比已生成:${labels.join(' / ')}(${outDir})`);
|
package/tests/smoke.mjs
CHANGED
|
@@ -1,52 +1,59 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Node 侧冒烟测试:入口能加载、通知渠道兜底逻辑正确。
|
|
3
|
-
* 跑法:node --experimental-strip-types tests/smoke.mjs
|
|
4
|
-
*/
|
|
5
|
-
import { notify } from '../src/notify.ts';
|
|
6
|
-
|
|
7
|
-
let failed = 0;
|
|
8
|
-
function check(name, ok, detail = '') {
|
|
9
|
-
console.log(`${ok ? '✓' : '✗'} ${name}${detail ? `(${detail})` : ''}`);
|
|
10
|
-
if (!ok) failed += 1;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const log = { info: () => {}, warn: () => {}, error: () => {} };
|
|
14
|
-
|
|
15
|
-
// ---- 1. 桌宠渠道:pushEvent 被调用 ----
|
|
16
|
-
let pushed = [];
|
|
17
|
-
const r1 = await notify(
|
|
18
|
-
{ cfg: { enabled: true, channel: 'pet' }, pushEvent: (e) => pushed.push(e), onebot: { httpUrl: '' }, log },
|
|
19
|
-
'训练完成:dfy3', '200 轮全部完成。',
|
|
20
|
-
);
|
|
21
|
-
check('桌宠渠道走 pushEvent', r1.via === 'pet' && pushed.length === 1 && pushed[0].type === 'fishsing.notify');
|
|
22
|
-
check('事件带正文', typeof pushed[0]?.text === 'string' && pushed[0].text.includes('dfy3'));
|
|
23
|
-
|
|
24
|
-
// ---- 2. auto + 没配 QQ 目标 → 退桌宠 ----
|
|
25
|
-
pushed = [];
|
|
26
|
-
const r2 = await notify(
|
|
27
|
-
{ cfg: { enabled: true, channel: 'auto' }, pushEvent: (e) => pushed.push(e), onebot: { httpUrl: '' }, log },
|
|
28
|
-
'测试2',
|
|
29
|
-
);
|
|
30
|
-
check('auto 无 QQ 目标 → 桌宠', r2.via === 'pet' && pushed.length === 1);
|
|
31
|
-
|
|
32
|
-
// ---- 3. QQ 不通 → 退桌宠(用户定的兜底规则) ----
|
|
33
|
-
pushed = [];
|
|
34
|
-
const r3 = await notify(
|
|
35
|
-
{ cfg: { enabled: true, channel: 'auto', qqTarget: 'group:123' }, pushEvent: (e) => pushed.push(e), onebot: { httpUrl: 'http://127.0.0.1:59999' }, log },
|
|
36
|
-
'测试3',
|
|
37
|
-
);
|
|
38
|
-
check('QQ 不通退桌宠', r3.via === 'pet' && pushed.length === 1);
|
|
39
|
-
|
|
40
|
-
// ---- 4. 关闭 → 不发 ----
|
|
41
|
-
pushed = [];
|
|
42
|
-
const r4 = await notify(
|
|
43
|
-
{ cfg: { enabled: false, channel: 'pet' }, pushEvent: (e) => pushed.push(e), onebot: { httpUrl: '' }, log },
|
|
44
|
-
'测试4',
|
|
45
|
-
);
|
|
46
|
-
check('enabled=false 不发', r4.via === 'off' && pushed.length === 0);
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Node 侧冒烟测试:入口能加载、通知渠道兜底逻辑正确。
|
|
3
|
+
* 跑法:node --experimental-strip-types tests/smoke.mjs
|
|
4
|
+
*/
|
|
5
|
+
import { notify } from '../src/notify.ts';
|
|
6
|
+
|
|
7
|
+
let failed = 0;
|
|
8
|
+
function check(name, ok, detail = '') {
|
|
9
|
+
console.log(`${ok ? '✓' : '✗'} ${name}${detail ? `(${detail})` : ''}`);
|
|
10
|
+
if (!ok) failed += 1;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const log = { info: () => {}, warn: () => {}, error: () => {} };
|
|
14
|
+
|
|
15
|
+
// ---- 1. 桌宠渠道:pushEvent 被调用 ----
|
|
16
|
+
let pushed = [];
|
|
17
|
+
const r1 = await notify(
|
|
18
|
+
{ cfg: { enabled: true, channel: 'pet' }, pushEvent: (e) => pushed.push(e), onebot: { httpUrl: '' }, log },
|
|
19
|
+
'训练完成:dfy3', '200 轮全部完成。',
|
|
20
|
+
);
|
|
21
|
+
check('桌宠渠道走 pushEvent', r1.via === 'pet' && pushed.length === 1 && pushed[0].type === 'fishsing.notify');
|
|
22
|
+
check('事件带正文', typeof pushed[0]?.text === 'string' && pushed[0].text.includes('dfy3'));
|
|
23
|
+
|
|
24
|
+
// ---- 2. auto + 没配 QQ 目标 → 退桌宠 ----
|
|
25
|
+
pushed = [];
|
|
26
|
+
const r2 = await notify(
|
|
27
|
+
{ cfg: { enabled: true, channel: 'auto' }, pushEvent: (e) => pushed.push(e), onebot: { httpUrl: '' }, log },
|
|
28
|
+
'测试2',
|
|
29
|
+
);
|
|
30
|
+
check('auto 无 QQ 目标 → 桌宠', r2.via === 'pet' && pushed.length === 1);
|
|
31
|
+
|
|
32
|
+
// ---- 3. QQ 不通 → 退桌宠(用户定的兜底规则) ----
|
|
33
|
+
pushed = [];
|
|
34
|
+
const r3 = await notify(
|
|
35
|
+
{ cfg: { enabled: true, channel: 'auto', qqTarget: 'group:123' }, pushEvent: (e) => pushed.push(e), onebot: { httpUrl: 'http://127.0.0.1:59999' }, log },
|
|
36
|
+
'测试3',
|
|
37
|
+
);
|
|
38
|
+
check('QQ 不通退桌宠', r3.via === 'pet' && pushed.length === 1);
|
|
39
|
+
|
|
40
|
+
// ---- 4. 关闭 → 不发 ----
|
|
41
|
+
pushed = [];
|
|
42
|
+
const r4 = await notify(
|
|
43
|
+
{ cfg: { enabled: false, channel: 'pet' }, pushEvent: (e) => pushed.push(e), onebot: { httpUrl: '' }, log },
|
|
44
|
+
'测试4',
|
|
45
|
+
);
|
|
46
|
+
check('enabled=false 不发', r4.via === 'off' && pushed.length === 0);
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
// ---- 5. 裸号码当私聊(0.4.10 的坑:填了号码没前缀就静默不发) ----
|
|
50
|
+
const { parseTarget } = await import('../src/deliver.ts');
|
|
51
|
+
const t1 = parseTarget('2587509374');
|
|
52
|
+
check('裸号码 → 私聊', Boolean(t1) && t1.action === 'send_private_msg' && t1.params.user_id === 2587509374);
|
|
53
|
+
check('乱码 → null', parseTarget('2587509374abc') === null);
|
|
54
|
+
|
|
55
|
+
if (failed) {
|
|
56
|
+
console.error(`\n${failed} 项失败`);
|
|
57
|
+
process.exit(1);
|
|
58
|
+
}
|
|
59
|
+
console.log('\n冒烟测试全部通过');
|