@alemonjs/bubble 2.1.2 → 2.1.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/README.md +5 -3
- package/lib/config.d.ts +1 -1
- package/lib/format.d.ts +3 -3
- package/lib/format.js +18 -3
- package/lib/send.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -44,8 +44,10 @@ bubble:
|
|
|
44
44
|
clientName: 'alemonjs-bot'
|
|
45
45
|
|
|
46
46
|
# 隐藏不支持的消息类型(可选,默认: false)
|
|
47
|
-
#
|
|
48
|
-
#
|
|
47
|
+
# 1:一级隐藏,不可读占位符([视频]、[音频]、[图片]、[附件]等)被置空,可读内容保留
|
|
48
|
+
# 2:二级隐藏,按钮仅显示指令数据(如 /挑战),链接仅显示 URL
|
|
49
|
+
# 3:三级隐藏,按钮和链接的 data 也不保留,完全隐藏
|
|
50
|
+
# 4:四级隐藏,不进行任何转换,降级数据直接丢弃
|
|
49
51
|
# 转换后内容为空时,将跳过发送并输出 info 日志
|
|
50
|
-
hideUnsupported:
|
|
52
|
+
hideUnsupported: 1
|
|
51
53
|
```
|
package/lib/config.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export type Options = BUBBLEOptions & {
|
|
|
8
8
|
websocket_options?: any;
|
|
9
9
|
clientName?: string;
|
|
10
10
|
URL?: string;
|
|
11
|
-
hideUnsupported?: boolean;
|
|
11
|
+
hideUnsupported?: boolean | number;
|
|
12
12
|
};
|
|
13
13
|
export declare const platform = "bubble";
|
|
14
14
|
export declare const getBubbleConfig: () => Options & {
|
package/lib/format.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { DataEnums, DataMarkDown } from 'alemonjs';
|
|
2
|
-
export declare const markdownToBubbleText: (items: DataMarkDown["value"]) => string;
|
|
3
|
-
export declare const markdownRawToBubbleText: (raw: string, hideUnsupported?: boolean) => string;
|
|
4
|
-
export declare const dataEnumToBubbleText: (item: DataEnums, hideUnsupported?: boolean) => string;
|
|
2
|
+
export declare const markdownToBubbleText: (items: DataMarkDown["value"], hideUnsupported?: boolean | number) => string;
|
|
3
|
+
export declare const markdownRawToBubbleText: (raw: string, hideUnsupported?: boolean | number) => string;
|
|
4
|
+
export declare const dataEnumToBubbleText: (item: DataEnums, hideUnsupported?: boolean | number) => string;
|
package/lib/format.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
const markdownToBubbleText = (items) => {
|
|
1
|
+
const markdownToBubbleText = (items, hideUnsupported) => {
|
|
2
|
+
if (Number(hideUnsupported) >= 4)
|
|
3
|
+
return '';
|
|
2
4
|
return items
|
|
3
5
|
.map(item => {
|
|
4
6
|
switch (item.type) {
|
|
@@ -17,7 +19,9 @@ const markdownToBubbleText = (items) => {
|
|
|
17
19
|
return `~~${item.value}~~`;
|
|
18
20
|
case 'MD.link': {
|
|
19
21
|
const v = item.value;
|
|
20
|
-
|
|
22
|
+
if (Number(hideUnsupported) >= 3)
|
|
23
|
+
return '';
|
|
24
|
+
return Number(hideUnsupported) >= 2 ? v.url : `[${v.text}](${v.url})`;
|
|
21
25
|
}
|
|
22
26
|
case 'MD.image':
|
|
23
27
|
return ``;
|
|
@@ -48,6 +52,12 @@ const markdownToBubbleText = (items) => {
|
|
|
48
52
|
case 'MD.content':
|
|
49
53
|
return item.value;
|
|
50
54
|
case 'MD.button': {
|
|
55
|
+
if (Number(hideUnsupported) >= 3)
|
|
56
|
+
return '';
|
|
57
|
+
if (Number(hideUnsupported) >= 2) {
|
|
58
|
+
const btnData = item.options?.data || (typeof item.value === 'object' ? item.value.title : item.value);
|
|
59
|
+
return String(btnData);
|
|
60
|
+
}
|
|
51
61
|
const options = item?.options;
|
|
52
62
|
const autoEnter = options?.autoEnter ?? false;
|
|
53
63
|
const label = typeof item.value === 'object' ? item.value.title : item.value;
|
|
@@ -58,15 +68,20 @@ const markdownToBubbleText = (items) => {
|
|
|
58
68
|
return String(item?.value ?? '');
|
|
59
69
|
}
|
|
60
70
|
})
|
|
61
|
-
.join('')
|
|
71
|
+
.join('')
|
|
72
|
+
.trim();
|
|
62
73
|
};
|
|
63
74
|
const markdownRawToBubbleText = (raw, hideUnsupported) => {
|
|
75
|
+
if (Number(hideUnsupported) >= 4)
|
|
76
|
+
return '';
|
|
64
77
|
if (hideUnsupported) {
|
|
65
78
|
return raw.replace(/!\[([^\]]*)\]\([^)]*\)/g, '');
|
|
66
79
|
}
|
|
67
80
|
return raw;
|
|
68
81
|
};
|
|
69
82
|
const dataEnumToBubbleText = (item, hideUnsupported) => {
|
|
83
|
+
if (Number(hideUnsupported) >= 4)
|
|
84
|
+
return '';
|
|
70
85
|
switch (item.type) {
|
|
71
86
|
case 'MarkdownOriginal':
|
|
72
87
|
return markdownRawToBubbleText(String(item.value), hideUnsupported);
|
package/lib/send.js
CHANGED
|
@@ -109,7 +109,7 @@ const sendToRoom = async (client, param, val) => {
|
|
|
109
109
|
const mdAndButtons = val.filter(item => item.type === 'Markdown' || item.type === 'BT.group');
|
|
110
110
|
const nativeTypes = new Set(['Image', 'ImageURL', 'ImageFile', 'Markdown', 'BT.group', 'Mention', 'Text', 'Link']);
|
|
111
111
|
const unsupportedItems = val.filter(item => !nativeTypes.has(item.type));
|
|
112
|
-
const hide = getBubbleConfig().hideUnsupported
|
|
112
|
+
const hide = getBubbleConfig().hideUnsupported;
|
|
113
113
|
const fallbackText = unsupportedItems
|
|
114
114
|
.map(item => dataEnumToBubbleText(item, hide))
|
|
115
115
|
.filter(Boolean)
|