@alemonjs/onebot 2.1.0-alpha.13 → 2.1.0-alpha.14

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 CHANGED
@@ -7,13 +7,13 @@ const getOneBotConfig = () => {
7
7
  };
8
8
  const getMaster = (UserId) => {
9
9
  const config = getOneBotConfig();
10
- const master_key = config.master_key || [];
11
- const master_id = config.master_id || [];
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 = master_key.includes(UserKey) || master_id.includes(UserId);
16
+ const is = masterKey.includes(UserKey) || masterId.includes(UserId);
17
17
  return [is, UserKey];
18
18
  };
19
19
 
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
- ws: WebSocket | null;
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
- ws = null;
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.ws) {
47
+ if (!this.__ws) {
42
48
  return;
43
49
  }
44
- return send(this.ws, {
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.ws) {
56
+ if (!this.__ws) {
51
57
  return;
52
58
  }
53
- return send(this.ws, {
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.ws) {
65
+ if (!this.__ws) {
60
66
  return;
61
67
  }
62
- return send(this.ws, {
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.ws) {
74
+ if (!this.__ws) {
69
75
  return;
70
76
  }
71
- return send(this.ws, {
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.ws) {
83
+ if (!this.__ws) {
78
84
  return;
79
85
  }
80
- return send(this.ws, {
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.ws) {
92
+ if (!this.__ws) {
87
93
  return;
88
94
  }
89
- return send(this.ws, {
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.ws) {
101
+ if (!this.__ws) {
96
102
  return;
97
103
  }
98
- return send(this.ws, {
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.ws) {
110
+ if (!this.__ws) {
105
111
  return;
106
112
  }
107
- return send(this.ws, {
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.ws) {
119
+ if (!this.__ws) {
114
120
  return;
115
121
  }
116
- return send(this.ws, {
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.ws) {
128
+ if (!this.__ws) {
123
129
  return;
124
130
  }
125
- return send(this.ws, {
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.ws) {
137
+ if (!this.__ws) {
132
138
  return;
133
139
  }
134
- return send(this.ws, {
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.ws) {
146
+ if (!this.__ws) {
141
147
  return;
142
148
  }
143
- return send(this.ws, {
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.ws) {
155
+ if (!this.__ws) {
150
156
  return;
151
157
  }
152
- return send(this.ws, {
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.ws) {
164
+ if (!this.__ws) {
159
165
  return;
160
166
  }
161
- return send(this.ws, {
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.ws) {
173
+ if (!this.__ws) {
168
174
  return;
169
175
  }
170
- return send(this.ws, {
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.ws) {
182
+ if (!this.__ws) {
177
183
  return;
178
184
  }
179
- return send(this.ws, {
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.ws) {
191
+ if (!this.__ws) {
186
192
  return;
187
193
  }
188
- return send(this.ws, {
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.ws) {
200
+ if (!this.__ws) {
195
201
  return;
196
202
  }
197
- return send(this.ws, {
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.ws) {
209
+ if (!this.__ws) {
204
210
  return;
205
211
  }
206
- return send(this.ws, {
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.ws) {
218
+ if (!this.__ws) {
213
219
  return;
214
220
  }
215
- return send(this.ws, {
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.ws) {
227
+ if (!this.__ws) {
222
228
  return;
223
229
  }
224
- return send(this.ws, {
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.ws) {
236
+ if (!this.__ws) {
231
237
  return;
232
238
  }
233
- return send(this.ws, {
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.ws) {
245
+ if (!this.__ws) {
240
246
  return;
241
247
  }
242
- return send(this.ws, {
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.ws) {
254
+ if (!this.__ws) {
249
255
  return;
250
256
  }
251
- return send(this.ws, {
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.ws) {
263
+ if (!this.__ws) {
258
264
  return;
259
265
  }
260
- return send(this.ws, {
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.ws) {
272
+ if (!this.__ws) {
267
273
  return;
268
274
  }
269
- return send(this.ws, {
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.ws) {
281
+ if (!this.__ws) {
276
282
  return;
277
283
  }
278
- return send(this.ws, {
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.ws) {
290
+ if (!this.__ws) {
285
291
  return;
286
292
  }
287
- return send(this.ws, {
293
+ return send(this.__ws, {
288
294
  action: 'get_cookies',
289
295
  params: {}
290
296
  });
291
297
  }
292
298
  getCsrfToken() {
293
- if (!this.ws) {
299
+ if (!this.__ws) {
294
300
  return;
295
301
  }
296
- return send(this.ws, {
302
+ return send(this.__ws, {
297
303
  action: 'get_csrf_token',
298
304
  params: {}
299
305
  });
300
306
  }
301
307
  getCredentials() {
302
- if (!this.ws) {
308
+ if (!this.__ws) {
303
309
  return;
304
310
  }
305
- return send(this.ws, {
311
+ return send(this.__ws, {
306
312
  action: 'get_credentials',
307
313
  params: {}
308
314
  });
309
315
  }
310
316
  getRecord(options) {
311
- if (!this.ws) {
317
+ if (!this.__ws) {
312
318
  return;
313
319
  }
314
- return send(this.ws, {
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.ws) {
326
+ if (!this.__ws) {
321
327
  return;
322
328
  }
323
- return send(this.ws, {
329
+ return send(this.__ws, {
324
330
  action: 'get_image',
325
331
  params: options
326
332
  });
327
333
  }
328
334
  canSendImage() {
329
- if (!this.ws) {
335
+ if (!this.__ws) {
330
336
  return;
331
337
  }
332
- return send(this.ws, {
338
+ return send(this.__ws, {
333
339
  action: 'can_send_image',
334
340
  params: {}
335
341
  });
336
342
  }
337
343
  canSendRecord() {
338
- if (!this.ws) {
344
+ if (!this.__ws) {
339
345
  return;
340
346
  }
341
- return send(this.ws, {
347
+ return send(this.__ws, {
342
348
  action: 'can_send_record',
343
349
  params: {}
344
350
  });
345
351
  }
346
352
  getStatus() {
347
- if (!this.ws) {
353
+ if (!this.__ws) {
348
354
  return;
349
355
  }
350
- return send(this.ws, {
356
+ return send(this.__ws, {
351
357
  action: 'get_status',
352
358
  params: {}
353
359
  });
354
360
  }
355
361
  getVersionInfo() {
356
- if (!this.ws) {
362
+ if (!this.__ws) {
357
363
  return;
358
364
  }
359
- return send(this.ws, {
365
+ return send(this.__ws, {
360
366
  action: 'get_version_info',
361
367
  params: {}
362
368
  });
363
369
  }
364
370
  setRestart() {
365
- if (!this.ws) {
371
+ if (!this.__ws) {
366
372
  return;
367
373
  }
368
- return send(this.ws, {
374
+ return send(this.__ws, {
369
375
  action: 'set_restart',
370
376
  params: {}
371
377
  });
372
378
  }
373
379
  cleanCache() {
374
- if (!this.ws) {
380
+ if (!this.__ws) {
375
381
  return;
376
382
  }
377
- return send(this.ws, {
383
+ return send(this.__ws, {
378
384
  action: 'clean_cache',
379
385
  params: {}
380
386
  });
381
387
  }
382
388
  uploadPrivateFile(options) {
383
- if (!this.ws) {
389
+ if (!this.__ws) {
384
390
  return;
385
391
  }
386
- return send(this.ws, {
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.ws) {
398
+ if (!this.__ws) {
393
399
  return;
394
400
  }
395
- return send(this.ws, {
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.ws) {
407
+ if (!this.__ws) {
402
408
  return;
403
409
  }
404
- return send(this.ws, {
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.ws) {
421
+ if (!this.__ws) {
416
422
  return;
417
423
  }
418
- return send(this.ws, {
424
+ return send(this.__ws, {
419
425
  action: 'send_group_forward_msg',
420
426
  params: {
421
427
  user_id: 80000000,
@@ -1,7 +1,9 @@
1
- export declare const actionResolves: Map<string, {
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 {};
@@ -73,14 +73,14 @@ export interface DIRECT_MESSAGE_TYPE {
73
73
  group_id: number;
74
74
  temp_source: number;
75
75
  }
76
- export interface meta_event_lifecycle {
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 meta_event_heartbeat {
83
+ export interface META_EVENT_HEARTBEAT {
84
84
  time: number;
85
85
  self_id: number;
86
86
  post_type: 'meta_event';
@@ -1,8 +1,8 @@
1
- import { MESSAGES_TYPE, DIRECT_MESSAGE_TYPE, meta_event_lifecycle, meta_event_heartbeat } from './types';
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: meta_event_lifecycle | meta_event_heartbeat;
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.ws) {
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.ws = ws;
113
- this.ws.on('message', onMessage);
114
- this.ws.on('close', onClose);
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.ws = new WebSocket(url, c);
120
- this.ws.on('open', () => {
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.ws.on('message', onMessage);
125
- this.ws.on('close', onClose);
124
+ this.__ws.on('message', onMessage);
125
+ this.__ws.on('close', onClose);
126
126
  }
127
127
  }
128
128
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alemonjs/onebot",
3
- "version": "2.1.0-alpha.13",
3
+ "version": "2.1.0-alpha.14",
4
4
  "description": "oneBot v11",
5
5
  "author": "lemonade",
6
6
  "license": "MIT",