onebots 0.0.14 → 0.0.15

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 +63 -63
  3. package/lib/bin.d.ts +2 -2
  4. package/lib/bin.js +5 -5
  5. package/lib/db.d.ts +19 -19
  6. package/lib/db.js +91 -91
  7. package/lib/index.d.ts +5 -5
  8. package/lib/index.js +21 -21
  9. package/lib/onebot.d.ts +44 -44
  10. package/lib/onebot.js +86 -86
  11. package/lib/server/app.d.ts +52 -52
  12. package/lib/server/app.js +232 -232
  13. package/lib/server/router.d.ts +9 -9
  14. package/lib/server/router.js +32 -32
  15. package/lib/service/V11/action/common.d.ts +65 -65
  16. package/lib/service/V11/action/common.js +142 -142
  17. package/lib/service/V11/action/friend.d.ts +38 -38
  18. package/lib/service/V11/action/friend.js +44 -44
  19. package/lib/service/V11/action/group.d.ts +104 -104
  20. package/lib/service/V11/action/group.js +138 -138
  21. package/lib/service/V11/action/index.d.ts +9 -9
  22. package/lib/service/V11/action/index.js +10 -10
  23. package/lib/service/V11/config.d.ts +10 -10
  24. package/lib/service/V11/config.js +2 -2
  25. package/lib/service/V11/index.d.ts +95 -95
  26. package/lib/service/V11/index.js +499 -499
  27. package/lib/service/V12/action/common.d.ts +33 -33
  28. package/lib/service/V12/action/common.js +108 -108
  29. package/lib/service/V12/action/friend.d.ts +13 -13
  30. package/lib/service/V12/action/friend.js +15 -15
  31. package/lib/service/V12/action/group.d.ts +104 -104
  32. package/lib/service/V12/action/group.js +138 -138
  33. package/lib/service/V12/action/guild.d.ts +2 -2
  34. package/lib/service/V12/action/guild.js +6 -6
  35. package/lib/service/V12/action/index.d.ts +10 -10
  36. package/lib/service/V12/action/index.js +11 -11
  37. package/lib/service/V12/config.d.ts +17 -17
  38. package/lib/service/V12/config.js +2 -2
  39. package/lib/service/V12/index.d.ts +102 -102
  40. package/lib/service/V12/index.js +538 -537
  41. package/lib/types.d.ts +3 -3
  42. package/lib/types.js +2 -2
  43. package/lib/utils.d.ts +14 -14
  44. package/lib/utils.js +150 -150
  45. package/package.json +58 -58
  46. package/lib/config.sample.yaml +0 -31
package/lib/onebot.js CHANGED
@@ -1,86 +1,86 @@
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
+ 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,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
+ }