koishi-plugin-kkk 3.3.0-beta.2 → 3.3.0-beta.3
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 +6 -0
- package/lib/index.js +21 -1
- package/lib/karin/module/utils/ParseForward.js +30 -3
- package/package.json +1 -1
- package/src/index.ts +21 -1
- package/src/karin/module/utils/ParseForward.ts +29 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# 更新日志
|
|
2
2
|
|
|
3
|
+
## 3.3.0-beta.3
|
|
4
|
+
|
|
5
|
+
### 修了两个「设置根本没生效」的问题
|
|
6
|
+
|
|
7
|
+
- **「强制在线播放的适配器」这类设置以前是静默失效的**:运行时配置是一份**手写白名单**,新加的开关(强制在线播放的适配器、面板「在线看」列、按需切片、解析去重…)忘了往里补一行,运行时读到的就是 undefined —— 表现就是 B站私聊明明配了强制在线播放,**还是去下载并发视频文件**。现在改成「字段表里的默认值打底 + 归一化覆盖」,以后再加开关不会漏。
|
|
8
|
+
- **不支持的适配器不再尝试合并转发**:判断「这个适配器支不支持聊天记录」用的是**黑名单**(只排除 QQ 官方),于是任何自定义适配器都被当成支持 —— B站私聊适配器(platform 就是 bilibili)也被算进去了,整条转发发出去「没有拿到消息 ID」,连退回来的逐条发送也失败,用户什么都没收到。现在改成**白名单**(OneBot 系平台名,或适配器自带 sendGroupForwardMsg/sendPrivateForwardMsg),并会在日志里写明「适配器 xxx 不支持合并转发,本次逐条发送」。
|
|
3
9
|
## 3.3.0-beta.2
|
|
4
10
|
|
|
5
11
|
> **预览版**:给愿意先试的人用。npm 上默认安装的(latest)还是 3.2.2,想装这个用 npm i koishi-plugin-kkk@beta(或者面板里的「检查更新」换成 beta 通道)。
|
package/lib/index.js
CHANGED
|
@@ -892,7 +892,16 @@ async function apply(ctx, rawConfig) {
|
|
|
892
892
|
if (raw[key] !== undefined)
|
|
893
893
|
legacy[key] = raw[key];
|
|
894
894
|
}
|
|
895
|
-
|
|
895
|
+
/**
|
|
896
|
+
* **每个 qq 字段都要有值**:不能指望 Koishi 的 schema 默认值一定被填上 ——
|
|
897
|
+
* 线上实测踩过(用户报「B站私聊还是发视频、没给在线播放链接」):
|
|
898
|
+
* 配置里没写过的字段,运行时读到的是 `undefined`,
|
|
899
|
+
* 于是「强制在线播放的适配器」(默认 bilibili)整个失效、面板列按钮的开关也失效。
|
|
900
|
+
*
|
|
901
|
+
* 所以这里用 `readQqOptions` 先铺一层**字段表里的默认值**(qqFields.json 是唯一出处),
|
|
902
|
+
* 再用用户显式配的值覆盖 —— 显式配置永远优先,缺的字段一律有默认。
|
|
903
|
+
*/
|
|
904
|
+
const groupQq = { ...(0, qqOptions_1.readQqOptions)(raw), ...(qq ?? {}) };
|
|
896
905
|
const groupNative = { ...(advanced ?? {}) };
|
|
897
906
|
for (const key of qqOptions_1.QQ_KEYS)
|
|
898
907
|
if (legacy[key] !== undefined)
|
|
@@ -952,7 +961,18 @@ async function apply(ctx, rawConfig) {
|
|
|
952
961
|
const dataRoot = node_path_1.default.isAbsolute(config.dataPath) ? config.dataPath : node_path_1.default.resolve(ctx.baseDir ?? process.cwd(), config.dataPath);
|
|
953
962
|
(0, runtime_1.bindRuntime)({
|
|
954
963
|
ctx,
|
|
964
|
+
/**
|
|
965
|
+
* ⚠️ 这份 config **不是**原封不动转发,而是运行时真正读的那一份(`tryGetRuntime().config`)。
|
|
966
|
+
*
|
|
967
|
+
* 以前它是一个**手写白名单** —— 于是每加一个新开关(例如「强制在线播放的适配器」
|
|
968
|
+
* `forceOnlinePlayer`),忘了往这里补一行,运行时就读到 undefined,功能整个静默失效:
|
|
969
|
+
* 线上真实故障就是「B站私聊该给在线播放链接,结果还是去发视频文件」。
|
|
970
|
+
*
|
|
971
|
+
* 现在改成 `...readQqOptions(config)` 打底(qqFields.json 里的字段一个不落,缺的用默认值),
|
|
972
|
+
* 下面那些需要**归一化**的字段(端口取整数、分钟数夹范围、布尔用 !== false 这种)再覆盖上去。
|
|
973
|
+
*/
|
|
955
974
|
config: {
|
|
975
|
+
...(0, qqOptions_1.readQqOptions)(config),
|
|
956
976
|
masters: config.masters ?? [],
|
|
957
977
|
debug: config.debug,
|
|
958
978
|
dataPath: config.dataPath,
|
|
@@ -41,9 +41,31 @@ function parseForwardPeer(e) {
|
|
|
41
41
|
function platformOf(e) {
|
|
42
42
|
return String(e?.bot?.bot?.platform ?? e?.bot?.platform ?? '');
|
|
43
43
|
}
|
|
44
|
-
/**
|
|
44
|
+
/**
|
|
45
|
+
* OneBot 系适配器(NapCat / Lagrange / go-cqhttp / Chronocat…):它们真的有「聊天记录」这个概念。
|
|
46
|
+
*
|
|
47
|
+
* 注意这份名单是**白名单**:compat 那边的 isForwardSupported 是黑名单(只排除 QQ 官方),
|
|
48
|
+
* 于是**任何自定义适配器都会被当成支持** —— 线上真实故障就是这样:
|
|
49
|
+
* B站私聊适配器(koishi-plugin-adapter-bilibili-dm,platform 就是 bilibili)被认成支持合并转发,
|
|
50
|
+
* 结果整条转发发出去「没有拿到消息 ID」(适配器根本没有聊天记录这种东西),
|
|
51
|
+
* 连退回来的逐条发送也失败了 —— 用户什么都没收到。
|
|
52
|
+
*/
|
|
53
|
+
const ONEBOT_LIKE = /onebot|napcat|lagrange|go-?cqhttp|chronocat|mirai/i;
|
|
54
|
+
/** 这台部署的适配器支不支持合并转发(**只有明确支持才算支持**) */
|
|
45
55
|
function canForwardParseResult(e) {
|
|
46
|
-
|
|
56
|
+
const raw = e?.bot?.bot ?? e?.bot;
|
|
57
|
+
/**
|
|
58
|
+
* ① 适配器自己带合并转发 API(OneBot 系的 sendGroupForwardMsg / sendPrivateForwardMsg)
|
|
59
|
+
* —— 这条最可靠,不依赖平台名怎么写。
|
|
60
|
+
*/
|
|
61
|
+
const internal = raw?.internal ?? e?.bot?.internal;
|
|
62
|
+
if (internal && (typeof internal.sendGroupForwardMsg === 'function' || typeof internal.sendPrivateForwardMsg === 'function'))
|
|
63
|
+
return true;
|
|
64
|
+
/** ② 其余只认 OneBot 系的平台名 */
|
|
65
|
+
const platform = platformOf(e);
|
|
66
|
+
if (!platform)
|
|
67
|
+
return false;
|
|
68
|
+
return ONEBOT_LIKE.test(platform);
|
|
47
69
|
}
|
|
48
70
|
/** 平台名 → 配置段名(合并转发的平台开关就写在各自的平台段里) */
|
|
49
71
|
const PLATFORM_SECTIONS = {
|
|
@@ -311,8 +333,13 @@ function withParseForward(handler, platform) {
|
|
|
311
333
|
+ '.forward 都没打开),按逐条发送处理');
|
|
312
334
|
return await handler(e, next);
|
|
313
335
|
}
|
|
314
|
-
if (!parseForwardPeer(e)
|
|
336
|
+
if (!parseForwardPeer(e))
|
|
315
337
|
return await handler(e, next);
|
|
338
|
+
if (!canForwardParseResult(e)) {
|
|
339
|
+
// 说明白为什么没合并:以前这里静默退化,用户只看到「转发了但没收到」
|
|
340
|
+
node_karin_1.logger.mark('[合并转发] 适配器 ' + (platformOf(e) || '未知') + ' 不支持合并转发(不是 OneBot 系、也没有 forward API),本次逐条发送');
|
|
341
|
+
return await handler(e, next);
|
|
342
|
+
}
|
|
316
343
|
return await (0, node_karin_1.runWithForwardBag)(parseForwardPeer(e), async () => {
|
|
317
344
|
try {
|
|
318
345
|
return await handler(e, next);
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -885,7 +885,16 @@ export async function apply (ctx: Context, rawConfig: Config) {
|
|
|
885
885
|
for (const key of [...NATIVE_KEYS, ...QQ_KEYS]) {
|
|
886
886
|
if (raw[key] !== undefined) legacy[key] = raw[key]
|
|
887
887
|
}
|
|
888
|
-
|
|
888
|
+
/**
|
|
889
|
+
* **每个 qq 字段都要有值**:不能指望 Koishi 的 schema 默认值一定被填上 ——
|
|
890
|
+
* 线上实测踩过(用户报「B站私聊还是发视频、没给在线播放链接」):
|
|
891
|
+
* 配置里没写过的字段,运行时读到的是 `undefined`,
|
|
892
|
+
* 于是「强制在线播放的适配器」(默认 bilibili)整个失效、面板列按钮的开关也失效。
|
|
893
|
+
*
|
|
894
|
+
* 所以这里用 `readQqOptions` 先铺一层**字段表里的默认值**(qqFields.json 是唯一出处),
|
|
895
|
+
* 再用用户显式配的值覆盖 —— 显式配置永远优先,缺的字段一律有默认。
|
|
896
|
+
*/
|
|
897
|
+
const groupQq: any = { ...readQqOptions(raw as any), ...(qq ?? {}) }
|
|
889
898
|
const groupNative: any = { ...(advanced ?? {}) }
|
|
890
899
|
for (const key of QQ_KEYS) if (legacy[key] !== undefined) groupQq[key] = legacy[key]
|
|
891
900
|
for (const key of NATIVE_KEYS) if (legacy[key] !== undefined) groupNative[key] = legacy[key]
|
|
@@ -940,7 +949,18 @@ export async function apply (ctx: Context, rawConfig: Config) {
|
|
|
940
949
|
|
|
941
950
|
bindRuntime({
|
|
942
951
|
ctx,
|
|
952
|
+
/**
|
|
953
|
+
* ⚠️ 这份 config **不是**原封不动转发,而是运行时真正读的那一份(`tryGetRuntime().config`)。
|
|
954
|
+
*
|
|
955
|
+
* 以前它是一个**手写白名单** —— 于是每加一个新开关(例如「强制在线播放的适配器」
|
|
956
|
+
* `forceOnlinePlayer`),忘了往这里补一行,运行时就读到 undefined,功能整个静默失效:
|
|
957
|
+
* 线上真实故障就是「B站私聊该给在线播放链接,结果还是去发视频文件」。
|
|
958
|
+
*
|
|
959
|
+
* 现在改成 `...readQqOptions(config)` 打底(qqFields.json 里的字段一个不落,缺的用默认值),
|
|
960
|
+
* 下面那些需要**归一化**的字段(端口取整数、分钟数夹范围、布尔用 !== false 这种)再覆盖上去。
|
|
961
|
+
*/
|
|
943
962
|
config: {
|
|
963
|
+
...readQqOptions(config),
|
|
944
964
|
masters: config.masters ?? [],
|
|
945
965
|
debug: config.debug,
|
|
946
966
|
dataPath: config.dataPath,
|
|
@@ -35,9 +35,30 @@ function platformOf (e: any): string {
|
|
|
35
35
|
return String(e?.bot?.bot?.platform ?? e?.bot?.platform ?? '')
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
/**
|
|
38
|
+
/**
|
|
39
|
+
* OneBot 系适配器(NapCat / Lagrange / go-cqhttp / Chronocat…):它们真的有「聊天记录」这个概念。
|
|
40
|
+
*
|
|
41
|
+
* 注意这份名单是**白名单**:compat 那边的 isForwardSupported 是黑名单(只排除 QQ 官方),
|
|
42
|
+
* 于是**任何自定义适配器都会被当成支持** —— 线上真实故障就是这样:
|
|
43
|
+
* B站私聊适配器(koishi-plugin-adapter-bilibili-dm,platform 就是 bilibili)被认成支持合并转发,
|
|
44
|
+
* 结果整条转发发出去「没有拿到消息 ID」(适配器根本没有聊天记录这种东西),
|
|
45
|
+
* 连退回来的逐条发送也失败了 —— 用户什么都没收到。
|
|
46
|
+
*/
|
|
47
|
+
const ONEBOT_LIKE = /onebot|napcat|lagrange|go-?cqhttp|chronocat|mirai/i
|
|
48
|
+
|
|
49
|
+
/** 这台部署的适配器支不支持合并转发(**只有明确支持才算支持**) */
|
|
39
50
|
export function canForwardParseResult (e: any): boolean {
|
|
40
|
-
|
|
51
|
+
const raw: any = e?.bot?.bot ?? e?.bot
|
|
52
|
+
/**
|
|
53
|
+
* ① 适配器自己带合并转发 API(OneBot 系的 sendGroupForwardMsg / sendPrivateForwardMsg)
|
|
54
|
+
* —— 这条最可靠,不依赖平台名怎么写。
|
|
55
|
+
*/
|
|
56
|
+
const internal: any = raw?.internal ?? e?.bot?.internal
|
|
57
|
+
if (internal && (typeof internal.sendGroupForwardMsg === 'function' || typeof internal.sendPrivateForwardMsg === 'function')) return true
|
|
58
|
+
/** ② 其余只认 OneBot 系的平台名 */
|
|
59
|
+
const platform = platformOf(e)
|
|
60
|
+
if (!platform) return false
|
|
61
|
+
return ONEBOT_LIKE.test(platform)
|
|
41
62
|
}
|
|
42
63
|
|
|
43
64
|
/** 平台名 → 配置段名(合并转发的平台开关就写在各自的平台段里) */
|
|
@@ -302,7 +323,12 @@ export function withParseForward<F extends (e: any, next?: any) => any> (handler
|
|
|
302
323
|
+ '.forward 都没打开),按逐条发送处理')
|
|
303
324
|
return await handler(e, next)
|
|
304
325
|
}
|
|
305
|
-
if (!parseForwardPeer(e)
|
|
326
|
+
if (!parseForwardPeer(e)) return await handler(e, next)
|
|
327
|
+
if (!canForwardParseResult(e)) {
|
|
328
|
+
// 说明白为什么没合并:以前这里静默退化,用户只看到「转发了但没收到」
|
|
329
|
+
logger.mark('[合并转发] 适配器 ' + (platformOf(e) || '未知') + ' 不支持合并转发(不是 OneBot 系、也没有 forward API),本次逐条发送')
|
|
330
|
+
return await handler(e, next)
|
|
331
|
+
}
|
|
306
332
|
return await runWithForwardBag(parseForwardPeer(e), async () => {
|
|
307
333
|
try {
|
|
308
334
|
return await handler(e, next)
|