@alemonjs/bubble 2.1.4 → 2.1.6

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/lib/config.d.ts CHANGED
@@ -14,4 +14,4 @@ export declare const platform = "bubble";
14
14
  export declare const getBubbleConfig: () => Options & {
15
15
  [key: string]: any;
16
16
  };
17
- export declare const getMaster: (UserId: string) => readonly [boolean, string];
17
+ export declare const getMaster: (UserId: string) => readonly [any, string];
package/lib/config.js CHANGED
@@ -1,4 +1,4 @@
1
- import { useUserHashKey, getConfigValue } from 'alemonjs';
1
+ import { getConfigValue, useUserHashKey } from 'alemonjs';
2
2
  import { GATEWAY_URL, API_URL, CDN_URL } from './sdk/api.js';
3
3
 
4
4
  const platform = 'bubble';
@@ -20,6 +20,9 @@ const getBubbleConfig = () => {
20
20
  return config;
21
21
  };
22
22
  const getMaster = (UserId) => {
23
+ const values = getConfigValue() || {};
24
+ const mainMasterKey = values.master_key || [];
25
+ const mainMasterId = values.master_id || [];
23
26
  const config = getBubbleConfig();
24
27
  const masterKey = config.master_key || [];
25
28
  const masterId = config.master_id || [];
@@ -27,7 +30,7 @@ const getMaster = (UserId) => {
27
30
  Platform: platform,
28
31
  UserId: UserId
29
32
  });
30
- const is = masterKey.includes(UserKey) || masterId.includes(UserId);
33
+ const is = mainMasterKey.includes(UserKey) || mainMasterId.includes(UserId) || masterKey.includes(UserKey) || masterId.includes(UserId);
31
34
  return [is, UserKey];
32
35
  };
33
36
 
