@alemonjs/bubble 2.1.8 → 2.1.10
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/dist/assets/index.css +1 -1
- package/dist/assets/index.js +5 -5
- package/dist/index.html +1 -1
- package/lib/desktop.js +4 -4
- package/lib/hook.d.ts +9 -0
- package/lib/hook.js +1 -1
- package/lib/index.js +72 -135
- package/package.json +2 -2
package/dist/index.html
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
<meta charset="UTF-8" />
|
|
5
5
|
<link rel="icon" type="image/svg+xml" href="/favicon.ico" />
|
|
6
6
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
|
-
<title>
|
|
7
|
+
<title>ALemonJS</title>
|
|
8
8
|
<script type="module" crossorigin src="/assets/index.js"></script>
|
|
9
9
|
<link rel="stylesheet" crossorigin href="/assets/index.css">
|
|
10
10
|
</head>
|
package/lib/desktop.js
CHANGED
|
@@ -3,16 +3,16 @@ import { dirname, join } from 'path';
|
|
|
3
3
|
import { fileURLToPath } from 'url';
|
|
4
4
|
import { getConfig, getConfigValue } from 'alemonjs';
|
|
5
5
|
|
|
6
|
-
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
6
|
+
const __dirname$1 = dirname(fileURLToPath(import.meta.url));
|
|
7
7
|
const activate = context => {
|
|
8
8
|
const webView = context.createSidebarWebView(context);
|
|
9
9
|
context.onCommand('open.bubble', () => {
|
|
10
|
-
const dir = join(__dirname, '../', 'dist', 'index.html');
|
|
10
|
+
const dir = join(__dirname$1, '../', 'dist', 'index.html');
|
|
11
11
|
const scriptReg = /<script.*?src="(.+?)".*?>/;
|
|
12
12
|
const styleReg = /<link.*?rel="stylesheet".*?href="(.+?)".*?>/;
|
|
13
13
|
const iconReg = /<link.*?rel="icon".*?href="(.+?)".*?>/g;
|
|
14
|
-
const styleUri = context.createExtensionDir(join(__dirname, '../', 'dist', 'assets', 'index.css'));
|
|
15
|
-
const scriptUri = context.createExtensionDir(join(__dirname, '../', 'dist', 'assets', 'index.js'));
|
|
14
|
+
const styleUri = context.createExtensionDir(join(__dirname$1, '../', 'dist', 'assets', 'index.css'));
|
|
15
|
+
const scriptUri = context.createExtensionDir(join(__dirname$1, '../', 'dist', 'assets', 'index.js'));
|
|
16
16
|
const html = readFileSync(dir, 'utf-8')
|
|
17
17
|
.replace(iconReg, '')
|
|
18
18
|
.replace(scriptReg, `<script type="module" crossorigin src="${scriptUri}"></script>`)
|
package/lib/hook.d.ts
CHANGED
|
@@ -17,8 +17,17 @@ type MAP = {
|
|
|
17
17
|
'member.remove': undefined;
|
|
18
18
|
'private.message.update': undefined;
|
|
19
19
|
'private.message.delete': undefined;
|
|
20
|
+
'message.pin': undefined;
|
|
21
|
+
'channel.update': undefined;
|
|
22
|
+
'guild.update': undefined;
|
|
23
|
+
'member.ban': undefined;
|
|
24
|
+
'member.unban': undefined;
|
|
25
|
+
'member.update': undefined;
|
|
26
|
+
'notice.create': undefined;
|
|
20
27
|
'private.friend.add': undefined;
|
|
28
|
+
'private.friend.remove': undefined;
|
|
21
29
|
'private.guild.add': undefined;
|
|
30
|
+
'private.notice.create': undefined;
|
|
22
31
|
};
|
|
23
32
|
export declare const useValue: <T extends EventKeys>(event: Events[T]) => readonly [MAP[T]];
|
|
24
33
|
export declare const useClient: <T extends EventKeys>(event: Events[T]) => readonly [API, MAP[T]];
|
package/lib/hook.js
CHANGED
package/lib/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BubbleClient } from './sdk/wss.js';
|
|
2
|
-
import { definePlatform, cbpPlatform, createResult, ResultCode } from 'alemonjs';
|
|
2
|
+
import { definePlatform, cbpPlatform, FormatEvent, createResult, ResultCode } from 'alemonjs';
|
|
3
3
|
import { getMaster, platform } from './config.js';
|
|
4
4
|
import { CDN_URL } from './sdk/api.js';
|
|
5
5
|
export { BubbleAPI as API, API_URL, GATEWAY_URL } from './sdk/api.js';
|
|
@@ -43,158 +43,85 @@ const main = () => {
|
|
|
43
43
|
const UserId = String(event.authorId);
|
|
44
44
|
const [isMaster, UserKey] = getMaster(UserId);
|
|
45
45
|
const UserAvatar = createUserAvatar(UserId, event?.author?.avatar);
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
UserAvatar: UserAvatar,
|
|
56
|
-
IsMaster: isMaster,
|
|
57
|
-
IsBot: false,
|
|
58
|
-
OpenId: UserId,
|
|
59
|
-
MessageId: String(event.id),
|
|
60
|
-
MessageText: msg,
|
|
61
|
-
BotId: botId,
|
|
62
|
-
_tag: 'message.create',
|
|
63
|
-
value: event
|
|
64
|
-
};
|
|
65
|
-
cbp.send(e);
|
|
46
|
+
cbp.send(FormatEvent.create('message.create')
|
|
47
|
+
.addPlatform({ Platform: platform, value: event, BotId: botId })
|
|
48
|
+
.addGuild({ GuildId: String(event.channelId || ''), SpaceId: String(event.channelId || '') })
|
|
49
|
+
.addChannel({ ChannelId: String(event.channelId || '') })
|
|
50
|
+
.addUser({ UserId, UserKey, UserName: event?.author?.username, UserAvatar, IsMaster: isMaster, IsBot: false })
|
|
51
|
+
.addMessage({ MessageId: String(event.id) })
|
|
52
|
+
.addText({ MessageText: msg })
|
|
53
|
+
.addOpen({ OpenId: UserId })
|
|
54
|
+
.add({ tag: 'message.create' }).value);
|
|
66
55
|
});
|
|
67
56
|
client.on('DM_MESSAGE_CREATE', event => {
|
|
68
57
|
const UserId = String(event.authorId);
|
|
69
58
|
const [isMaster, UserKey] = getMaster(UserId);
|
|
70
59
|
const UserAvatar = createUserAvatar(UserId, event?.author?.avatar);
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
IsMaster: isMaster,
|
|
79
|
-
IsBot: false,
|
|
80
|
-
OpenId: UserId,
|
|
81
|
-
MessageId: String(event.id),
|
|
82
|
-
MessageText: event.content,
|
|
83
|
-
BotId: botId,
|
|
84
|
-
_tag: 'private.message.create',
|
|
85
|
-
value: event
|
|
86
|
-
};
|
|
87
|
-
cbp.send(e);
|
|
60
|
+
cbp.send(FormatEvent.create('private.message.create')
|
|
61
|
+
.addPlatform({ Platform: platform, value: event, BotId: botId })
|
|
62
|
+
.addUser({ UserId, UserKey, UserName: event?.author?.username, UserAvatar, IsMaster: isMaster, IsBot: false })
|
|
63
|
+
.addMessage({ MessageId: String(event.id) })
|
|
64
|
+
.addText({ MessageText: event.content })
|
|
65
|
+
.addOpen({ OpenId: UserId })
|
|
66
|
+
.add({ tag: 'private.message.create' }).value);
|
|
88
67
|
});
|
|
89
68
|
client.on('MESSAGE_UPDATE', event => {
|
|
90
69
|
const UserId = String(event.authorId);
|
|
91
70
|
const [isMaster, UserKey] = getMaster(UserId);
|
|
92
71
|
const UserAvatar = createUserAvatar(UserId, event?.author?.avatar);
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
UserKey,
|
|
101
|
-
UserName: event?.author?.username,
|
|
102
|
-
UserAvatar: UserAvatar,
|
|
103
|
-
IsMaster: isMaster,
|
|
104
|
-
IsBot: false,
|
|
105
|
-
MessageId: String(event.id),
|
|
106
|
-
BotId: botId,
|
|
107
|
-
_tag: 'MESSAGE_UPDATE',
|
|
108
|
-
value: event
|
|
109
|
-
};
|
|
110
|
-
cbp.send(e);
|
|
72
|
+
cbp.send(FormatEvent.create('message.update')
|
|
73
|
+
.addPlatform({ Platform: platform, value: event, BotId: botId })
|
|
74
|
+
.addGuild({ GuildId: String(event.channelId || ''), SpaceId: String(event.channelId || '') })
|
|
75
|
+
.addChannel({ ChannelId: String(event.channelId || '') })
|
|
76
|
+
.addUser({ UserId, UserKey, UserName: event?.author?.username, UserAvatar, IsMaster: isMaster, IsBot: false })
|
|
77
|
+
.addMessage({ MessageId: String(event.id) })
|
|
78
|
+
.add({ tag: 'MESSAGE_UPDATE' }).value);
|
|
111
79
|
});
|
|
112
80
|
client.on('MESSAGE_DELETE', event => {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
MessageId: String(event.id),
|
|
120
|
-
BotId: botId,
|
|
121
|
-
_tag: 'MESSAGE_DELETE',
|
|
122
|
-
value: event
|
|
123
|
-
};
|
|
124
|
-
cbp.send(e);
|
|
81
|
+
cbp.send(FormatEvent.create('message.delete')
|
|
82
|
+
.addPlatform({ Platform: platform, value: event, BotId: botId })
|
|
83
|
+
.addGuild({ GuildId: String(event.guild_id || ''), SpaceId: String(event.channel_id || '') })
|
|
84
|
+
.addChannel({ ChannelId: String(event.channel_id || '') })
|
|
85
|
+
.addMessage({ MessageId: String(event.id) })
|
|
86
|
+
.add({ tag: 'MESSAGE_DELETE' }).value);
|
|
125
87
|
});
|
|
126
88
|
client.on('DM_MESSAGE_UPDATE', event => {
|
|
127
89
|
const UserId = String(event.authorId);
|
|
128
90
|
const [isMaster, UserKey] = getMaster(UserId);
|
|
129
91
|
const UserAvatar = createUserAvatar(UserId, event?.author?.avatar);
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
UserName: event?.author?.username,
|
|
136
|
-
UserAvatar: UserAvatar,
|
|
137
|
-
IsMaster: isMaster,
|
|
138
|
-
IsBot: false,
|
|
139
|
-
MessageId: String(event.id),
|
|
140
|
-
BotId: botId,
|
|
141
|
-
_tag: 'DM_MESSAGE_UPDATE',
|
|
142
|
-
value: event
|
|
143
|
-
};
|
|
144
|
-
cbp.send(e);
|
|
92
|
+
cbp.send(FormatEvent.create('private.message.update')
|
|
93
|
+
.addPlatform({ Platform: platform, value: event, BotId: botId })
|
|
94
|
+
.addUser({ UserId, UserKey, UserName: event?.author?.username, UserAvatar, IsMaster: isMaster, IsBot: false })
|
|
95
|
+
.addMessage({ MessageId: String(event.id) })
|
|
96
|
+
.add({ tag: 'DM_MESSAGE_UPDATE' }).value);
|
|
145
97
|
});
|
|
146
98
|
client.on('DM_MESSAGE_DELETE', event => {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
BotId: botId,
|
|
152
|
-
_tag: 'DM_MESSAGE_DELETE',
|
|
153
|
-
value: event
|
|
154
|
-
};
|
|
155
|
-
cbp.send(e);
|
|
99
|
+
cbp.send(FormatEvent.create('private.message.delete')
|
|
100
|
+
.addPlatform({ Platform: platform, value: event, BotId: botId })
|
|
101
|
+
.addMessage({ MessageId: String(event.id) })
|
|
102
|
+
.add({ tag: 'DM_MESSAGE_DELETE' }).value);
|
|
156
103
|
});
|
|
157
104
|
client.on('GUILD_MEMBER_ADD', event => {
|
|
158
105
|
const UserId = String(event.user_id || event.user?.id || '');
|
|
159
106
|
const [isMaster, UserKey] = getMaster(UserId);
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
UserKey,
|
|
168
|
-
UserName: event.user?.username ?? event.nickname,
|
|
169
|
-
IsMaster: isMaster,
|
|
170
|
-
IsBot: false,
|
|
171
|
-
MessageId: '',
|
|
172
|
-
BotId: botId,
|
|
173
|
-
_tag: 'GUILD_MEMBER_ADD',
|
|
174
|
-
value: event
|
|
175
|
-
};
|
|
176
|
-
cbp.send(e);
|
|
107
|
+
cbp.send(FormatEvent.create('member.add')
|
|
108
|
+
.addPlatform({ Platform: platform, value: event, BotId: botId })
|
|
109
|
+
.addGuild({ GuildId: String(event.guild_id || ''), SpaceId: String(event.guild_id || '') })
|
|
110
|
+
.addChannel({ ChannelId: '' })
|
|
111
|
+
.addUser({ UserId, UserKey, UserName: event.user?.username ?? event.nickname, IsMaster: isMaster, IsBot: false })
|
|
112
|
+
.addMessage({ MessageId: '' })
|
|
113
|
+
.add({ tag: 'GUILD_MEMBER_ADD' }).value);
|
|
177
114
|
});
|
|
178
115
|
client.on('GUILD_MEMBER_REMOVE', event => {
|
|
179
116
|
const UserId = String(event.user_id || event.user?.id || '');
|
|
180
117
|
const [isMaster, UserKey] = getMaster(UserId);
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
UserKey,
|
|
189
|
-
UserName: event.user?.username ?? event.nickname,
|
|
190
|
-
IsMaster: isMaster,
|
|
191
|
-
IsBot: false,
|
|
192
|
-
MessageId: '',
|
|
193
|
-
BotId: botId,
|
|
194
|
-
_tag: 'GUILD_MEMBER_REMOVE',
|
|
195
|
-
value: event
|
|
196
|
-
};
|
|
197
|
-
cbp.send(e);
|
|
118
|
+
cbp.send(FormatEvent.create('member.remove')
|
|
119
|
+
.addPlatform({ Platform: platform, value: event, BotId: botId })
|
|
120
|
+
.addGuild({ GuildId: String(event.guild_id || ''), SpaceId: String(event.guild_id || '') })
|
|
121
|
+
.addChannel({ ChannelId: '' })
|
|
122
|
+
.addUser({ UserId, UserKey, UserName: event.user?.username ?? event.nickname, IsMaster: isMaster, IsBot: false })
|
|
123
|
+
.addMessage({ MessageId: '' })
|
|
124
|
+
.add({ tag: 'GUILD_MEMBER_REMOVE' }).value);
|
|
198
125
|
});
|
|
199
126
|
const api = {
|
|
200
127
|
active: {
|
|
@@ -337,18 +264,28 @@ const main = () => {
|
|
|
337
264
|
cbp.onactions((data, consume) => void onactions(data, consume));
|
|
338
265
|
const onapis = async (data, consume) => {
|
|
339
266
|
const key = data.payload?.key;
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
267
|
+
const params = data.payload?.params;
|
|
268
|
+
try {
|
|
269
|
+
const keys = key.split('.');
|
|
270
|
+
let parent = null;
|
|
271
|
+
let target = client;
|
|
272
|
+
for (const k of keys) {
|
|
273
|
+
if (target === null || target === undefined || !(k in target)) {
|
|
274
|
+
consume([createResult(ResultCode.Fail, '未知请求,请尝试升级版本', null)]);
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
parent = target;
|
|
278
|
+
target = target[k];
|
|
345
279
|
}
|
|
346
|
-
|
|
347
|
-
consume([createResult(ResultCode.Fail, '
|
|
280
|
+
if (typeof target !== 'function') {
|
|
281
|
+
consume([createResult(ResultCode.Fail, '目标不是可调用方法', null)]);
|
|
282
|
+
return;
|
|
348
283
|
}
|
|
284
|
+
const res = await target.call(parent, ...params);
|
|
285
|
+
consume([createResult(ResultCode.Ok, '请求完成', res)]);
|
|
349
286
|
}
|
|
350
|
-
|
|
351
|
-
consume([createResult(ResultCode.Fail, '
|
|
287
|
+
catch (error) {
|
|
288
|
+
consume([createResult(ResultCode.Fail, '请求失败', error)]);
|
|
352
289
|
}
|
|
353
290
|
};
|
|
354
291
|
cbp.onapis((data, consume) => void onapis(data, consume));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alemonjs/bubble",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.10",
|
|
4
4
|
"description": "bubble platform",
|
|
5
5
|
"author": "lemonade",
|
|
6
6
|
"license": "MIT",
|
|
@@ -62,5 +62,5 @@
|
|
|
62
62
|
"type": "git",
|
|
63
63
|
"url": "https://github.com/lemonade-lab/alemonjs.git"
|
|
64
64
|
},
|
|
65
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "fee3935ca19b1658ea4b41d5d3e7f281e7efc932"
|
|
66
66
|
}
|