@alemonjs/bubble 2.1.1 → 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 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,12 @@ 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
- ## API 文档
59
-
60
- 详细的 API 文档请参考:[https://bubble.alemonjs.com/developer/docs](https://bubble.alemonjs.com/developer/docs)
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
+ # 1:一级隐藏,不可读占位符([视频]、[音频]、[图片]、[附件]等)被置空,可读内容保留
48
+ # 2:二级隐藏,按钮仅显示指令数据(如 /挑战),链接仅显示 URL
49
+ # 3:三级隐藏,按钮和链接的 data 也不保留,完全隐藏
50
+ # 4:四级隐藏,不进行任何转换,降级数据直接丢弃
51
+ # 转换后内容为空时,将跳过发送并输出 info 日志
52
+ hideUnsupported: 1
53
+ ```
package/lib/config.d.ts CHANGED
@@ -8,6 +8,7 @@ export type Options = BUBBLEOptions & {
8
8
  websocket_options?: any;
9
9
  clientName?: string;
10
10
  URL?: string;
11
+ hideUnsupported?: boolean | number;
11
12
  };
12
13
  export declare const platform = "bubble";
13
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) => string;
4
- export declare const dataEnumToBubbleText: (item: DataEnums) => 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
- return `[${v.text}](${v.url})`;
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 `![image](${item.value})`;
@@ -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,21 +68,29 @@ const markdownToBubbleText = (items) => {
58
68
  return String(item?.value ?? '');
59
69
  }
60
70
  })
61
- .join('');
71
+ .join('')
72
+ .trim();
62
73
  };
63
- const markdownRawToBubbleText = (raw) => {
74
+ const markdownRawToBubbleText = (raw, hideUnsupported) => {
75
+ if (Number(hideUnsupported) >= 4)
76
+ return '';
77
+ if (hideUnsupported) {
78
+ return raw.replace(/!\[([^\]]*)\]\([^)]*\)/g, '');
79
+ }
64
80
  return raw;
65
81
  };
66
- const dataEnumToBubbleText = (item) => {
82
+ const dataEnumToBubbleText = (item, hideUnsupported) => {
83
+ if (Number(hideUnsupported) >= 4)
84
+ return '';
67
85
  switch (item.type) {
68
86
  case 'MarkdownOriginal':
69
- return markdownRawToBubbleText(String(item.value));
87
+ return markdownRawToBubbleText(String(item.value), hideUnsupported);
70
88
  case 'Attachment':
71
- return `[附件${item.options?.filename ? ': ' + item.options.filename : ''}]`;
89
+ return hideUnsupported ? '' : `[附件${item.options?.filename ? ': ' + item.options.filename : ''}]`;
72
90
  case 'Audio':
73
- return '[音频]';
91
+ return hideUnsupported ? '' : '[音频]';
74
92
  case 'Video':
75
- return '[视频]';
93
+ return hideUnsupported ? '' : '[视频]';
76
94
  default:
77
95
  return '';
78
96
  }
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 fallbackText = unsupportedItems.map(item => dataEnumToBubbleText(item)).filter(Boolean).join('\n');
112
+ const hide = getBubbleConfig().hideUnsupported;
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++) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alemonjs/bubble",
3
- "version": "2.1.1",
3
+ "version": "2.1.3",
4
4
  "description": "bubble platform",
5
5
  "author": "lemonade",
6
6
  "license": "MIT",