package/lib/format.js CHANGED
@@ -1,6 +1,7 @@
1
1
  const markdownToBubbleText = (items, hideUnsupported) => {
2
- if (Number(hideUnsupported) >= 4)
2
+ if (Number(hideUnsupported) >= 4) {
3
3
  return '';
4
+ }
4
5
  return items
5
6
  .map(item => {
6
7
  switch (item.type) {
@@ -19,8 +20,9 @@ const markdownToBubbleText = (items, hideUnsupported) => {
19
20
  return `~~${item.value}~~`;
20
21
  case 'MD.link': {
21
22
  const v = item.value;
22
- if (Number(hideUnsupported) >= 3)
23
+ if (Number(hideUnsupported) >= 3) {
23
24
  return '';
25
+ }
24
26
  return Number(hideUnsupported) >= 2 ? v.url : `[${v.text}](${v.url})`;
25
27
  }
26
28
  case 'MD.image':
@@ -52,8 +54,9 @@ const markdownToBubbleText = (items, hideUnsupported) => {
52
54
  case 'MD.content':
53
55
  return item.value;
54
56
  case 'MD.button': {
55
- if (Number(hideUnsupported) >= 3)
57
+ if (Number(hideUnsupported) >= 3) {
56
58
  return '';
59
+ }
57
60
  if (Number(hideUnsupported) >= 2) {
58
61
  const btnData = item.options?.data || (typeof item.value === 'object' ? item.value.title : item.value);
59
62
  return String(btnData);
@@ -71,16 +74,18 @@ const markdownToBubbleText = (items, hideUnsupported) => {
71
74
  .join('');
72
75
  };
73
76
  const markdownRawToBubbleText = (raw, hideUnsupported) => {
74
- if (Number(hideUnsupported) >= 4)
77
+ if (Number(hideUnsupported) >= 4) {
75
78
  return '';
79
+ }
76
80
  if (hideUnsupported) {
77
81
  return raw.replace(/!\[([^\]]*)\]\([^)]*\)/g, '');
78
82
  }
79
83
  return raw;
80
84
  };
81
85
  const dataEnumToBubbleText = (item, hideUnsupported) => {
82
- if (Number(hideUnsupported) >= 4)
86
+ if (Number(hideUnsupported) >= 4) {
83
87
  return '';
88
+ }
84
89
  switch (item.type) {
85
90
  case 'MarkdownOriginal':
86
91
  return markdownRawToBubbleText(String(item.value), hideUnsupported);
package/lib/index.js CHANGED
@@ -292,6 +292,40 @@ const main = () => {
292
292
  const res = await api.use.mention(event);
293
293
  consume([createResult(ResultCode.Ok, '请求完成', res)]);
294
294
  }
295
+ else if (data.action === 'media.upload') {
296
+ const params = data.payload.params;
297
+ const fileData = params?.url ?? params?.data;
298
+ if (!fileData) {
299
+ consume([createResult(ResultCode.FailParams, 'Missing url or data', null)]);
300
+ }
301
+ else {
302
+ const res = await client
303
+ .uploadFile(fileData, params?.name)
304
+ .then(r => createResult(ResultCode.Ok, data.action, r))
305
+ .catch(err => createResult(ResultCode.Fail, data.action, err));
306
+ consume([res]);
307
+ }
308
+ }
309
+ else if (data.action === 'history.list') {
310
+ const res = await client
311
+ .getChannelMessages(data.payload.ChannelId)
312
+ .then(r => createResult(ResultCode.Ok, data.action, r))
313
+ .catch(err => createResult(ResultCode.Fail, data.action, err));
314
+ consume([res]);
315
+ }
316
+ else if (data.action === 'member.search') {
317
+ const guildId = data.payload.GuildId;
318
+ const keyword = data.payload.params?.keyword ?? '';
319
+ const res = await client
320
+ .listGuildMembers(guildId)
321
+ .then(r => {
322
+ const list = Array.isArray(r) ? r : [];
323
+ const filtered = list.filter((m) => (m.name ?? '').includes(keyword) || (m.username ?? '').includes(keyword));
324
+ return createResult(ResultCode.Ok, data.action, filtered);
325
+ })
326
+ .catch(err => createResult(ResultCode.Fail, data.action, err));
327
+ consume([res]);
328
+ }
295
329
  else {
296
330
  consume([createResult(ResultCode.Fail, '未知请求,请尝试升级版本', null)]);
297
331
  }
package/lib/send.js CHANGED
@@ -151,7 +151,10 @@ const sendToRoom = async (client, param, val) => {
151
151
  })
152
152
  .join('');
153
153
  const contentMd = buildBubbleMdContent(mdAndButtons);
154
- const finalContent = [content, contentMd, fallbackText].filter(Boolean).join('\n').replace(/^[^\S\n\r]+|[^\S\n\r]+$/g, '');
154
+ const finalContent = [content, contentMd, fallbackText]
155
+ .filter(Boolean)
156
+ .join('\n')
157
+ .replace(/^[^\S\n\r]+|[^\S\n\r]+$/g, '');
155
158
  if (hide && !finalContent && images.length <= 0) {
156
159
  logger.info('[bubble] hideUnsupported: 消息内容转换后为空,跳过发送');
157
160
  return [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alemonjs/bubble",
3
- "version": "2.1.4",
3
+ "version": "2.1.6",
4
4
  "description": "bubble platform",
5
5
  "author": "lemonade",
6
6
  "license": "MIT",
@@ -36,18 +36,15 @@
36
36
  "name": "bubble"
37
37
  }
38
38
  ],
39
- "logo": "antd.bubbleOutlined",
40
39
  "command": [
41
40
  {
42
41
  "name": "打开bubble",
43
- "icon": "antd.bubbleOutlined",
44
42
  "command": "open.bubble"
45
43
  }
46
44
  ],
47
45
  "sidebars": [
48
46
  {
49
- "name": "dc",
50
- "icon": "antd.bubbleOutlined",
47
+ "name": "bubble",
51
48
  "command": "open.bubble"
52
49
  }
53
50
  ]
@@ -64,5 +61,6 @@
64
61
  "repository": {
65
62
  "type": "git",
66
63
  "url": "https://github.com/lemonade-lab/alemonjs.git"
67
- }
68
- }
64
+ },
65
+ "gitHead": "743b70375f728a1584ae149bbadcd04378540ade"
66
+ }