onebots 0.0.1

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.
Files changed (46) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +59 -0
  3. package/lib/bin.d.ts +2 -0
  4. package/lib/bin.js +5 -0
  5. package/lib/config.sample.yaml +31 -0
  6. package/lib/db.d.ts +19 -0
  7. package/lib/db.js +91 -0
  8. package/lib/index.d.ts +5 -0
  9. package/lib/index.js +21 -0
  10. package/lib/onebot.d.ts +43 -0
  11. package/lib/onebot.js +85 -0
  12. package/lib/server/app.d.ts +52 -0
  13. package/lib/server/app.js +232 -0
  14. package/lib/server/router.d.ts +9 -0
  15. package/lib/server/router.js +32 -0
  16. package/lib/service/V11/action/common.d.ts +64 -0
  17. package/lib/service/V11/action/common.js +115 -0
  18. package/lib/service/V11/action/friend.d.ts +38 -0
  19. package/lib/service/V11/action/friend.js +44 -0
  20. package/lib/service/V11/action/group.d.ts +104 -0
  21. package/lib/service/V11/action/group.js +138 -0
  22. package/lib/service/V11/action/index.d.ts +9 -0
  23. package/lib/service/V11/action/index.js +10 -0
  24. package/lib/service/V11/config.d.ts +10 -0
  25. package/lib/service/V11/config.js +2 -0
  26. package/lib/service/V11/index.d.ts +95 -0
  27. package/lib/service/V11/index.js +481 -0
  28. package/lib/service/V12/action/common.d.ts +32 -0
  29. package/lib/service/V12/action/common.js +105 -0
  30. package/lib/service/V12/action/friend.d.ts +13 -0
  31. package/lib/service/V12/action/friend.js +15 -0
  32. package/lib/service/V12/action/group.d.ts +104 -0
  33. package/lib/service/V12/action/group.js +138 -0
  34. package/lib/service/V12/action/guild.d.ts +2 -0
  35. package/lib/service/V12/action/guild.js +6 -0
  36. package/lib/service/V12/action/index.d.ts +10 -0
  37. package/lib/service/V12/action/index.js +11 -0
  38. package/lib/service/V12/config.d.ts +17 -0
  39. package/lib/service/V12/config.js +2 -0
  40. package/lib/service/V12/index.d.ts +102 -0
  41. package/lib/service/V12/index.js +530 -0
  42. package/lib/types.d.ts +3 -0
  43. package/lib/types.js +2 -0
  44. package/lib/utils.d.ts +13 -0
  45. package/lib/utils.js +139 -0
  46. package/package.json +58 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 凉菜
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,59 @@
1
+ <div align="center">
2
+ <h1>基于icqq的oneBot实现</h1>
3
+ <p>
4
+
5
+ [![dm](https://shields.io/npm/dm/icqq-onebot)](https://www.npmjs.com/package/icqq-onebot)
6
+ [![oneBot V11](https://img.shields.io/badge/OneBot-11-black?logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAHAAAABwCAMAAADxPgR5AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAAxQTFRF////29vbr6+vAAAAk1hCcwAAAAR0Uk5T////AEAqqfQAAAKcSURBVHja7NrbctswDATQXfD//zlpO7FlmwAWIOnOtNaTM5JwDMa8E+PNFz7g3waJ24fviyDPgfhz8fHP39cBcBL9KoJbQUxjA2iYqHL3FAnvzhL4GtVNUcoSZe6eSHizBcK5LL7dBr2AUZlev1ARRHCljzRALIEog6H3U6bCIyqIZdAT0eBuJYaGiJaHSjmkYIZd+qSGWAQnIaz2OArVnX6vrItQvbhZJtVGB5qX9wKqCMkb9W7aexfCO/rwQRBzsDIsYx4AOz0nhAtWu7bqkEQBO0Pr+Ftjt5fFCUEbm0Sbgdu8WSgJ5NgH2iu46R/o1UcBXJsFusWF/QUaz3RwJMEgngfaGGdSxJkE/Yg4lOBryBiMwvAhZrVMUUvwqU7F05b5WLaUIN4M4hRocQQRnEedgsn7TZB3UCpRrIJwQfqvGwsg18EnI2uSVNC8t+0QmMXogvbPg/xk+Mnw/6kW/rraUlvqgmFreAA09xW5t0AFlHrQZ3CsgvZm0FbHNKyBmheBKIF2cCA8A600aHPmFtRB1XvMsJAiza7LpPog0UJwccKdzw8rdf8MyN2ePYF896LC5hTzdZqxb6VNXInaupARLDNBWgI8spq4T0Qb5H4vWfPmHo8OyB1ito+AysNNz0oglj1U955sjUN9d41LnrX2D/u7eRwxyOaOpfyevCWbTgDEoilsOnu7zsKhjRCsnD/QzhdkYLBLXjiK4f3UWmcx2M7PO21CKVTH84638NTplt6JIQH0ZwCNuiWAfvuLhdrcOYPVO9eW3A67l7hZtgaY9GZo9AFc6cryjoeFBIWeU+npnk/nLE0OxCHL1eQsc1IciehjpJv5mqCsjeopaH6r15/MrxNnVhu7tmcslay2gO2Z1QfcfX0JMACG41/u0RrI9QAAAABJRU5ErkJggg==)](https://onebot.dev/)
7
+ [![oneBot V12](https://img.shields.io/badge/OneBot-12-black?logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAHAAAABwCAMAAADxPgR5AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAAxQTFRF////29vbr6+vAAAAk1hCcwAAAAR0Uk5T////AEAqqfQAAAKcSURBVHja7NrbctswDATQXfD//zlpO7FlmwAWIOnOtNaTM5JwDMa8E+PNFz7g3waJ24fviyDPgfhz8fHP39cBcBL9KoJbQUxjA2iYqHL3FAnvzhL4GtVNUcoSZe6eSHizBcK5LL7dBr2AUZlev1ARRHCljzRALIEog6H3U6bCIyqIZdAT0eBuJYaGiJaHSjmkYIZd+qSGWAQnIaz2OArVnX6vrItQvbhZJtVGB5qX9wKqCMkb9W7aexfCO/rwQRBzsDIsYx4AOz0nhAtWu7bqkEQBO0Pr+Ftjt5fFCUEbm0Sbgdu8WSgJ5NgH2iu46R/o1UcBXJsFusWF/QUaz3RwJMEgngfaGGdSxJkE/Yg4lOBryBiMwvAhZrVMUUvwqU7F05b5WLaUIN4M4hRocQQRnEedgsn7TZB3UCpRrIJwQfqvGwsg18EnI2uSVNC8t+0QmMXogvbPg/xk+Mnw/6kW/rraUlvqgmFreAA09xW5t0AFlHrQZ3CsgvZm0FbHNKyBmheBKIF2cCA8A600aHPmFtRB1XvMsJAiza7LpPog0UJwccKdzw8rdf8MyN2ePYF896LC5hTzdZqxb6VNXInaupARLDNBWgI8spq4T0Qb5H4vWfPmHo8OyB1ito+AysNNz0oglj1U955sjUN9d41LnrX2D/u7eRwxyOaOpfyevCWbTgDEoilsOnu7zsKhjRCsnD/QzhdkYLBLXjiK4f3UWmcx2M7PO21CKVTH84638NTplt6JIQH0ZwCNuiWAfvuLhdrcOYPVO9eW3A67l7hZtgaY9GZo9AFc6cryjoeFBIWeU+npnk/nLE0OxCHL1eQsc1IciehjpJv5mqCsjeopaH6r15/MrxNnVhu7tmcslay2gO2Z1QfcfX0JMACG41/u0RrI9QAAAABJRU5ErkJggg==)](https://12.onebot.dev/)
8
+ [![node engine](https://img.shields.io/node/v/oitq?color=339933&style=flat-square&labelColor=FAFAFA&logo=Node.js)](https://nodejs.org)
9
+ [![qq group](https://img.shields.io/badge/group-860669870-blue?style=flat-square&labelColor=FAFAFA&logo=data:image/png;base64,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&logoColor=000000)](https://jq.qq.com/?_wv=1027&k=B22VGXov)
10
+ [docs](/docs)
11
+
12
+
13
+ </p>
14
+ </div>
15
+
16
+ # 使用示例
17
+ 1. 新建一个node项目
18
+ ```shell
19
+ npm init -y
20
+ ```
21
+ 2. 安装@icqq/oneBot
22
+ ```shell
23
+ npm install onebots
24
+ ```
25
+ 3. 在项目跟目录添加配置文件config.yaml
26
+ ```yaml
27
+ port: 6727 # 项目icqq-oneBot监听的端口(默认:6727)
28
+ 1472258369: # 你的机器人账户
29
+ version: V11 # oneBot版本(V11 或 V12)
30
+ ```
31
+ 4. 新建入口文件`index.js`并输入一下内容
32
+ ```javascript
33
+ const {createApp}=require('onebots')
34
+ createApp()
35
+ .start()
36
+ ```
37
+ 5. 启动项目
38
+ ```shell
39
+ node ./index.js
40
+ ```
41
+ # 使用命令行启动
42
+ ```shell
43
+ npm install -g onebots
44
+ onebots
45
+ ```
46
+ # 使用接口管理oneBot
47
+
48
+ | url | method | params | desc |
49
+ |:--------| :--- |:-----------------|:----------------------|
50
+ | /list | GET | | 获取当前运行的机器人列表 |
51
+ | /detail | GET | uin | 获取指定机器人配置 |
52
+ | /qrcode | GET | uin | 获取指定机器人登录二维码 |
53
+ | /add | POST | {uin,...config} | 添加机器人 config 为机器人配置 |
54
+ | /edit | POST | {uin,...config} | 修改机器人配置 config 为机器人配置 |
55
+ | /remove | get | uin | 移除机器人 |
56
+
57
+ # 鸣谢
58
+ 1. [icqqjs/icqq](https://github.com/takayama-lily/icqq) 底层服务支持
59
+ 2. [takayama-lily/onebot](https://github.com/takayama-lily/node-onebot) oneBots原先版本
package/lib/bin.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/lib/bin.js ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const app_1 = require("./server/app");
5
+ (0, app_1.createApp)();
@@ -0,0 +1,31 @@
1
+ port: 6727 # 监听端口
2
+ general: # 通用配置,在单个配置省略时的默认值
3
+ V11: # oneBotV11的通用配置
4
+ heartbeat: 3 # 心跳间隔 (秒)
5
+ access_token: '' # 访问api的token
6
+ post_timeout: 15 # 上报超时时间,(秒)
7
+ secret: '' # 上报数据的sha1签名密钥
8
+ rate_limit_interval: 4 # ws心跳间隔(秒)
9
+ post_message_format: string # "string"或"array"
10
+ reconnect_interval: 3 # 重连间隔 (秒)
11
+ use_http: true # 是否使用 http
12
+ enable_cors: true # 是否允许跨域
13
+ use_ws: true # 是否使用websocket
14
+ http_reverse: [] # http上报地址
15
+ ws_reverse: [] # 反向ws连接地址
16
+ V12: # oneBotV12的通用配置
17
+ heartbeat: 3 # 心跳间隔 (秒)
18
+ access_token: '' # 访问api的token
19
+ request_timeout: 15 # 上报超时时间 (秒)
20
+ reconnect_interval: 3 # 重连间隔 (秒)
21
+ enable_cors: true # 是否允许跨域
22
+ use_http: true # 是否启用http
23
+ use_ws: true # 是否启用 websocket
24
+ webhook: [] # http 上报地址
25
+ ws_reverse: [] # 反向ws连接地址
26
+ log_level: info # 日志等级
27
+ # 每个账号的单独配置(用于覆盖通用配置)
28
+ 123456789:
29
+ version: V11 # 使用的oneBot版本
30
+ password: abcedfghi # 账号密码,未配置则扫码登陆
31
+ # 。。。其他配置项参见上方对应oneBot版本的通用配置
package/lib/db.d.ts ADDED
@@ -0,0 +1,19 @@
1
+ /// <reference types="node" />
2
+ import { EventEmitter } from "events";
3
+ export declare class Db extends EventEmitter {
4
+ private readonly path;
5
+ private data;
6
+ private raw_data;
7
+ constructor(path: string, force_create?: boolean);
8
+ get(key: string, escape?: boolean): any;
9
+ set(key: string, value: any, escape?: boolean): any;
10
+ has(key: string, escape?: boolean): boolean;
11
+ delete(key: string, escape?: boolean): boolean;
12
+ write(): Promise<void>;
13
+ }
14
+ export declare namespace Db {
15
+ interface Config {
16
+ path: string;
17
+ force?: boolean;
18
+ }
19
+ }
package/lib/db.js ADDED
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Db = void 0;
4
+ const fs_1 = require("fs");
5
+ const promises_1 = require("fs/promises");
6
+ const events_1 = require("events");
7
+ class Db extends events_1.EventEmitter {
8
+ constructor(path, force_create = true) {
9
+ super();
10
+ this.path = path;
11
+ this.data = {};
12
+ this.raw_data = '{}';
13
+ if (!this.path.toLowerCase().endsWith('.json'))
14
+ this.path = this.path + '.json';
15
+ if (!(0, fs_1.existsSync)(this.path) && force_create) {
16
+ (0, fs_1.writeFileSync)(this.path, this.raw_data);
17
+ }
18
+ try {
19
+ const raw_data = (0, fs_1.readFileSync)(this.path, 'utf8');
20
+ this.raw_data = raw_data || this.raw_data;
21
+ this.data = JSON.parse(this.raw_data);
22
+ }
23
+ catch (error) {
24
+ const { message } = error;
25
+ if (!message.includes('ENOENT: no such file or directory')) {
26
+ throw error;
27
+ }
28
+ }
29
+ }
30
+ get(key, escape = true) {
31
+ const func = new Function(`return this.data.${key}`);
32
+ const _this = this;
33
+ let result;
34
+ try {
35
+ result = escape ? func.apply(this) : this.data[key];
36
+ }
37
+ catch {
38
+ throw new Error('不可达的位置:' + key.toString());
39
+ }
40
+ return result && typeof result === 'object' ? new Proxy(result, {
41
+ get(target, p) {
42
+ return target[p];
43
+ },
44
+ set(target, p, value, receiver) {
45
+ const result = target[p] = value;
46
+ _this.write();
47
+ return result;
48
+ }
49
+ }) : result;
50
+ }
51
+ set(key, value, escape = true) {
52
+ const func = new Function('value', `return this.data.${key}=value`);
53
+ const _this = this;
54
+ let result;
55
+ result = escape ? func.apply(this, [value]) : this.data[key] = value;
56
+ this.raw_data = JSON.stringify(this.data, null, 2);
57
+ this.write();
58
+ return result && typeof result === 'object' ? new Proxy(result, {
59
+ get(target, p) {
60
+ return target[p];
61
+ },
62
+ set(target, p, value, receiver) {
63
+ const result = target[p] = value;
64
+ _this.write();
65
+ return result;
66
+ }
67
+ }) : result;
68
+ }
69
+ has(key, escape = true) {
70
+ return escape ? new Function(`return !!this.data.${key}`).apply(this) : !!this.data[key];
71
+ }
72
+ delete(key, escape = true) {
73
+ const result = escape ? new Function(`return delete this.data.${key}`).apply(this) : delete this.data[key];
74
+ this.write();
75
+ return result;
76
+ }
77
+ async write() {
78
+ try {
79
+ const raw_data = JSON.stringify(this.data, null, 2);
80
+ if (raw_data !== this.raw_data) {
81
+ await (0, promises_1.writeFile)(this.path, raw_data);
82
+ this.raw_data = raw_data;
83
+ }
84
+ }
85
+ catch (error) {
86
+ this.data = JSON.parse(this.raw_data);
87
+ throw error;
88
+ }
89
+ }
90
+ }
91
+ exports.Db = Db;
package/lib/index.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ export * from './server/app';
2
+ export * from './server/router';
3
+ export * from './onebot';
4
+ export * from './types';
5
+ export * from './utils';
package/lib/index.js ADDED
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./server/app"), exports);
18
+ __exportStar(require("./server/router"), exports);
19
+ __exportStar(require("./onebot"), exports);
20
+ __exportStar(require("./types"), exports);
21
+ __exportStar(require("./utils"), exports);
@@ -0,0 +1,43 @@
1
+ /// <reference types="node" />
2
+ import { EventEmitter } from 'events';
3
+ import { App } from "./server/app";
4
+ import { Client } from "icqq";
5
+ import { V11 } from "./service/V11";
6
+ import { V12 } from "./service/V12";
7
+ import { MayBeArray } from "./types";
8
+ export declare class NotFoundError extends Error {
9
+ message: string;
10
+ }
11
+ export declare class OneBot<V extends OneBot.Version> extends EventEmitter {
12
+ app: App;
13
+ readonly uin: number;
14
+ config: OneBotConfig[];
15
+ status: OneBotStatus;
16
+ protected password: string;
17
+ client: Client;
18
+ instances: (V11 | V12)[];
19
+ constructor(app: App, uin: number, config: MayBeArray<OneBotConfig>);
20
+ start(): void;
21
+ startListen(): void;
22
+ stop(): void;
23
+ dispatch(data: any): void;
24
+ }
25
+ export declare enum OneBotStatus {
26
+ Good = 0,
27
+ Bad = 1
28
+ }
29
+ export declare type OneBotConfig = OneBot.Config<OneBot.Version>;
30
+ export declare namespace OneBot {
31
+ type Version = 'V11' | 'V12';
32
+ type Config<V extends Version = 'V11'> = ({
33
+ version?: V;
34
+ password?: string;
35
+ } & (V extends 'V11' ? V11.Config : V12.Config));
36
+ interface Base {
37
+ start(path?: string): any;
38
+ stop(): any;
39
+ dispatch(...args: any[]): any;
40
+ apply(...args: any[]): any;
41
+ }
42
+ }
43
+ export declare const BOOLS: string[];
package/lib/onebot.js ADDED
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BOOLS = exports.OneBotStatus = exports.OneBot = exports.NotFoundError = void 0;
4
+ const events_1 = require("events");
5
+ const app_1 = require("./server/app");
6
+ const utils_1 = require("./utils");
7
+ const path_1 = require("path");
8
+ const icqq_1 = require("icqq");
9
+ const V11_1 = require("./service/V11");
10
+ const V12_1 = require("./service/V12");
11
+ class NotFoundError extends Error {
12
+ constructor() {
13
+ super(...arguments);
14
+ this.message = '不支持的API';
15
+ }
16
+ }
17
+ exports.NotFoundError = NotFoundError;
18
+ class OneBot extends events_1.EventEmitter {
19
+ constructor(app, uin, config) {
20
+ super();
21
+ this.app = app;
22
+ this.uin = uin;
23
+ if (!Array.isArray(config))
24
+ config = new Array(config);
25
+ this.config = config.map(c => {
26
+ if (c.password)
27
+ this.password = c.password;
28
+ if (!c.version)
29
+ c.version = 'V11';
30
+ switch (c.version) {
31
+ case 'V11':
32
+ return (0, utils_1.deepMerge)(this.app.config.general.V11, c);
33
+ case 'V12':
34
+ return (0, utils_1.deepMerge)(this.app.config.general.V12, c);
35
+ default:
36
+ throw new Error('不支持的oneBot版本:' + c.version);
37
+ }
38
+ });
39
+ this.client = new icqq_1.Client(uin, { platform: this.app.config.platform, data_dir: (0, path_1.join)(app_1.App.configDir, 'data') });
40
+ this.instances = this.config.map(c => {
41
+ switch (c.version) {
42
+ case 'V11':
43
+ return new V11_1.V11(this, this.client, (0, utils_1.omit)(c, ['version', 'password']));
44
+ case 'V12':
45
+ return new V12_1.V12(this, this.client, (0, utils_1.omit)(c, ['version', 'password']));
46
+ default:
47
+ throw new Error('不支持的oneBot版本:' + c.version);
48
+ }
49
+ });
50
+ }
51
+ start() {
52
+ this.startListen();
53
+ this.client.login(this.password);
54
+ }
55
+ startListen() {
56
+ this.client.on('system', this.dispatch.bind(this));
57
+ this.client.on('notice', this.dispatch.bind(this));
58
+ this.client.on('request', this.dispatch.bind(this));
59
+ this.client.on('message', this.dispatch.bind(this));
60
+ this.instances.forEach(instance => {
61
+ instance.start(this.instances.length > 1 ? '/' + instance.version : undefined);
62
+ });
63
+ }
64
+ stop() {
65
+ this.instances.forEach(instance => {
66
+ instance.stop();
67
+ });
68
+ this.client.off('system', this.dispatch.bind(this));
69
+ this.client.off('notice', this.dispatch.bind(this));
70
+ this.client.off('request', this.dispatch.bind(this));
71
+ this.client.off('message', this.dispatch.bind(this));
72
+ }
73
+ dispatch(data) {
74
+ for (const instance of this.instances) {
75
+ instance.dispatch(data);
76
+ }
77
+ }
78
+ }
79
+ exports.OneBot = OneBot;
80
+ var OneBotStatus;
81
+ (function (OneBotStatus) {
82
+ OneBotStatus[OneBotStatus["Good"] = 0] = "Good";
83
+ OneBotStatus[OneBotStatus["Bad"] = 1] = "Bad";
84
+ })(OneBotStatus = exports.OneBotStatus || (exports.OneBotStatus = {}));
85
+ exports.BOOLS = ["no_cache", "auto_escape", "as_long", "enable", "reject_add_request", "is_dismiss", "approve", "block"];
@@ -0,0 +1,52 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="koa-bodyparser" />
3
+ import Koa from 'koa';
4
+ import { Logger } from "log4js";
5
+ import { Server } from "http";
6
+ import { OneBot } from "../onebot";
7
+ import { Router } from "./router";
8
+ import { V11 } from "../service/V11";
9
+ import { V12 } from "../service/V12";
10
+ import { LogLevel, MayBeArray } from "../types";
11
+ import { Platform } from "icqq";
12
+ export interface KoaOptions {
13
+ env?: string;
14
+ keys?: string[];
15
+ proxy?: boolean;
16
+ subdomainOffset?: number;
17
+ proxyIpHeader?: string;
18
+ maxIpsCount?: number;
19
+ }
20
+ export declare class App extends Koa {
21
+ config: App.Config;
22
+ readonly httpServer: Server;
23
+ logger: Logger;
24
+ static configDir: string;
25
+ static configPath: string;
26
+ oneBots: OneBot<any>[];
27
+ router: Router;
28
+ constructor(config?: App.Config);
29
+ getLogger(uin: number | string, version?: string): Logger;
30
+ private getBots;
31
+ private createOneBots;
32
+ addAccount(uin: number | `${number}`, config: MayBeArray<OneBot.Config<OneBot.Version>>): void;
33
+ updateAccount(uin: number | `${number}`, config: MayBeArray<OneBot.Config<OneBot.Version>>): void;
34
+ removeAccount(uin: number | `${number}`): void;
35
+ createOneBot(uin: number, config: MayBeArray<OneBot.Config<OneBot.Version>>): OneBot<OneBot.Version>;
36
+ start(): void;
37
+ }
38
+ export declare function createApp<V extends OneBot.Version>(config?: App.Config | string): App;
39
+ export declare function defineConfig(config: App.Config): App.Config;
40
+ export declare namespace App {
41
+ type Config = {
42
+ port?: number;
43
+ path?: string;
44
+ log_level?: LogLevel;
45
+ platform?: Platform;
46
+ general?: {
47
+ V11?: V11.Config;
48
+ V12?: V12.Config;
49
+ };
50
+ } & KoaOptions & Record<`${number}`, MayBeArray<OneBot.Config<OneBot.Version>>>;
51
+ const defaultConfig: Config;
52
+ }