onebots 0.0.15 → 0.0.16

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 -21
  2. package/README.md +84 -63
  3. package/lib/bin.d.ts +2 -2
  4. package/lib/bin.js +11 -5
  5. package/lib/config.sample.yaml +31 -0
  6. package/lib/db.d.ts +19 -19
  7. package/lib/db.js +91 -91
  8. package/lib/index.d.ts +5 -5
  9. package/lib/index.js +21 -21
  10. package/lib/onebot.d.ts +44 -44
  11. package/lib/onebot.js +133 -86
  12. package/lib/server/app.d.ts +52 -52
  13. package/lib/server/app.js +235 -232
  14. package/lib/server/router.d.ts +9 -9
  15. package/lib/server/router.js +32 -32
  16. package/lib/service/V11/action/common.d.ts +65 -65
  17. package/lib/service/V11/action/common.js +142 -142
  18. package/lib/service/V11/action/friend.d.ts +38 -38
  19. package/lib/service/V11/action/friend.js +44 -44
  20. package/lib/service/V11/action/group.d.ts +104 -104
  21. package/lib/service/V11/action/group.js +138 -138
  22. package/lib/service/V11/action/index.d.ts +9 -9
  23. package/lib/service/V11/action/index.js +10 -10
  24. package/lib/service/V11/config.d.ts +10 -10
  25. package/lib/service/V11/config.js +2 -2
  26. package/lib/service/V11/index.d.ts +95 -95
  27. package/lib/service/V11/index.js +499 -499
  28. package/lib/service/V12/action/common.d.ts +37 -33
  29. package/lib/service/V12/action/common.js +114 -108
  30. package/lib/service/V12/action/friend.d.ts +13 -13
  31. package/lib/service/V12/action/friend.js +15 -15
  32. package/lib/service/V12/action/group.d.ts +104 -104
  33. package/lib/service/V12/action/group.js +138 -138
  34. package/lib/service/V12/action/guild.d.ts +2 -2
  35. package/lib/service/V12/action/guild.js +6 -6
  36. package/lib/service/V12/action/index.d.ts +10 -10
  37. package/lib/service/V12/action/index.js +11 -11
  38. package/lib/service/V12/config.d.ts +17 -17
  39. package/lib/service/V12/config.js +2 -2
  40. package/lib/service/V12/index.d.ts +121 -102
  41. package/lib/service/V12/index.js +533 -538
  42. package/lib/types.d.ts +3 -3
  43. package/lib/types.js +2 -2
  44. package/lib/utils.d.ts +14 -14
  45. package/lib/utils.js +150 -150
  46. package/package.json +58 -58
