@alemonjs/bubble 2.1.5 → 2.1.7
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/LICENSE +21 -0
- package/lib/config.d.ts +1 -1
- package/lib/config.js +2 -10
- package/lib/format.js +10 -5
- package/lib/index.js +34 -0
- package/package.json +4 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2013-present, Yuxi (Evan) You
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIdED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
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) =>
|
|
17
|
+
export declare const getMaster: (UserId: string) => boolean;
|
package/lib/config.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isMaster, getConfigValue } from 'alemonjs';
|
|
2
2
|
import { GATEWAY_URL, API_URL, CDN_URL } from './sdk/api.js';
|
|
3
3
|
|
|
4
4
|
const platform = 'bubble';
|
|
@@ -20,15 +20,7 @@ const getBubbleConfig = () => {
|
|
|
20
20
|
return config;
|
|
21
21
|
};
|
|
22
22
|
const getMaster = (UserId) => {
|
|
23
|
-
|
|
24
|
-
const masterKey = config.master_key || [];
|
|
25
|
-
const masterId = config.master_id || [];
|
|
26
|
-
const UserKey = useUserHashKey({
|
|
27
|
-
Platform: platform,
|
|
28
|
-
UserId: UserId
|
|
29
|
-
});
|
|
30
|
-
const is = masterKey.includes(UserKey) || masterId.includes(UserId);
|
|
31
|
-
return [is, UserKey];
|
|
23
|
+
return isMaster(UserId, platform);
|
|
32
24
|
};
|
|
33
25
|
|
|
34
26
|
export { getBubbleConfig, getMaster, platform };
|
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alemonjs/bubble",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.7",
|
|
4
4
|
"description": "bubble platform",
|
|
5
5
|
"author": "lemonade",
|
|
6
6
|
"license": "MIT",
|
|
@@ -61,5 +61,6 @@
|
|
|
61
61
|
"repository": {
|
|
62
62
|
"type": "git",
|
|
63
63
|
"url": "https://github.com/lemonade-lab/alemonjs.git"
|
|
64
|
-
}
|
|
65
|
-
|
|
64
|
+
},
|
|
65
|
+
"gitHead": "e50477125586204c6e56a8ecfe3391136f5fe74b"
|
|
66
|
+
}
|