@alemonjs/bubble 2.1.1 → 2.1.2
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 +6 -33
- package/lib/config.d.ts +1 -0
- package/lib/format.d.ts +2 -2
- package/lib/format.js +9 -6
- package/lib/send.js +10 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
# @alemonjs/bubble
|
|
2
2
|
|
|
3
|
-
Bubble 平台适配器 for AlemonJS
|
|
4
|
-
|
|
5
3
|
[文档 https://bubble.alemonjs.com/developer/docs](https://bubble.alemonjs.com/developer/docs)
|
|
6
4
|
|
|
7
5
|
## 安装
|
|
@@ -44,35 +42,10 @@ bubble:
|
|
|
44
42
|
|
|
45
43
|
# 客户端名称(可选,默认: alemonjs-bot)
|
|
46
44
|
clientName: 'alemonjs-bot'
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
## 功能特性
|
|
50
|
-
|
|
51
|
-
- ✅ WebSocket Gateway 实时事件推送
|
|
52
|
-
- ✅ 完整的 HTTP API 接口支持
|
|
53
|
-
- ✅ 文件上传功能
|
|
54
|
-
- ✅ 类型安全的 TypeScript 支持
|
|
55
|
-
- ✅ 自动重连机制
|
|
56
|
-
- ✅ 事件订阅管理
|
|
57
45
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
- `MESSAGE_CREATE` - 频道新消息创建
|
|
65
|
-
- `MESSAGE_UPDATE` - 频道消息更新
|
|
66
|
-
- `MESSAGE_DELETE` - 频道消息删除
|
|
67
|
-
- `MESSAGE_UNPIN` - 频道消息取消置顶
|
|
68
|
-
- `DM_MESSAGE_CREATE` - 私聊新消息创建
|
|
69
|
-
- `DM_MESSAGE_UPDATE` - 私聊消息更新
|
|
70
|
-
- `DM_MESSAGE_DELETE` - 私聊消息删除
|
|
71
|
-
- `DM_MESSAGE_UNPIN` - 私聊消息取消置顶
|
|
72
|
-
- `GUILD_MEMBER_ADD` - 成员加入服务器
|
|
73
|
-
- `GUILD_MEMBER_UPDATE` - 成员更新
|
|
74
|
-
- `GUILD_MEMBER_REMOVE` - 成员离开服务器
|
|
75
|
-
- `BOT_READY` - 机器人就绪
|
|
76
|
-
- `EVENTS_SUBSCRIBED` - 事件订阅成功
|
|
77
|
-
- `EVENTS_UNSUBSCRIBED` - 事件取消订阅成功
|
|
78
|
-
- `SUBSCRIBE_DENIED` - 订阅被拒绝
|
|
46
|
+
# 隐藏不支持的消息类型(可选,默认: false)
|
|
47
|
+
# 开启后,转为文本时不可读内容(如 [视频]、[音频]、[图片]、[附件] 等占位符)将被置空
|
|
48
|
+
# 可读内容(如标题、按钮文本、链接等)仍会保留为纯文本
|
|
49
|
+
# 转换后内容为空时,将跳过发送并输出 info 日志
|
|
50
|
+
hideUnsupported: true
|
|
51
|
+
```
|
package/lib/config.d.ts
CHANGED
package/lib/format.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { DataEnums, DataMarkDown } from 'alemonjs';
|
|
2
2
|
export declare const markdownToBubbleText: (items: DataMarkDown["value"]) => string;
|
|
3
|
-
export declare const markdownRawToBubbleText: (raw: string) => string;
|
|
4
|
-
export declare const dataEnumToBubbleText: (item: DataEnums) => string;
|
|
3
|
+
export declare const markdownRawToBubbleText: (raw: string, hideUnsupported?: boolean) => string;
|
|
4
|
+
export declare const dataEnumToBubbleText: (item: DataEnums, hideUnsupported?: boolean) => string;
|
package/lib/format.js
CHANGED
|
@@ -60,19 +60,22 @@ const markdownToBubbleText = (items) => {
|
|
|
60
60
|
})
|
|
61
61
|
.join('');
|
|
62
62
|
};
|
|
63
|
-
const markdownRawToBubbleText = (raw) => {
|
|
63
|
+
const markdownRawToBubbleText = (raw, hideUnsupported) => {
|
|
64
|
+
if (hideUnsupported) {
|
|
65
|
+
return raw.replace(/!\[([^\]]*)\]\([^)]*\)/g, '');
|
|
66
|
+
}
|
|
64
67
|
return raw;
|
|
65
68
|
};
|
|
66
|
-
const dataEnumToBubbleText = (item) => {
|
|
69
|
+
const dataEnumToBubbleText = (item, hideUnsupported) => {
|
|
67
70
|
switch (item.type) {
|
|
68
71
|
case 'MarkdownOriginal':
|
|
69
|
-
return markdownRawToBubbleText(String(item.value));
|
|
72
|
+
return markdownRawToBubbleText(String(item.value), hideUnsupported);
|
|
70
73
|
case 'Attachment':
|
|
71
|
-
return `[附件${item.options?.filename ? ': ' + item.options.filename : ''}]`;
|
|
74
|
+
return hideUnsupported ? '' : `[附件${item.options?.filename ? ': ' + item.options.filename : ''}]`;
|
|
72
75
|
case 'Audio':
|
|
73
|
-
return '[音频]';
|
|
76
|
+
return hideUnsupported ? '' : '[音频]';
|
|
74
77
|
case 'Video':
|
|
75
|
-
return '[视频]';
|
|
78
|
+
return hideUnsupported ? '' : '[视频]';
|
|
76
79
|
default:
|
|
77
80
|
return '';
|
|
78
81
|
}
|
package/lib/send.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createResult, ResultCode } from 'alemonjs';
|
|
2
2
|
import { readFileSync } from 'fs';
|
|
3
3
|
import { dataEnumToBubbleText } from './format.js';
|
|
4
|
+
import { getBubbleConfig } from './config.js';
|
|
4
5
|
|
|
5
6
|
const ImageURLToBuffer = async (url) => {
|
|
6
7
|
const arrayBuffer = await fetch(url).then(res => res.arrayBuffer());
|
|
@@ -108,7 +109,11 @@ const sendToRoom = async (client, param, val) => {
|
|
|
108
109
|
const mdAndButtons = val.filter(item => item.type === 'Markdown' || item.type === 'BT.group');
|
|
109
110
|
const nativeTypes = new Set(['Image', 'ImageURL', 'ImageFile', 'Markdown', 'BT.group', 'Mention', 'Text', 'Link']);
|
|
110
111
|
const unsupportedItems = val.filter(item => !nativeTypes.has(item.type));
|
|
111
|
-
const
|
|
112
|
+
const hide = getBubbleConfig().hideUnsupported === true;
|
|
113
|
+
const fallbackText = unsupportedItems
|
|
114
|
+
.map(item => dataEnumToBubbleText(item, hide))
|
|
115
|
+
.filter(Boolean)
|
|
116
|
+
.join('\n');
|
|
112
117
|
const content = val
|
|
113
118
|
.filter(item => item.type === 'Mention' || item.type === 'Text' || item.type === 'Link')
|
|
114
119
|
.map(item => {
|
|
@@ -147,6 +152,10 @@ const sendToRoom = async (client, param, val) => {
|
|
|
147
152
|
.join('');
|
|
148
153
|
const contentMd = buildBubbleMdContent(mdAndButtons);
|
|
149
154
|
const finalContent = [content, contentMd, fallbackText].filter(Boolean).join('\n');
|
|
155
|
+
if (hide && !finalContent && images.length <= 0) {
|
|
156
|
+
logger.info('[bubble] hideUnsupported: 消息内容转换后为空,跳过发送');
|
|
157
|
+
return [];
|
|
158
|
+
}
|
|
150
159
|
if (images.length > 0) {
|
|
151
160
|
let bufferData = null;
|
|
152
161
|
for (let i = 0; i < images.length; i++) {
|