onebots 0.0.9 → 0.0.11
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/README.md +8 -8
- package/lib/onebot.d.ts +1 -1
- package/lib/onebot.js +2 -2
- package/lib/server/app.d.ts +1 -1
- package/lib/server/app.js +4 -4
- package/lib/service/V11/action/common.d.ts +2 -1
- package/lib/service/V11/action/common.js +13 -3
- package/lib/service/V11/index.d.ts +1 -1
- package/lib/service/V11/index.js +5 -3
- package/lib/service/V12/action/common.d.ts +5 -5
- package/lib/service/V12/action/common.js +13 -3
- package/lib/service/V12/index.d.ts +1 -1
- package/lib/service/V12/index.js +5 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -49,14 +49,14 @@ onebots
|
|
|
49
49
|
```
|
|
50
50
|
# 使用接口管理oneBot
|
|
51
51
|
|
|
52
|
-
| url | method | params
|
|
53
|
-
|:--------| :---
|
|
54
|
-
| /list | GET |
|
|
55
|
-
| /detail | GET | uin
|
|
56
|
-
| /qrcode | GET | uin
|
|
57
|
-
| /add | POST | {uin,...config}
|
|
58
|
-
| /edit | POST | {uin,...config}
|
|
59
|
-
| /remove | get | uin
|
|
52
|
+
| url | method | params | desc |
|
|
53
|
+
|:--------| :--- |:----------------|:-------------------------------|
|
|
54
|
+
| /list | GET | | 获取当前运行的机器人列表 |
|
|
55
|
+
| /detail | GET | uin | 获取指定机器人配置 |
|
|
56
|
+
| /qrcode | GET | uin | 获取指定机器人登录二维码 |
|
|
57
|
+
| /add | POST | {uin,...config} | 添加机器人 config 为机器人配置 |
|
|
58
|
+
| /edit | POST | {uin,...config} | 修改机器人配置 config 为机器人配置 |
|
|
59
|
+
| /remove | get | uin,force | 移除机器人,force为true时,将删除机器人data目录 |
|
|
60
60
|
|
|
61
61
|
# 鸣谢
|
|
62
62
|
1. [takayama-lily/oicq](https://github.com/takayama-lily/oicq) 底层服务支持
|
package/lib/onebot.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export declare class OneBot<V extends OneBot.Version> extends EventEmitter {
|
|
|
20
20
|
constructor(app: App, uin: number, config: MayBeArray<OneBotConfig>);
|
|
21
21
|
start(): Promise<void>;
|
|
22
22
|
startListen(): void;
|
|
23
|
-
stop(): Promise<void>;
|
|
23
|
+
stop(force?: boolean): Promise<void>;
|
|
24
24
|
dispatch(data: any): void;
|
|
25
25
|
}
|
|
26
26
|
export declare enum OneBotStatus {
|
package/lib/onebot.js
CHANGED
|
@@ -62,9 +62,9 @@ class OneBot extends events_1.EventEmitter {
|
|
|
62
62
|
instance.start(this.instances.length > 1 ? '/' + instance.version : undefined);
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
|
-
async stop() {
|
|
65
|
+
async stop(force) {
|
|
66
66
|
for (const instance of this.instances) {
|
|
67
|
-
await instance.stop();
|
|
67
|
+
await instance.stop(force);
|
|
68
68
|
}
|
|
69
69
|
this.client.off('system', this.dispatch.bind(this));
|
|
70
70
|
this.client.off('notice', this.dispatch.bind(this));
|
package/lib/server/app.d.ts
CHANGED
|
@@ -31,7 +31,7 @@ export declare class App extends Koa {
|
|
|
31
31
|
private createOneBots;
|
|
32
32
|
addAccount(uin: number | `${number}`, config: MayBeArray<OneBot.Config<OneBot.Version>>): void;
|
|
33
33
|
updateAccount(uin: number | `${number}`, config: MayBeArray<OneBot.Config<OneBot.Version>>): void;
|
|
34
|
-
removeAccount(uin: number | `${number}
|
|
34
|
+
removeAccount(uin: number | `${number}`, force?: boolean): void;
|
|
35
35
|
createOneBot(uin: number, config: MayBeArray<OneBot.Config<OneBot.Version>>): OneBot<OneBot.Version>;
|
|
36
36
|
start(): void;
|
|
37
37
|
}
|
package/lib/server/app.js
CHANGED
|
@@ -100,7 +100,7 @@ class App extends koa_1.default {
|
|
|
100
100
|
this.removeAccount(uin);
|
|
101
101
|
this.addAccount(uin, newConfig);
|
|
102
102
|
}
|
|
103
|
-
removeAccount(uin) {
|
|
103
|
+
removeAccount(uin, force) {
|
|
104
104
|
if (typeof uin !== "number")
|
|
105
105
|
uin = Number(uin);
|
|
106
106
|
if (Number.isNaN(uin))
|
|
@@ -109,7 +109,7 @@ class App extends koa_1.default {
|
|
|
109
109
|
if (currentIdx < 0)
|
|
110
110
|
throw new Error('账户不存在');
|
|
111
111
|
const oneBot = this.oneBots[currentIdx];
|
|
112
|
-
oneBot.stop();
|
|
112
|
+
oneBot.stop(force);
|
|
113
113
|
delete this.config[uin];
|
|
114
114
|
this.oneBots.splice(currentIdx, 1);
|
|
115
115
|
(0, fs_1.writeFileSync)(App.configPath, js_yaml_1.default.dump(this.config));
|
|
@@ -181,9 +181,9 @@ class App extends koa_1.default {
|
|
|
181
181
|
}
|
|
182
182
|
});
|
|
183
183
|
this.router.get('/remove', (ctx, next) => {
|
|
184
|
-
const { uin } = ctx.request.query;
|
|
184
|
+
const { uin, force } = ctx.request.query;
|
|
185
185
|
try {
|
|
186
|
-
this.removeAccount(Number(uin));
|
|
186
|
+
this.removeAccount(Number(uin), Boolean(force));
|
|
187
187
|
ctx.body = `移除成功`;
|
|
188
188
|
}
|
|
189
189
|
catch (e) {
|
|
@@ -59,7 +59,8 @@ export declare class CommonAction {
|
|
|
59
59
|
};
|
|
60
60
|
callLogin(this: V11, func: string, ...args: any[]): Promise<unknown>;
|
|
61
61
|
submitSlider(this: V11, ticket: string): Promise<any>;
|
|
62
|
-
login(this: V11, password?: string): any;
|
|
63
62
|
submitSmsCode(this: V11, code: string): Promise<any>;
|
|
64
63
|
sendSmsCode(this: V11): Promise<any>;
|
|
64
|
+
login(this: V11, password?: string): any;
|
|
65
|
+
logout(this: V11, keepalive?: boolean): Promise<unknown>;
|
|
65
66
|
}
|
|
@@ -105,9 +105,6 @@ class CommonAction {
|
|
|
105
105
|
async submitSlider(ticket) {
|
|
106
106
|
return this.action.callLogin.apply(this, ['submitSlider', ticket]);
|
|
107
107
|
}
|
|
108
|
-
login(password) {
|
|
109
|
-
return this.action.callLogin.apply(this, ['login', password]);
|
|
110
|
-
}
|
|
111
108
|
async submitSmsCode(code) {
|
|
112
109
|
return this.action.callLogin.apply(this, ['submitSmsCode', code]);
|
|
113
110
|
}
|
|
@@ -128,5 +125,18 @@ class CommonAction {
|
|
|
128
125
|
this.client.sendSmsCode();
|
|
129
126
|
});
|
|
130
127
|
}
|
|
128
|
+
login(password) {
|
|
129
|
+
return this.action.callLogin.apply(this, ['login', password]);
|
|
130
|
+
}
|
|
131
|
+
logout(keepalive) {
|
|
132
|
+
return new Promise(async (resolve) => {
|
|
133
|
+
const receiveResult = (e) => {
|
|
134
|
+
this.client.off('system.offline', receiveResult);
|
|
135
|
+
resolve(e);
|
|
136
|
+
};
|
|
137
|
+
this.client.on('system.offline', receiveResult);
|
|
138
|
+
await this.client.logout(keepalive);
|
|
139
|
+
});
|
|
140
|
+
}
|
|
131
141
|
}
|
|
132
142
|
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(): Promise<void>;
|
|
35
|
+
stop(force?: boolean): Promise<void>;
|
|
36
36
|
dispatch(data: any): void;
|
|
37
37
|
private _httpRequestHandler;
|
|
38
38
|
/**
|
package/lib/service/V11/index.js
CHANGED
|
@@ -163,11 +163,13 @@ class V11 extends events_1.EventEmitter {
|
|
|
163
163
|
}
|
|
164
164
|
});
|
|
165
165
|
}
|
|
166
|
-
async stop() {
|
|
166
|
+
async stop(force) {
|
|
167
167
|
if (this.client.status === oicq_1.OnlineStatus.Online) {
|
|
168
|
-
await this.client.
|
|
168
|
+
await this.client.terminate();
|
|
169
|
+
}
|
|
170
|
+
if (force) {
|
|
171
|
+
(0, fs_1.rmSync)(this.client.dir, { force: true, recursive: true });
|
|
169
172
|
}
|
|
170
|
-
(0, fs_1.unlinkSync)(this.client.dir);
|
|
171
173
|
}
|
|
172
174
|
dispatch(data) {
|
|
173
175
|
if (!data.post_type)
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { V12 } from '../../../service/V12';
|
|
2
2
|
import { OnlineStatus } from "oicq";
|
|
3
3
|
import { Action } from "./";
|
|
4
|
-
import { V11 } from "../../../service/V11";
|
|
5
4
|
export declare class CommonAction {
|
|
6
5
|
sendMsg(): void;
|
|
7
6
|
/**
|
|
@@ -24,10 +23,11 @@ export declare class CommonAction {
|
|
|
24
23
|
version: string;
|
|
25
24
|
onebot_version: string;
|
|
26
25
|
};
|
|
27
|
-
callLogin(this:
|
|
28
|
-
submitSlider(this:
|
|
29
|
-
|
|
30
|
-
submitSmsCode(this: V11, code: string): Promise<any>;
|
|
26
|
+
callLogin(this: V12, func: string, ...args: any[]): Promise<unknown>;
|
|
27
|
+
submitSlider(this: V12, ticket: string): Promise<any>;
|
|
28
|
+
submitSmsCode(this: V12, code: string): Promise<any>;
|
|
31
29
|
sendSmsCode(this: V12): Promise<any>;
|
|
30
|
+
login(this: V12, password?: string): any;
|
|
31
|
+
logout(this: V12, keepalive?: boolean): Promise<unknown>;
|
|
32
32
|
getSupportedActions(this: V12): string[];
|
|
33
33
|
}
|
|
@@ -66,9 +66,6 @@ class CommonAction {
|
|
|
66
66
|
async submitSlider(ticket) {
|
|
67
67
|
return this.action.callLogin.apply(this, ['submitSlider', ticket]);
|
|
68
68
|
}
|
|
69
|
-
login(password) {
|
|
70
|
-
return this.action.callLogin.apply(this, ['login', password]);
|
|
71
|
-
}
|
|
72
69
|
async submitSmsCode(code) {
|
|
73
70
|
return this.action.callLogin.apply(this, ['submitSmsCode', code]);
|
|
74
71
|
}
|
|
@@ -89,6 +86,19 @@ class CommonAction {
|
|
|
89
86
|
this.client.sendSmsCode();
|
|
90
87
|
});
|
|
91
88
|
}
|
|
89
|
+
login(password) {
|
|
90
|
+
return this.action.callLogin.apply(this, ['login', password]);
|
|
91
|
+
}
|
|
92
|
+
logout(keepalive) {
|
|
93
|
+
return new Promise(async (resolve) => {
|
|
94
|
+
const receiveResult = (e) => {
|
|
95
|
+
this.client.off('system.offline', receiveResult);
|
|
96
|
+
resolve(e);
|
|
97
|
+
};
|
|
98
|
+
this.client.on('system.offline', receiveResult);
|
|
99
|
+
await this.client.logout(keepalive);
|
|
100
|
+
});
|
|
101
|
+
}
|
|
92
102
|
getSupportedActions() {
|
|
93
103
|
return [...new Set((0, utils_1.getProperties)(this.action))].filter(key => {
|
|
94
104
|
return key !== 'constructor';
|
|
@@ -28,7 +28,7 @@ export declare class V12 extends EventEmitter implements OneBot.Base {
|
|
|
28
28
|
private startWebhook;
|
|
29
29
|
private startWs;
|
|
30
30
|
private startWsReverse;
|
|
31
|
-
stop(): Promise<void>;
|
|
31
|
+
stop(force?: boolean): Promise<void>;
|
|
32
32
|
dispatch<T extends Record<string, any>>(data?: T): void;
|
|
33
33
|
apply(req: any): Promise<string>;
|
|
34
34
|
private _httpRequestHandler;
|
package/lib/service/V12/index.js
CHANGED
|
@@ -199,11 +199,13 @@ class V12 extends events_1.EventEmitter {
|
|
|
199
199
|
}
|
|
200
200
|
});
|
|
201
201
|
}
|
|
202
|
-
async stop() {
|
|
202
|
+
async stop(force) {
|
|
203
203
|
if (this.client.status === oicq_1.OnlineStatus.Online) {
|
|
204
|
-
await this.client.
|
|
204
|
+
await this.client.terminate();
|
|
205
|
+
}
|
|
206
|
+
if (force) {
|
|
207
|
+
(0, fs_1.rmSync)(this.client.dir, { force: true, recursive: true });
|
|
205
208
|
}
|
|
206
|
-
(0, fs_1.unlinkSync)(this.client.dir);
|
|
207
209
|
}
|
|
208
210
|
dispatch(data = {}) {
|
|
209
211
|
if (!data)
|