onebots 0.1.1 → 0.1.2

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.
@@ -68,7 +68,7 @@ export declare namespace V11 {
68
68
  function error(error: string, retcode?: number): Result<any>;
69
69
  const defaultConfig: Config;
70
70
  function genMetaEvent(uin: number, type: string): {
71
- self_id: number;
71
+ self_id: string;
72
72
  time: number;
73
73
  post_type: string;
74
74
  meta_event_type: string;
@@ -28,10 +28,10 @@ class V11 extends events_1.EventEmitter {
28
28
  this.queue_running = false;
29
29
  this.wsr = new Set();
30
30
  this.action = new action_1.Action();
31
- this.logger = this.oneBot.app.getLogger(this.client.uin, this.version);
31
+ this.logger = this.oneBot.app.getLogger(this.oneBot.uin, this.version);
32
32
  }
33
33
  start(path) {
34
- this.path = `/${this.client.uin}`;
34
+ this.path = `/${this.oneBot.uin}`;
35
35
  if (path)
36
36
  this.path += path;
37
37
  if (this.config.use_http)
@@ -61,7 +61,7 @@ class V11 extends events_1.EventEmitter {
61
61
  if (this.config.heartbeat) {
62
62
  this.heartbeat = setInterval(() => {
63
63
  this.dispatch({
64
- self_id: this.client.uin,
64
+ self_id: this.oneBot.uin + '',
65
65
  status: {
66
66
  online: this.client.status === icqq_1.OnlineStatus.Online,
67
67
  good: this.oneBot.status === onebot_1.OneBotStatus.Good
@@ -87,7 +87,7 @@ class V11 extends events_1.EventEmitter {
87
87
  headers: {
88
88
  "Content-Type": "application/json",
89
89
  "Content-Length": Buffer.byteLength(serialized),
90
- "X-Self-ID": String(this.client.uin),
90
+ "X-Self-ID": String(this.oneBot.uin),
91
91
  "User-Agent": "OneBot",
92
92
  },
93
93
  };
@@ -296,8 +296,8 @@ class V11 extends events_1.EventEmitter {
296
296
  }));
297
297
  }
298
298
  });
299
- ws.send(JSON.stringify(V11.genMetaEvent(this.client.uin, "connect")));
300
- ws.send(JSON.stringify(V11.genMetaEvent(this.client.uin, "enable")));
299
+ ws.send(JSON.stringify(V11.genMetaEvent(this.oneBot.uin, "connect")));
300
+ ws.send(JSON.stringify(V11.genMetaEvent(this.oneBot.uin, "enable")));
301
301
  }
302
302
  /**
303
303
  * 创建反向ws
@@ -305,7 +305,7 @@ class V11 extends events_1.EventEmitter {
305
305
  _createWsr(url) {
306
306
  const timestmap = Date.now();
307
307
  const headers = {
308
- "X-Self-ID": String(this.client.uin),
308
+ "X-Self-ID": String(this.oneBot.uin),
309
309
  "X-Client-Role": "Universal",
310
310
  "User-Agent": "OneBot",
311
311
  };
@@ -497,7 +497,7 @@ exports.V11 = V11;
497
497
  };
498
498
  function genMetaEvent(uin, type) {
499
499
  return {
500
- self_id: uin,
500
+ self_id: uin + '',
501
501
  time: Math.floor(Date.now() / 1000),
502
502
  post_type: "meta_event",
503
503
  meta_event_type: "lifecycle",
@@ -32,7 +32,7 @@ export declare class V12 extends EventEmitter implements OneBot.Base {
32
32
  private startWsReverse;
33
33
  stop(force?: boolean): Promise<void>;
34
34
  format<E extends keyof V12.BotEventMap>(event: E, ...args: [V12.BotEventMap[E]]): {
35
- self_id: number;
35
+ self_id: string;
36
36
  time: number;
37
37
  detail_type: E;
38
38
  type: string;
@@ -183,7 +183,7 @@ export declare namespace V12 {
183
183
  function success<T extends any>(data: T, retcode?: Result<T>['retcode'], echo?: string): Result<T>;
184
184
  function error(message: string, retcode?: Result<null>['retcode'], echo?: string): Result<null>;
185
185
  function formatPayload<K extends keyof BotEventMap>(uin: number, type: K, data: Omit<BotEventMap[K], K>): {
186
- self_id: number;
186
+ self_id: string;
187
187
  time: number;
188
188
  detail_type: K;
189
189
  type: string;
@@ -26,11 +26,11 @@ class V12 extends events_1.EventEmitter {
26
26
  this.version = 'V12';
27
27
  this.timestamp = Date.now();
28
28
  this.wsr = new Set();
29
- this.db = new db_1.Db((0, path_1.join)(app_1.App.configDir, 'data', this.client.uin + '.json'));
29
+ this.db = new db_1.Db((0, path_1.join)(app_1.App.configDir, 'data', this.oneBot.uin + '.json'));
30
30
  if (!this.history)
31
31
  this.history = [];
32
32
  this.action = new action_1.Action();
33
- this.logger = this.oneBot.app.getLogger(this.client.uin, this.version);
33
+ this.logger = this.oneBot.app.getLogger(this.oneBot.uin, this.version);
34
34
  }
35
35
  get history() {
36
36
  return this.db.get('eventBuffer');
@@ -39,7 +39,7 @@ class V12 extends events_1.EventEmitter {
39
39
  this.db.set('eventBuffer', value);
40
40
  }
41
41
  start(path) {
42
- this.path = `/${this.client.uin}`;
42
+ this.path = `/${this.oneBot.uin}`;
43
43
  if (path)
44
44
  this.path += path;
45
45
  if (this.config.use_http) {
@@ -90,7 +90,7 @@ class V12 extends events_1.EventEmitter {
90
90
  });
91
91
  if (this.config.heartbeat) {
92
92
  this.heartbeat = setInterval(() => {
93
- this.dispatch(V12.formatPayload(this.client.uin, 'heartbeat', {
93
+ this.dispatch(V12.formatPayload(this.oneBot.uin, 'heartbeat', {
94
94
  detail_type: "heartbeat",
95
95
  interval: new Date().getTime() + this.config.heartbeat * 1000
96
96
  }));
@@ -313,7 +313,7 @@ class V12 extends events_1.EventEmitter {
313
313
  if (!data.detail_type)
314
314
  data.detail_type = data.message_type || data.notice_type || data.request_type || data.system_type;
315
315
  data.message = data.type === 'message' ? V12.toSegment(data.message) : data.message;
316
- return V12.formatPayload(this.client.uin, event, data);
316
+ return V12.formatPayload(this.oneBot.uin, event, data);
317
317
  }
318
318
  dispatch(data) {
319
319
  const payload = {
@@ -323,7 +323,7 @@ class V12 extends events_1.EventEmitter {
323
323
  platform: 'qq',
324
324
  self: {
325
325
  platform: 'qq',
326
- user_id: `${this.client.uin}`
326
+ user_id: `${this.oneBot.uin}`
327
327
  },
328
328
  ...(0, utils_1.transformObj)(data, (key, value) => {
329
329
  if (!['user_id', 'group_id', 'discuss_id', 'member_id', 'channel_id', 'guild_id'].includes(key))
@@ -482,7 +482,7 @@ class V12 extends events_1.EventEmitter {
482
482
  _createWsr(url, config) {
483
483
  const timestmap = Date.now();
484
484
  const headers = {
485
- "X-Self-ID": String(this.client.uin),
485
+ "X-Self-ID": String(this.oneBot.uin),
486
486
  "X-Client-Role": "Universal",
487
487
  "User-Agent": "OneBot/12 (qq) Node-onebots/0.0.15",
488
488
  "Sec-WebSocket-Protocol": "12.onebots.v0.0.15"
@@ -558,8 +558,8 @@ class V12 extends events_1.EventEmitter {
558
558
  }));
559
559
  }
560
560
  });
561
- this.dispatch(V12.formatPayload(this.client.uin, "connect", this.action.getVersion.apply(this)));
562
- this.dispatch(V12.formatPayload(this.client.uin, "status_update", this.action.getStatus.apply(this)));
561
+ this.dispatch(V12.formatPayload(this.oneBot.uin, "connect", this.action.getVersion.apply(this)));
562
+ this.dispatch(V12.formatPayload(this.oneBot.uin, "status_update", this.action.getStatus.apply(this)));
563
563
  }
564
564
  }
565
565
  exports.V12 = V12;
@@ -632,7 +632,7 @@ exports.V12 = V12;
632
632
  V12.error = error;
633
633
  function formatPayload(uin, type, data) {
634
634
  return {
635
- self_id: uin,
635
+ self_id: uin + '',
636
636
  time: Math.floor(Date.now() / 1000),
637
637
  detail_type: type,
638
638
  type: 'meta',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "onebots",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "基于icqq的多例oneBot实现",
5
5
  "engines": {
6
6
  "node": ">=16"