@alemonjs/onebot 2.1.0-alpha.13 → 2.1.0-alpha.16
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.js +3 -3
- package/lib/db.d.ts +0 -2
- package/lib/db.js +1 -3
- package/lib/index.d.ts +2 -2
- package/lib/index.js +40 -30
- package/lib/sdk/api.d.ts +4 -1
- package/lib/sdk/api.js +91 -85
- package/lib/sdk/config.d.ts +4 -2
- package/lib/sdk/types.d.ts +2 -2
- package/lib/sdk/typing.d.ts +2 -2
- package/lib/sdk/wss.js +8 -8
- package/package.json +2 -3
package/lib/config.js
CHANGED
|
@@ -7,13 +7,13 @@ const getOneBotConfig = () => {
|
|
|
7
7
|
};
|
|
8
8
|
const getMaster = (UserId) => {
|
|
9
9
|
const config = getOneBotConfig();
|
|
10
|
-
const
|
|
11
|
-
const
|
|
10
|
+
const masterKey = config.master_key || [];
|
|
11
|
+
const masterId = config.master_id || [];
|
|
12
12
|
const UserKey = useUserHashKey({
|
|
13
13
|
Platform: platform,
|
|
14
14
|
UserId: UserId
|
|
15
15
|
});
|
|
16
|
-
const is =
|
|
16
|
+
const is = masterKey.includes(UserKey) || masterId.includes(UserId);
|
|
17
17
|
return [is, UserKey];
|
|
18
18
|
};
|
|
19
19
|
|
package/lib/db.d.ts
CHANGED
package/lib/db.js
CHANGED
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { cbpPlatform, createResult, ResultCode } from 'alemonjs';
|
|
1
|
+
import { definePlatform, cbpPlatform, createResult, ResultCode } from 'alemonjs';
|
|
2
2
|
import { getBufferByURL } from 'alemonjs/utils';
|
|
3
3
|
import { readFileSync } from 'fs';
|
|
4
4
|
import { getOneBotConfig, getMaster, platform } from './config.js';
|
|
@@ -128,10 +128,46 @@ const main = () => {
|
|
|
128
128
|
return empty;
|
|
129
129
|
}
|
|
130
130
|
else if (item.type === 'Image') {
|
|
131
|
+
if (item.value.startsWith('http://') || item.value.startsWith('https://')) {
|
|
132
|
+
const res = await getBufferByURL(item.value);
|
|
133
|
+
return {
|
|
134
|
+
type: 'image',
|
|
135
|
+
data: {
|
|
136
|
+
file: `base64://${res.toString('base64')}`
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
else if (item.value.startsWith('base64://')) {
|
|
141
|
+
const base64Str = item.value.replace('base64://', '');
|
|
142
|
+
return {
|
|
143
|
+
type: 'image',
|
|
144
|
+
data: {
|
|
145
|
+
file: `base64://${base64Str}`
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
else if (item.value.startsWith('buffer://')) {
|
|
150
|
+
const base64Str = item.value.replace('buffer://', '');
|
|
151
|
+
return {
|
|
152
|
+
type: 'image',
|
|
153
|
+
data: {
|
|
154
|
+
file: `base64://${base64Str}`
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
else if (item.value.startsWith('file://')) {
|
|
159
|
+
const db = readFileSync(item.value);
|
|
160
|
+
return {
|
|
161
|
+
type: 'image',
|
|
162
|
+
data: {
|
|
163
|
+
file: `base64://${db.toString('base64')}`
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
}
|
|
131
167
|
return {
|
|
132
168
|
type: 'image',
|
|
133
169
|
data: {
|
|
134
|
-
file: `base64://${item.value}`
|
|
170
|
+
file: `base64://${item.value.toString('base64')}`
|
|
135
171
|
}
|
|
136
172
|
};
|
|
137
173
|
}
|
|
@@ -358,32 +394,6 @@ const main = () => {
|
|
|
358
394
|
};
|
|
359
395
|
cbp.onapis((data, consume) => void onapis(data, consume));
|
|
360
396
|
};
|
|
361
|
-
|
|
362
|
-
['SIGINT', 'SIGTERM', 'SIGQUIT', 'disconnect'].forEach(sig => {
|
|
363
|
-
process?.on?.(sig, () => {
|
|
364
|
-
logger.info?.(`[@alemonjs/onebot][${sig}] 收到信号,正在关闭...`);
|
|
365
|
-
setImmediate(() => process.exit(0));
|
|
366
|
-
});
|
|
367
|
-
});
|
|
368
|
-
process?.on?.('exit', code => {
|
|
369
|
-
logger.info?.(`[@alemonjs/onebot][exit] 进程退出,code=${code}`);
|
|
370
|
-
});
|
|
371
|
-
process.on('message', msg => {
|
|
372
|
-
try {
|
|
373
|
-
const data = typeof msg === 'string' ? JSON.parse(msg) : msg;
|
|
374
|
-
if (data?.type === 'start') {
|
|
375
|
-
main();
|
|
376
|
-
}
|
|
377
|
-
else if (data?.type === 'stop') {
|
|
378
|
-
process.exit(0);
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
catch { }
|
|
382
|
-
});
|
|
383
|
-
if (process.send) {
|
|
384
|
-
process.send(JSON.stringify({ type: 'ready' }));
|
|
385
|
-
}
|
|
386
|
-
};
|
|
387
|
-
mainProcess();
|
|
397
|
+
var index = definePlatform({ main });
|
|
388
398
|
|
|
389
|
-
export {
|
|
399
|
+
export { index as default, platform };
|
package/lib/sdk/api.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import WebSocket from 'ws';
|
|
2
2
|
export declare const consume: (parsedMessage: any) => void;
|
|
3
3
|
export declare class OneBotAPI {
|
|
4
|
-
|
|
4
|
+
__ws: WebSocket | null;
|
|
5
|
+
send(options: {
|
|
6
|
+
[key: string]: any;
|
|
7
|
+
}): Promise<any>;
|
|
5
8
|
sendPrivateMessage(options: {
|
|
6
9
|
user_id: number;
|
|
7
10
|
message: any[];
|
package/lib/sdk/api.js
CHANGED
|
@@ -36,372 +36,378 @@ const consume = (parsedMessage) => {
|
|
|
36
36
|
resolve(parsedMessage?.data);
|
|
37
37
|
};
|
|
38
38
|
class OneBotAPI {
|
|
39
|
-
|
|
39
|
+
__ws = null;
|
|
40
|
+
send(options) {
|
|
41
|
+
if (!this.__ws) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
return send(this.__ws, options);
|
|
45
|
+
}
|
|
40
46
|
sendPrivateMessage(options) {
|
|
41
|
-
if (!this.
|
|
47
|
+
if (!this.__ws) {
|
|
42
48
|
return;
|
|
43
49
|
}
|
|
44
|
-
return send(this.
|
|
50
|
+
return send(this.__ws, {
|
|
45
51
|
action: 'send_private_msg',
|
|
46
52
|
params: options
|
|
47
53
|
});
|
|
48
54
|
}
|
|
49
55
|
sendGroupMessage(options) {
|
|
50
|
-
if (!this.
|
|
56
|
+
if (!this.__ws) {
|
|
51
57
|
return;
|
|
52
58
|
}
|
|
53
|
-
return send(this.
|
|
59
|
+
return send(this.__ws, {
|
|
54
60
|
action: 'send_group_msg',
|
|
55
61
|
params: options
|
|
56
62
|
});
|
|
57
63
|
}
|
|
58
64
|
sendMessage(options) {
|
|
59
|
-
if (!this.
|
|
65
|
+
if (!this.__ws) {
|
|
60
66
|
return;
|
|
61
67
|
}
|
|
62
|
-
return send(this.
|
|
68
|
+
return send(this.__ws, {
|
|
63
69
|
action: 'send_msg',
|
|
64
70
|
params: options
|
|
65
71
|
});
|
|
66
72
|
}
|
|
67
73
|
deleteMsg(options) {
|
|
68
|
-
if (!this.
|
|
74
|
+
if (!this.__ws) {
|
|
69
75
|
return;
|
|
70
76
|
}
|
|
71
|
-
return send(this.
|
|
77
|
+
return send(this.__ws, {
|
|
72
78
|
action: 'delete_msg',
|
|
73
79
|
params: options
|
|
74
80
|
});
|
|
75
81
|
}
|
|
76
82
|
getMsg(options) {
|
|
77
|
-
if (!this.
|
|
83
|
+
if (!this.__ws) {
|
|
78
84
|
return;
|
|
79
85
|
}
|
|
80
|
-
return send(this.
|
|
86
|
+
return send(this.__ws, {
|
|
81
87
|
action: 'get_msg',
|
|
82
88
|
params: options
|
|
83
89
|
});
|
|
84
90
|
}
|
|
85
91
|
getForwardMsg(options) {
|
|
86
|
-
if (!this.
|
|
92
|
+
if (!this.__ws) {
|
|
87
93
|
return;
|
|
88
94
|
}
|
|
89
|
-
return send(this.
|
|
95
|
+
return send(this.__ws, {
|
|
90
96
|
action: 'get_forward_msg',
|
|
91
97
|
params: options
|
|
92
98
|
});
|
|
93
99
|
}
|
|
94
100
|
sendLike(options) {
|
|
95
|
-
if (!this.
|
|
101
|
+
if (!this.__ws) {
|
|
96
102
|
return;
|
|
97
103
|
}
|
|
98
|
-
return send(this.
|
|
104
|
+
return send(this.__ws, {
|
|
99
105
|
action: 'send_like',
|
|
100
106
|
params: options
|
|
101
107
|
});
|
|
102
108
|
}
|
|
103
109
|
setGroupKick(options) {
|
|
104
|
-
if (!this.
|
|
110
|
+
if (!this.__ws) {
|
|
105
111
|
return;
|
|
106
112
|
}
|
|
107
|
-
return send(this.
|
|
113
|
+
return send(this.__ws, {
|
|
108
114
|
action: 'set_group_kick',
|
|
109
115
|
params: options
|
|
110
116
|
});
|
|
111
117
|
}
|
|
112
118
|
setGroupBan(options) {
|
|
113
|
-
if (!this.
|
|
119
|
+
if (!this.__ws) {
|
|
114
120
|
return;
|
|
115
121
|
}
|
|
116
|
-
return send(this.
|
|
122
|
+
return send(this.__ws, {
|
|
117
123
|
action: 'set_group_ban',
|
|
118
124
|
params: options
|
|
119
125
|
});
|
|
120
126
|
}
|
|
121
127
|
setGroupAnonymousBan(options) {
|
|
122
|
-
if (!this.
|
|
128
|
+
if (!this.__ws) {
|
|
123
129
|
return;
|
|
124
130
|
}
|
|
125
|
-
return send(this.
|
|
131
|
+
return send(this.__ws, {
|
|
126
132
|
action: 'set_group_anonymous_ban',
|
|
127
133
|
params: options
|
|
128
134
|
});
|
|
129
135
|
}
|
|
130
136
|
setGroupWholeBan(options) {
|
|
131
|
-
if (!this.
|
|
137
|
+
if (!this.__ws) {
|
|
132
138
|
return;
|
|
133
139
|
}
|
|
134
|
-
return send(this.
|
|
140
|
+
return send(this.__ws, {
|
|
135
141
|
action: 'set_group_whole_ban',
|
|
136
142
|
params: options
|
|
137
143
|
});
|
|
138
144
|
}
|
|
139
145
|
setGroupAdmin(options) {
|
|
140
|
-
if (!this.
|
|
146
|
+
if (!this.__ws) {
|
|
141
147
|
return;
|
|
142
148
|
}
|
|
143
|
-
return send(this.
|
|
149
|
+
return send(this.__ws, {
|
|
144
150
|
action: 'set_group_admin',
|
|
145
151
|
params: options
|
|
146
152
|
});
|
|
147
153
|
}
|
|
148
154
|
setGroupAnonymous(options) {
|
|
149
|
-
if (!this.
|
|
155
|
+
if (!this.__ws) {
|
|
150
156
|
return;
|
|
151
157
|
}
|
|
152
|
-
return send(this.
|
|
158
|
+
return send(this.__ws, {
|
|
153
159
|
action: 'set_group_anonymous',
|
|
154
160
|
params: options
|
|
155
161
|
});
|
|
156
162
|
}
|
|
157
163
|
setGroupCard(options) {
|
|
158
|
-
if (!this.
|
|
164
|
+
if (!this.__ws) {
|
|
159
165
|
return;
|
|
160
166
|
}
|
|
161
|
-
return send(this.
|
|
167
|
+
return send(this.__ws, {
|
|
162
168
|
action: 'set_group_card',
|
|
163
169
|
params: options
|
|
164
170
|
});
|
|
165
171
|
}
|
|
166
172
|
setGroupName(options) {
|
|
167
|
-
if (!this.
|
|
173
|
+
if (!this.__ws) {
|
|
168
174
|
return;
|
|
169
175
|
}
|
|
170
|
-
return send(this.
|
|
176
|
+
return send(this.__ws, {
|
|
171
177
|
action: 'set_group_name',
|
|
172
178
|
params: options
|
|
173
179
|
});
|
|
174
180
|
}
|
|
175
181
|
setGroupLeave(options) {
|
|
176
|
-
if (!this.
|
|
182
|
+
if (!this.__ws) {
|
|
177
183
|
return;
|
|
178
184
|
}
|
|
179
|
-
return send(this.
|
|
185
|
+
return send(this.__ws, {
|
|
180
186
|
action: 'set_group_leave',
|
|
181
187
|
params: options
|
|
182
188
|
});
|
|
183
189
|
}
|
|
184
190
|
setGroupSpecialTitle(options) {
|
|
185
|
-
if (!this.
|
|
191
|
+
if (!this.__ws) {
|
|
186
192
|
return;
|
|
187
193
|
}
|
|
188
|
-
return send(this.
|
|
194
|
+
return send(this.__ws, {
|
|
189
195
|
action: 'set_group_special_title',
|
|
190
196
|
params: options
|
|
191
197
|
});
|
|
192
198
|
}
|
|
193
199
|
setFriendAddRequest(options) {
|
|
194
|
-
if (!this.
|
|
200
|
+
if (!this.__ws) {
|
|
195
201
|
return;
|
|
196
202
|
}
|
|
197
|
-
return send(this.
|
|
203
|
+
return send(this.__ws, {
|
|
198
204
|
action: 'set_friend_add_request',
|
|
199
205
|
params: options
|
|
200
206
|
});
|
|
201
207
|
}
|
|
202
208
|
setGroupAddRequest(options) {
|
|
203
|
-
if (!this.
|
|
209
|
+
if (!this.__ws) {
|
|
204
210
|
return;
|
|
205
211
|
}
|
|
206
|
-
return send(this.
|
|
212
|
+
return send(this.__ws, {
|
|
207
213
|
action: 'set_group_add_request',
|
|
208
214
|
params: options
|
|
209
215
|
});
|
|
210
216
|
}
|
|
211
217
|
getLoginInfo() {
|
|
212
|
-
if (!this.
|
|
218
|
+
if (!this.__ws) {
|
|
213
219
|
return;
|
|
214
220
|
}
|
|
215
|
-
return send(this.
|
|
221
|
+
return send(this.__ws, {
|
|
216
222
|
action: 'get_login_info',
|
|
217
223
|
params: {}
|
|
218
224
|
});
|
|
219
225
|
}
|
|
220
226
|
getStrangerInfo(options) {
|
|
221
|
-
if (!this.
|
|
227
|
+
if (!this.__ws) {
|
|
222
228
|
return;
|
|
223
229
|
}
|
|
224
|
-
return send(this.
|
|
230
|
+
return send(this.__ws, {
|
|
225
231
|
action: 'get_stranger_info',
|
|
226
232
|
params: options
|
|
227
233
|
});
|
|
228
234
|
}
|
|
229
235
|
getFriendList() {
|
|
230
|
-
if (!this.
|
|
236
|
+
if (!this.__ws) {
|
|
231
237
|
return;
|
|
232
238
|
}
|
|
233
|
-
return send(this.
|
|
239
|
+
return send(this.__ws, {
|
|
234
240
|
action: 'get_friend_list',
|
|
235
241
|
params: {}
|
|
236
242
|
});
|
|
237
243
|
}
|
|
238
244
|
getGroupInfo(params) {
|
|
239
|
-
if (!this.
|
|
245
|
+
if (!this.__ws) {
|
|
240
246
|
return;
|
|
241
247
|
}
|
|
242
|
-
return send(this.
|
|
248
|
+
return send(this.__ws, {
|
|
243
249
|
action: 'get_group_info',
|
|
244
250
|
params: params
|
|
245
251
|
});
|
|
246
252
|
}
|
|
247
253
|
getGroupList() {
|
|
248
|
-
if (!this.
|
|
254
|
+
if (!this.__ws) {
|
|
249
255
|
return;
|
|
250
256
|
}
|
|
251
|
-
return send(this.
|
|
257
|
+
return send(this.__ws, {
|
|
252
258
|
action: 'get_group_list',
|
|
253
259
|
params: {}
|
|
254
260
|
});
|
|
255
261
|
}
|
|
256
262
|
getGroupMemberInfo(options) {
|
|
257
|
-
if (!this.
|
|
263
|
+
if (!this.__ws) {
|
|
258
264
|
return;
|
|
259
265
|
}
|
|
260
|
-
return send(this.
|
|
266
|
+
return send(this.__ws, {
|
|
261
267
|
action: 'get_group_member_info',
|
|
262
268
|
params: options
|
|
263
269
|
});
|
|
264
270
|
}
|
|
265
271
|
getGroupMemberList(options) {
|
|
266
|
-
if (!this.
|
|
272
|
+
if (!this.__ws) {
|
|
267
273
|
return;
|
|
268
274
|
}
|
|
269
|
-
return send(this.
|
|
275
|
+
return send(this.__ws, {
|
|
270
276
|
action: 'get_group_member_list',
|
|
271
277
|
params: options
|
|
272
278
|
});
|
|
273
279
|
}
|
|
274
280
|
getGroupHonorInfo(options) {
|
|
275
|
-
if (!this.
|
|
281
|
+
if (!this.__ws) {
|
|
276
282
|
return;
|
|
277
283
|
}
|
|
278
|
-
return send(this.
|
|
284
|
+
return send(this.__ws, {
|
|
279
285
|
action: 'get_group_honor_info',
|
|
280
286
|
params: options
|
|
281
287
|
});
|
|
282
288
|
}
|
|
283
289
|
getCookies() {
|
|
284
|
-
if (!this.
|
|
290
|
+
if (!this.__ws) {
|
|
285
291
|
return;
|
|
286
292
|
}
|
|
287
|
-
return send(this.
|
|
293
|
+
return send(this.__ws, {
|
|
288
294
|
action: 'get_cookies',
|
|
289
295
|
params: {}
|
|
290
296
|
});
|
|
291
297
|
}
|
|
292
298
|
getCsrfToken() {
|
|
293
|
-
if (!this.
|
|
299
|
+
if (!this.__ws) {
|
|
294
300
|
return;
|
|
295
301
|
}
|
|
296
|
-
return send(this.
|
|
302
|
+
return send(this.__ws, {
|
|
297
303
|
action: 'get_csrf_token',
|
|
298
304
|
params: {}
|
|
299
305
|
});
|
|
300
306
|
}
|
|
301
307
|
getCredentials() {
|
|
302
|
-
if (!this.
|
|
308
|
+
if (!this.__ws) {
|
|
303
309
|
return;
|
|
304
310
|
}
|
|
305
|
-
return send(this.
|
|
311
|
+
return send(this.__ws, {
|
|
306
312
|
action: 'get_credentials',
|
|
307
313
|
params: {}
|
|
308
314
|
});
|
|
309
315
|
}
|
|
310
316
|
getRecord(options) {
|
|
311
|
-
if (!this.
|
|
317
|
+
if (!this.__ws) {
|
|
312
318
|
return;
|
|
313
319
|
}
|
|
314
|
-
return send(this.
|
|
320
|
+
return send(this.__ws, {
|
|
315
321
|
action: 'get_record',
|
|
316
322
|
params: options
|
|
317
323
|
});
|
|
318
324
|
}
|
|
319
325
|
getImage(options) {
|
|
320
|
-
if (!this.
|
|
326
|
+
if (!this.__ws) {
|
|
321
327
|
return;
|
|
322
328
|
}
|
|
323
|
-
return send(this.
|
|
329
|
+
return send(this.__ws, {
|
|
324
330
|
action: 'get_image',
|
|
325
331
|
params: options
|
|
326
332
|
});
|
|
327
333
|
}
|
|
328
334
|
canSendImage() {
|
|
329
|
-
if (!this.
|
|
335
|
+
if (!this.__ws) {
|
|
330
336
|
return;
|
|
331
337
|
}
|
|
332
|
-
return send(this.
|
|
338
|
+
return send(this.__ws, {
|
|
333
339
|
action: 'can_send_image',
|
|
334
340
|
params: {}
|
|
335
341
|
});
|
|
336
342
|
}
|
|
337
343
|
canSendRecord() {
|
|
338
|
-
if (!this.
|
|
344
|
+
if (!this.__ws) {
|
|
339
345
|
return;
|
|
340
346
|
}
|
|
341
|
-
return send(this.
|
|
347
|
+
return send(this.__ws, {
|
|
342
348
|
action: 'can_send_record',
|
|
343
349
|
params: {}
|
|
344
350
|
});
|
|
345
351
|
}
|
|
346
352
|
getStatus() {
|
|
347
|
-
if (!this.
|
|
353
|
+
if (!this.__ws) {
|
|
348
354
|
return;
|
|
349
355
|
}
|
|
350
|
-
return send(this.
|
|
356
|
+
return send(this.__ws, {
|
|
351
357
|
action: 'get_status',
|
|
352
358
|
params: {}
|
|
353
359
|
});
|
|
354
360
|
}
|
|
355
361
|
getVersionInfo() {
|
|
356
|
-
if (!this.
|
|
362
|
+
if (!this.__ws) {
|
|
357
363
|
return;
|
|
358
364
|
}
|
|
359
|
-
return send(this.
|
|
365
|
+
return send(this.__ws, {
|
|
360
366
|
action: 'get_version_info',
|
|
361
367
|
params: {}
|
|
362
368
|
});
|
|
363
369
|
}
|
|
364
370
|
setRestart() {
|
|
365
|
-
if (!this.
|
|
371
|
+
if (!this.__ws) {
|
|
366
372
|
return;
|
|
367
373
|
}
|
|
368
|
-
return send(this.
|
|
374
|
+
return send(this.__ws, {
|
|
369
375
|
action: 'set_restart',
|
|
370
376
|
params: {}
|
|
371
377
|
});
|
|
372
378
|
}
|
|
373
379
|
cleanCache() {
|
|
374
|
-
if (!this.
|
|
380
|
+
if (!this.__ws) {
|
|
375
381
|
return;
|
|
376
382
|
}
|
|
377
|
-
return send(this.
|
|
383
|
+
return send(this.__ws, {
|
|
378
384
|
action: 'clean_cache',
|
|
379
385
|
params: {}
|
|
380
386
|
});
|
|
381
387
|
}
|
|
382
388
|
uploadPrivateFile(options) {
|
|
383
|
-
if (!this.
|
|
389
|
+
if (!this.__ws) {
|
|
384
390
|
return;
|
|
385
391
|
}
|
|
386
|
-
return send(this.
|
|
392
|
+
return send(this.__ws, {
|
|
387
393
|
action: 'upload_private_file',
|
|
388
394
|
params: options
|
|
389
395
|
});
|
|
390
396
|
}
|
|
391
397
|
uploadGroupFile(options) {
|
|
392
|
-
if (!this.
|
|
398
|
+
if (!this.__ws) {
|
|
393
399
|
return;
|
|
394
400
|
}
|
|
395
|
-
return send(this.
|
|
401
|
+
return send(this.__ws, {
|
|
396
402
|
action: 'upload_group_file',
|
|
397
403
|
params: options
|
|
398
404
|
});
|
|
399
405
|
}
|
|
400
406
|
sendPrivateForward(options) {
|
|
401
|
-
if (!this.
|
|
407
|
+
if (!this.__ws) {
|
|
402
408
|
return;
|
|
403
409
|
}
|
|
404
|
-
return send(this.
|
|
410
|
+
return send(this.__ws, {
|
|
405
411
|
action: 'send_private_forward_msg',
|
|
406
412
|
params: {
|
|
407
413
|
user_id: 80000000,
|
|
@@ -412,10 +418,10 @@ class OneBotAPI {
|
|
|
412
418
|
});
|
|
413
419
|
}
|
|
414
420
|
sendGroupForward(options) {
|
|
415
|
-
if (!this.
|
|
421
|
+
if (!this.__ws) {
|
|
416
422
|
return;
|
|
417
423
|
}
|
|
418
|
-
return send(this.
|
|
424
|
+
return send(this.__ws, {
|
|
419
425
|
action: 'send_group_forward_msg',
|
|
420
426
|
params: {
|
|
421
427
|
user_id: 80000000,
|
package/lib/sdk/config.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
type PromiseHandlers = {
|
|
2
2
|
resolve: (value: any) => void;
|
|
3
3
|
reject: (reason?: any) => void;
|
|
4
|
-
}
|
|
4
|
+
};
|
|
5
|
+
export declare const actionResolves: Map<string, PromiseHandlers>;
|
|
5
6
|
export declare const actionTimeouts: Map<string, NodeJS.Timeout>;
|
|
6
7
|
export declare const generateUniqueId: () => string;
|
|
7
8
|
export declare const timeoutTime: number;
|
|
9
|
+
export {};
|
package/lib/sdk/types.d.ts
CHANGED
|
@@ -73,14 +73,14 @@ export interface DIRECT_MESSAGE_TYPE {
|
|
|
73
73
|
group_id: number;
|
|
74
74
|
temp_source: number;
|
|
75
75
|
}
|
|
76
|
-
export interface
|
|
76
|
+
export interface META_EVENT_LIFECYCLE {
|
|
77
77
|
time: number;
|
|
78
78
|
self_id: number;
|
|
79
79
|
post_type: 'meta_event';
|
|
80
80
|
meta_event_type: 'lifecycle';
|
|
81
81
|
sub_type: 'connect';
|
|
82
82
|
}
|
|
83
|
-
export interface
|
|
83
|
+
export interface META_EVENT_HEARTBEAT {
|
|
84
84
|
time: number;
|
|
85
85
|
self_id: number;
|
|
86
86
|
post_type: 'meta_event';
|
package/lib/sdk/typing.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { MESSAGES_TYPE, DIRECT_MESSAGE_TYPE,
|
|
1
|
+
import { MESSAGES_TYPE, DIRECT_MESSAGE_TYPE, META_EVENT_LIFECYCLE, META_EVENT_HEARTBEAT } from './types';
|
|
2
2
|
export type OneBotEventMap = {
|
|
3
3
|
DIRECT_MESSAGE: DIRECT_MESSAGE_TYPE;
|
|
4
4
|
MESSAGES: MESSAGES_TYPE;
|
|
5
|
-
META:
|
|
5
|
+
META: META_EVENT_LIFECYCLE | META_EVENT_HEARTBEAT;
|
|
6
6
|
REQUEST_ADD_FRIEND: any;
|
|
7
7
|
REQUEST_ADD_GROUP: any;
|
|
8
8
|
NOTICE_GROUP_MEMBER_INCREASE: any;
|
package/lib/sdk/wss.js
CHANGED
|
@@ -105,24 +105,24 @@ class OneBotClient extends OneBotAPI {
|
|
|
105
105
|
this.connect();
|
|
106
106
|
}, curTime);
|
|
107
107
|
};
|
|
108
|
-
if (!this.
|
|
108
|
+
if (!this.__ws) {
|
|
109
109
|
if (reverse_enable) {
|
|
110
110
|
const server = new WebSocketServer({ port: reverse_port ?? 17158 });
|
|
111
111
|
server.on('connection', ws => {
|
|
112
|
-
this.
|
|
113
|
-
this.
|
|
114
|
-
this.
|
|
112
|
+
this.__ws = ws;
|
|
113
|
+
this.__ws.on('message', onMessage);
|
|
114
|
+
this.__ws.on('close', onClose);
|
|
115
115
|
logger.info(`[OneBot] connected: ws://127.0.0.1:${reverse_port}`);
|
|
116
116
|
});
|
|
117
117
|
}
|
|
118
118
|
else {
|
|
119
|
-
this.
|
|
120
|
-
this.
|
|
119
|
+
this.__ws = new WebSocket(url, c);
|
|
120
|
+
this.__ws.on('open', () => {
|
|
121
121
|
logger.info(`[OneBot] connected: ${url}`);
|
|
122
122
|
this.#count = 0;
|
|
123
123
|
});
|
|
124
|
-
this.
|
|
125
|
-
this.
|
|
124
|
+
this.__ws.on('message', onMessage);
|
|
125
|
+
this.__ws.on('close', onClose);
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
128
|
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alemonjs/onebot",
|
|
3
|
-
"version": "2.1.0-alpha.
|
|
3
|
+
"version": "2.1.0-alpha.16",
|
|
4
4
|
"description": "oneBot v11",
|
|
5
5
|
"author": "lemonade",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
|
-
"types": "lib",
|
|
10
9
|
"scripts": {
|
|
11
10
|
"build": "lvy build"
|
|
12
11
|
},
|
|
@@ -26,7 +25,7 @@
|
|
|
26
25
|
"ws": "^8.18.1"
|
|
27
26
|
},
|
|
28
27
|
"peerDependencies": {
|
|
29
|
-
"alemonjs": "^2.1.
|
|
28
|
+
"alemonjs": "^2.1.14"
|
|
30
29
|
},
|
|
31
30
|
"alemonjs": {
|
|
32
31
|
"desktop": {
|