package/lib/onebot.js CHANGED
@@ -1,86 +1,133 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BOOLS = exports.OneBotStatus = exports.OneBot = exports.NotFoundError = void 0;
4
- require("oicq2-cq-enable");
5
- const events_1 = require("events");
6
- const app_1 = require("./server/app");
7
- const utils_1 = require("./utils");
8
- const path_1 = require("path");
9
- const oicq_1 = require("oicq");
10
- const V11_1 = require("./service/V11");
11
- const V12_1 = require("./service/V12");
12
- class NotFoundError extends Error {
13
- constructor() {
14
- super(...arguments);
15
- this.message = '不支持的API';
16
- }
17
- }
18
- exports.NotFoundError = NotFoundError;
19
- class OneBot extends events_1.EventEmitter {
20
- constructor(app, uin, config) {
21
- super();
22
- this.app = app;
23
- this.uin = uin;
24
- if (!Array.isArray(config))
25
- config = new Array(config);
26
- this.config = config.map(c => {
27
- if (c.password)
28
- this.password = c.password;
29
- if (!c.version)
30
- c.version = 'V11';
31
- switch (c.version) {
32
- case 'V11':
33
- return (0, utils_1.deepMerge)(this.app.config.general.V11, c);
34
- case 'V12':
35
- return (0, utils_1.deepMerge)(this.app.config.general.V12, c);
36
- default:
37
- throw new Error('不支持的oneBot版本:' + c.version);
38
- }
39
- });
40
- this.client = new oicq_1.Client(uin, { platform: this.app.config.platform, data_dir: (0, path_1.join)(app_1.App.configDir, 'data') });
41
- this.instances = this.config.map(c => {
42
- switch (c.version) {
43
- case 'V11':
44
- return new V11_1.V11(this, this.client, (0, utils_1.omit)(c, ['version', 'password']));
45
- case 'V12':
46
- return new V12_1.V12(this, this.client, (0, utils_1.omit)(c, ['version', 'password']));
47
- default:
48
- throw new Error('不支持的oneBot版本:' + c.version);
49
- }
50
- });
51
- }
52
- async start() {
53
- this.startListen();
54
- await this.client.login(this.password);
55
- }
56
- startListen() {
57
- this.client.on('system', this.dispatch.bind(this));
58
- this.client.on('notice', this.dispatch.bind(this));
59
- this.client.on('request', this.dispatch.bind(this));
60
- this.client.on('message', this.dispatch.bind(this));
61
- for (const instance of this.instances) {
62
- instance.start(this.instances.length > 1 ? '/' + instance.version : undefined);
63
- }
64
- }
65
- async stop(force) {
66
- for (const instance of this.instances) {
67
- await instance.stop(force);
68
- }
69
- this.client.off('system', this.dispatch.bind(this));
70
- this.client.off('notice', this.dispatch.bind(this));
71
- this.client.off('request', this.dispatch.bind(this));
72
- this.client.off('message', this.dispatch.bind(this));
73
- }
74
- dispatch(data) {
75
- for (const instance of this.instances) {
76
- instance.dispatch(data);
77
- }
78
- }
79
- }
80
- exports.OneBot = OneBot;
81
- var OneBotStatus;
82
- (function (OneBotStatus) {
83
- OneBotStatus[OneBotStatus["Good"] = 0] = "Good";
84
- OneBotStatus[OneBotStatus["Bad"] = 1] = "Bad";
85
- })(OneBotStatus = exports.OneBotStatus || (exports.OneBotStatus = {}));
86
- exports.BOOLS = ["no_cache", "auto_escape", "as_long", "enable", "reject_add_request", "is_dismiss", "approve", "block"];
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BOOLS = exports.OneBotStatus = exports.OneBot = exports.NotFoundError = void 0;
4
+ require("oicq2-cq-enable");
5
+ const events_1 = require("events");
6
+ const app_1 = require("./server/app");
7
+ const utils_1 = require("./utils");
8
+ const path_1 = require("path");
9
+ const oicq_1 = require("oicq");
10
+ const V11_1 = require("./service/V11");
11
+ const V12_1 = require("./service/V12");
12
+ class NotFoundError extends Error {
13
+ constructor() {
14
+ super(...arguments);
15
+ this.message = '不支持的API';
16
+ }
17
+ }
18
+ exports.NotFoundError = NotFoundError;
19
+ class OneBot extends events_1.EventEmitter {
20
+ constructor(app, uin, config) {
21
+ super();
22
+ this.app = app;
23
+ this.uin = uin;
24
+ if (!Array.isArray(config))
25
+ config = new Array(config);
26
+ this.config = config.map(c => {
27
+ if (c.password)
28
+ this.password = c.password;
29
+ if (!c.version)
30
+ c.version = 'V11';
31
+ switch (c.version) {
32
+ case 'V11':
33
+ return (0, utils_1.deepMerge)(this.app.config.general.V11, c);
34
+ case 'V12':
35
+ return (0, utils_1.deepMerge)(this.app.config.general.V12, c);
36
+ default:
37
+ throw new Error('不支持的oneBot版本:' + c.version);
38
+ }
39
+ });
40
+ this.client = new oicq_1.Client(uin, { platform: this.app.config.platform, data_dir: (0, path_1.join)(app_1.App.configDir, 'data') });
41
+ this.instances = this.config.map(c => {
42
+ switch (c.version) {
43
+ case 'V11':
44
+ return new V11_1.V11(this, this.client, (0, utils_1.omit)(c, ['version', 'password']));
45
+ case 'V12':
46
+ return new V12_1.V12(this, this.client, (0, utils_1.omit)(c, ['version', 'password']));
47
+ default:
48
+ throw new Error('不支持的oneBot版本:' + c.version);
49
+ }
50
+ });
51
+ }
52
+ async start() {
53
+ this.startListen();
54
+ const disposeArr = [];
55
+ const clean = () => {
56
+ while (disposeArr.length) {
57
+ disposeArr.shift()();
58
+ }
59
+ };
60
+ this.client.on('system.login.qrcode', function qrcodeHelper() {
61
+ console.log('扫码后回车继续');
62
+ process.stdin.once('data', () => {
63
+ this.login();
64
+ });
65
+ disposeArr.push(() => {
66
+ this.off('system.login.qrcode', qrcodeHelper);
67
+ });
68
+ });
69
+ this.client.on('system.login.device', function deviceHelper() {
70
+ console.log('请输入密保手机接收的验证码');
71
+ this.sendSmsCode();
72
+ process.stdin.once('data', (e) => {
73
+ this.submitSmsCode(e.toString().trim());
74
+ });
75
+ disposeArr.push(() => {
76
+ this.off('system.login.device', deviceHelper);
77
+ });
78
+ });
79
+ this.client.on('system.login.error', function errorHandler(e) {
80
+ if (e.message.includes('密码错误')) {
81
+ process.stdin.once('data', (e) => {
82
+ this.login(e.toString().trim());
83
+ });
84
+ }
85
+ else {
86
+ process.exit();
87
+ }
88
+ this.off('system.login.error', errorHandler);
89
+ });
90
+ this.client.on('system.login.slider', function sliderHelper(e) {
91
+ console.log('滑块验证地址:' + e.url);
92
+ console.log('请输入滑块验证返回的ticket');
93
+ process.stdin.once('data', (e) => {
94
+ this.submitSlider(e.toString().trim());
95
+ });
96
+ disposeArr.push(() => {
97
+ this.off('system.login.slider', sliderHelper);
98
+ });
99
+ });
100
+ this.client.on('system.online', clean);
101
+ await this.client.login(this.password);
102
+ }
103
+ startListen() {
104
+ this.client.on('system', this.dispatch.bind(this));
105
+ this.client.on('notice', this.dispatch.bind(this));
106
+ this.client.on('request', this.dispatch.bind(this));
107
+ this.client.on('message', this.dispatch.bind(this));
108
+ for (const instance of this.instances) {
109
+ instance.start(this.instances.length > 1 ? '/' + instance.version : undefined);
110
+ }
111
+ }
112
+ async stop(force) {
113
+ for (const instance of this.instances) {
114
+ await instance.stop(force);
115
+ }
116
+ this.client.off('system', this.dispatch.bind(this));
117
+ this.client.off('notice', this.dispatch.bind(this));
118
+ this.client.off('request', this.dispatch.bind(this));
119
+ this.client.off('message', this.dispatch.bind(this));
120
+ }
121
+ dispatch(data) {
122
+ for (const instance of this.instances) {
123
+ instance.dispatch(data);
124
+ }
125
+ }
126
+ }
127
+ exports.OneBot = OneBot;
128
+ var OneBotStatus;
129
+ (function (OneBotStatus) {
130
+ OneBotStatus[OneBotStatus["Good"] = 0] = "Good";
131
+ OneBotStatus[OneBotStatus["Bad"] = 1] = "Bad";
132
+ })(OneBotStatus = exports.OneBotStatus || (exports.OneBotStatus = {}));
133
+ exports.BOOLS = ["no_cache", "auto_escape", "as_long", "enable", "reject_add_request", "is_dismiss", "approve", "block"];
@@ -1,52 +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 "oicq";
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}`, force?: boolean): void;
35
- createOneBot(uin: number, config: MayBeArray<OneBot.Config<OneBot.Version>>): OneBot<OneBot.Version>;
36
- start(): void;
37
- }
38
- export declare function createApp(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
- }
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 "oicq";
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}`, force?: boolean): void;
35
+ createOneBot(uin: number, config: MayBeArray<OneBot.Config<OneBot.Version>>): OneBot<OneBot.Version>;
36
+ start(): void;
37
+ }
38
+ export declare function createApp(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
+ }