onebots 0.0.7 → 0.0.9

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/onebot.d.ts CHANGED
@@ -18,9 +18,9 @@ export declare class OneBot<V extends OneBot.Version> extends EventEmitter {
18
18
  client: Client;
19
19
  instances: (V11 | V12)[];
20
20
  constructor(app: App, uin: number, config: MayBeArray<OneBotConfig>);
21
- start(): void;
21
+ start(): Promise<void>;
22
22
  startListen(): void;
23
- stop(): void;
23
+ stop(): Promise<void>;
24
24
  dispatch(data: any): void;
25
25
  }
26
26
  export declare enum OneBotStatus {
package/lib/onebot.js CHANGED
@@ -49,23 +49,23 @@ class OneBot extends events_1.EventEmitter {
49
49
  }
50
50
  });
51
51
  }
52
- start() {
52
+ async start() {
53
53
  this.startListen();
54
- this.client.login(this.password);
54
+ await this.client.login(this.password);
55
55
  }
56
56
  startListen() {
57
57
  this.client.on('system', this.dispatch.bind(this));
58
58
  this.client.on('notice', this.dispatch.bind(this));
59
59
  this.client.on('request', this.dispatch.bind(this));
60
60
  this.client.on('message', this.dispatch.bind(this));
61
- this.instances.forEach(instance => {
61
+ for (const instance of this.instances) {
62
62
  instance.start(this.instances.length > 1 ? '/' + instance.version : undefined);
63
- });
63
+ }
64
64
  }
65
- stop() {
66
- this.instances.forEach(instance => {
67
- instance.stop();
68
- });
65
+ async stop() {
66
+ for (const instance of this.instances) {
67
+ await instance.stop();
68
+ }
69
69
  this.client.off('system', this.dispatch.bind(this));
70
70
  this.client.off('notice', this.dispatch.bind(this));
71
71
  this.client.off('request', this.dispatch.bind(this));
@@ -61,5 +61,5 @@ export declare class CommonAction {
61
61
  submitSlider(this: V11, ticket: string): Promise<any>;
62
62
  login(this: V11, password?: string): any;
63
63
  submitSmsCode(this: V11, code: string): Promise<any>;
64
- sendSmsCode(this: V11): void;
64
+ sendSmsCode(this: V11): Promise<any>;
65
65
  }
@@ -109,10 +109,24 @@ class CommonAction {
109
109
  return this.action.callLogin.apply(this, ['login', password]);
110
110
  }
111
111
  async submitSmsCode(code) {
112
- return this.action.login.apply(this, ['submitSmsCode', code]);
112
+ return this.action.callLogin.apply(this, ['submitSmsCode', code]);
113
113
  }
114
114
  sendSmsCode() {
115
- return this.client.sendSmsCode();
115
+ return new Promise(resolve => {
116
+ const receiveResult = (e) => {
117
+ const callback = (data) => {
118
+ this.client.off('internal.verbose', receiveResult);
119
+ this.client.off('system.login.error', receiveResult);
120
+ resolve(data);
121
+ };
122
+ if ((typeof e === 'string' && e.includes('已发送')) || typeof e !== 'string') {
123
+ callback(e);
124
+ }
125
+ };
126
+ this.client.on('internal.verbose', receiveResult);
127
+ this.client.on('system.login.error', receiveResult);
128
+ this.client.sendSmsCode();
129
+ });
116
130
  }
117
131
  }
118
132
  exports.CommonAction = CommonAction;
@@ -32,7 +32,7 @@ export declare class V11 extends EventEmitter implements OneBot.Base {
32
32
  private startHttpReverse;
33
33
  private startWs;
34
34
  private startWsReverse;
35
- stop(): void;
35
+ stop(): Promise<void>;
36
36
  dispatch(data: any): void;
37
37
  private _httpRequestHandler;
38
38
  /**
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.V11 = void 0;
7
+ const oicq_1 = require("oicq");
7
8
  const action_1 = require("./action");
8
9
  const ws_1 = require("ws");
9
10
  const url_1 = require("url");
@@ -13,6 +14,7 @@ const onebot_1 = require("../../onebot");
13
14
  const http_1 = __importDefault(require("http"));
14
15
  const https_1 = __importDefault(require("https"));
15
16
  const events_1 = require("events");
17
+ const fs_1 = require("fs");
16
18
  class V11 extends events_1.EventEmitter {
17
19
  constructor(oneBot, client, config) {
18
20
  super();
@@ -161,8 +163,11 @@ class V11 extends events_1.EventEmitter {
161
163
  }
162
164
  });
163
165
  }
164
- stop() {
165
- this.client.logout();
166
+ async stop() {
167
+ if (this.client.status === oicq_1.OnlineStatus.Online) {
168
+ await this.client.logout();
169
+ }
170
+ (0, fs_1.unlinkSync)(this.client.dir);
166
171
  }
167
172
  dispatch(data) {
168
173
  if (!data.post_type)
@@ -28,6 +28,6 @@ export declare class CommonAction {
28
28
  submitSlider(this: V11, ticket: string): Promise<any>;
29
29
  login(this: V11, password?: string): any;
30
30
  submitSmsCode(this: V11, code: string): Promise<any>;
31
- sendSmsCode(this: V12): void;
31
+ sendSmsCode(this: V12): Promise<any>;
32
32
  getSupportedActions(this: V12): string[];
33
33
  }
@@ -70,10 +70,24 @@ class CommonAction {
70
70
  return this.action.callLogin.apply(this, ['login', password]);
71
71
  }
72
72
  async submitSmsCode(code) {
73
- return this.action.login.apply(this, ['submitSmsCode', code]);
73
+ return this.action.callLogin.apply(this, ['submitSmsCode', code]);
74
74
  }
75
75
  sendSmsCode() {
76
- return this.client.sendSmsCode();
76
+ return new Promise(resolve => {
77
+ const receiveResult = (e) => {
78
+ const callback = (data) => {
79
+ this.client.off('internal.verbose', receiveResult);
80
+ this.client.off('system.login.error', receiveResult);
81
+ resolve(data);
82
+ };
83
+ if ((typeof e === 'string' && e.includes('已发送')) || typeof e !== 'string') {
84
+ callback(e);
85
+ }
86
+ };
87
+ this.client.on('internal.verbose', receiveResult);
88
+ this.client.on('system.login.error', receiveResult);
89
+ this.client.sendSmsCode();
90
+ });
77
91
  }
78
92
  getSupportedActions() {
79
93
  return [...new Set((0, utils_1.getProperties)(this.action))].filter(key => {
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.V12 = void 0;
7
+ const oicq_1 = require("oicq");
7
8
  const path_1 = require("path");
8
9
  const onebot_1 = require("../../onebot");
9
10
  const action_1 = require("./action");
@@ -16,6 +17,7 @@ const oicq2_cq_enable_1 = require("oicq2-cq-enable");
16
17
  const utils_1 = require("../../utils");
17
18
  const db_1 = require("../../db");
18
19
  const app_1 = require("../../server/app");
20
+ const fs_1 = require("fs");
19
21
  class V12 extends events_1.EventEmitter {
20
22
  constructor(oneBot, client, config) {
21
23
  super();
@@ -197,8 +199,11 @@ class V12 extends events_1.EventEmitter {
197
199
  }
198
200
  });
199
201
  }
200
- stop() {
201
- return this.client.logout();
202
+ async stop() {
203
+ if (this.client.status === oicq_1.OnlineStatus.Online) {
204
+ await this.client.logout();
205
+ }
206
+ (0, fs_1.unlinkSync)(this.client.dir);
202
207
  }
203
208
  dispatch(data = {}) {
204
209
  if (!data)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "onebots",
3
- "version": "0.0.7",
3
+ "version": "0.0.9",
4
4
  "description": "基于oicq的多例oneBot实现",
5
5
  "main": "lib/index.js",
6
6
  "bin": {