@alemonjs/qq-bot 2.1.2 → 2.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.
- package/README.md +5 -3
- package/lib/config.d.ts +1 -1
- package/lib/format.d.ts +3 -3
- package/lib/format.js +16 -3
- package/lib/sends.js +3 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -47,8 +47,10 @@ qq-bot:
|
|
|
47
47
|
# 启动md强制转换为text,特别是当没有md权限,但使用了md数据格式时
|
|
48
48
|
markdownToText: true
|
|
49
49
|
# 隐藏不支持的消息类型(可选,默认: false)
|
|
50
|
-
#
|
|
51
|
-
#
|
|
50
|
+
# 1:一级隐藏,不可读占位符([视频]、[音频]、[图片]、[附件]等)被置空,可读内容保留
|
|
51
|
+
# 2:二级隐藏,按钮仅显示指令数据(如 /挑战),链接仅显示 URL
|
|
52
|
+
# 3:三级隐藏,按钮和链接的 data 也不保留,完全隐藏
|
|
53
|
+
# 4:四级隐藏,不进行任何转换,降级数据直接丢弃
|
|
52
54
|
# 转换后内容为空时,将跳过发送并输出 info 日志
|
|
53
|
-
hideUnsupported:
|
|
55
|
+
hideUnsupported: 1
|
|
54
56
|
```
|
package/lib/config.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export type Options = {
|
|
|
4
4
|
master_key?: string[];
|
|
5
5
|
master_id?: string[];
|
|
6
6
|
markdownToText?: boolean;
|
|
7
|
-
hideUnsupported?: boolean;
|
|
7
|
+
hideUnsupported?: boolean | number;
|
|
8
8
|
} & sdkOptions;
|
|
9
9
|
export declare const getQQBotConfig: () => Options;
|
|
10
10
|
export declare const getMaster: (UserId: string) => readonly [boolean, string];
|
package/lib/format.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { DataEnums, DataMarkDown } from 'alemonjs';
|
|
2
|
-
export declare const markdownToText: (items: DataMarkDown["value"], hideUnsupported?: boolean) => string;
|
|
2
|
+
export declare const markdownToText: (items: DataMarkDown["value"], hideUnsupported?: boolean | number) => string;
|
|
3
3
|
export declare const buttonsToText: (rows: any[]) => string;
|
|
4
|
-
export declare const markdownRawToText: (raw: string, hideUnsupported?: boolean) => string;
|
|
5
|
-
export declare const dataEnumToText: (item: DataEnums, hideUnsupported?: boolean) => string;
|
|
4
|
+
export declare const markdownRawToText: (raw: string, hideUnsupported?: boolean | number) => string;
|
|
5
|
+
export declare const dataEnumToText: (item: DataEnums, hideUnsupported?: boolean | number) => string;
|
package/lib/format.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
const markdownToText = (items, hideUnsupported) => {
|
|
2
|
+
if (Number(hideUnsupported) >= 4)
|
|
3
|
+
return '';
|
|
2
4
|
return items
|
|
3
5
|
.map(item => {
|
|
4
6
|
switch (item.type) {
|
|
@@ -15,7 +17,9 @@ const markdownToText = (items, hideUnsupported) => {
|
|
|
15
17
|
return item.value;
|
|
16
18
|
case 'MD.link': {
|
|
17
19
|
const v = item.value;
|
|
18
|
-
|
|
20
|
+
if (Number(hideUnsupported) >= 3)
|
|
21
|
+
return '';
|
|
22
|
+
return Number(hideUnsupported) >= 2 ? v.url : `${v.text}( ${v.url} )`;
|
|
19
23
|
}
|
|
20
24
|
case 'MD.image':
|
|
21
25
|
return hideUnsupported ? '' : '[图片]';
|
|
@@ -44,6 +48,11 @@ const markdownToText = (items, hideUnsupported) => {
|
|
|
44
48
|
case 'MD.content':
|
|
45
49
|
return item.value;
|
|
46
50
|
case 'MD.button':
|
|
51
|
+
if (Number(hideUnsupported) >= 3)
|
|
52
|
+
return '';
|
|
53
|
+
if (Number(hideUnsupported) >= 2) {
|
|
54
|
+
return item.options?.data || String(item.value);
|
|
55
|
+
}
|
|
47
56
|
return hideUnsupported ? String(item.value) : `[${item.value}]`;
|
|
48
57
|
default:
|
|
49
58
|
return String(item?.value ?? '');
|
|
@@ -55,9 +64,11 @@ const buttonsToText = (rows) => {
|
|
|
55
64
|
return rows.map((row) => row.value.map((btn) => `[${btn.value}]`).join(' ')).join('\n');
|
|
56
65
|
};
|
|
57
66
|
const markdownRawToText = (raw, hideUnsupported) => {
|
|
67
|
+
if (Number(hideUnsupported) >= 4)
|
|
68
|
+
return '';
|
|
58
69
|
let text = raw;
|
|
59
70
|
text = text.replace(/!\[([^\]]*)\]\([^)]*\)/g, hideUnsupported ? '' : '[图片]');
|
|
60
|
-
text = text.replace(/\[([^\]]*)\]\([^)]
|
|
71
|
+
text = text.replace(/\[([^\]]*)\]\(([^)]*)\)/g, Number(hideUnsupported) >= 2 ? '$2' : '$1');
|
|
61
72
|
text = text.replace(/^#{1,6}\s+/gm, '');
|
|
62
73
|
text = text.replace(/(\*{3}|_{3})([^*_]+)\1/g, '$2');
|
|
63
74
|
text = text.replace(/(\*{2}|_{2})([^*_]+)\1/g, '$2');
|
|
@@ -72,9 +83,11 @@ const markdownRawToText = (raw, hideUnsupported) => {
|
|
|
72
83
|
text = text.replace(/^[-*_]{3,}\s*$/gm, hideUnsupported ? '' : '————————');
|
|
73
84
|
text = text.replace(/^[\s]*[-*+]\s+/gm, '· ');
|
|
74
85
|
text = text.replace(/^[\s]*(\d+)\.\s+/gm, '$1. ');
|
|
75
|
-
return text
|
|
86
|
+
return text;
|
|
76
87
|
};
|
|
77
88
|
const dataEnumToText = (item, hideUnsupported) => {
|
|
89
|
+
if (Number(hideUnsupported) >= 4)
|
|
90
|
+
return '';
|
|
78
91
|
switch (item.type) {
|
|
79
92
|
case 'MarkdownOriginal':
|
|
80
93
|
return markdownRawToText(String(item.value), hideUnsupported);
|
package/lib/sends.js
CHANGED
|
@@ -194,7 +194,7 @@ const extractContent = (val, mode) => {
|
|
|
194
194
|
})
|
|
195
195
|
.join('');
|
|
196
196
|
const config = getQQBotConfig();
|
|
197
|
-
const hide = config.hideUnsupported
|
|
197
|
+
const hide = config.hideUnsupported;
|
|
198
198
|
const fallbackText = val
|
|
199
199
|
.filter(item => !nativeTypes.has(item.type))
|
|
200
200
|
.map(item => dataEnumToText(item, hide))
|
|
@@ -326,7 +326,7 @@ const flattenMdToText = (content, val) => {
|
|
|
326
326
|
parts.push(buttonsToText(item.value));
|
|
327
327
|
}
|
|
328
328
|
}
|
|
329
|
-
return parts.filter(Boolean).join('\n');
|
|
329
|
+
return parts.filter(Boolean).join('\n').replace(/^[^\S\n\r]+|[^\S\n\r]+$/g, '');
|
|
330
330
|
};
|
|
331
331
|
const sendOpenApiMessage = async (content, val, baseParams, uploadMedia, sendMessage, label) => {
|
|
332
332
|
const config = getQQBotConfig();
|
|
@@ -413,7 +413,7 @@ const sendGuildMessage = async (content, val, baseParams, sendMessage, label) =>
|
|
|
413
413
|
const res = await sendMessage({ content: imgContent, ...baseParams }, imageBuffer);
|
|
414
414
|
return [createResult(ResultCode.Ok, label, { id: res?.id })];
|
|
415
415
|
}
|
|
416
|
-
if (config.hideUnsupported
|
|
416
|
+
if (config.hideUnsupported && !content && !buildMdAndButtonsParams(val) && !buildArkParams(val)) {
|
|
417
417
|
logger.info('[qq-bot] hideUnsupported: 消息内容转换后为空,跳过发送');
|
|
418
418
|
return [];
|
|
419
419
|
}
|