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/types.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export declare type LogLevel = "trace" | "debug" | "info" | "warn" | "error" | "fatal" | "mark" | "off";
2
- export declare type Dispose = () => any;
3
- export declare type MayBeArray<T extends any> = T | T[];
1
+ export type LogLevel = "trace" | "debug" | "info" | "warn" | "error" | "fatal" | "mark" | "off";
2
+ export type Dispose = () => any;
3
+ export type MayBeArray<T extends any> = T | T[];
package/lib/types.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/lib/utils.d.ts CHANGED
@@ -1,14 +1,14 @@
1
- export declare function deepMerge<T extends any>(base: T, ...from: T[]): T;
2
- export declare function deepClone<T extends any>(obj: T): T;
3
- export declare function pick<T, K extends keyof T>(source: T, keys?: Iterable<K>, forced?: boolean): Pick<T, K>;
4
- export declare function omit<T, K extends keyof T>(source: T, keys?: Iterable<K>): Omit<T, K>;
5
- export interface Class {
6
- new (...args: any[]): any;
7
- }
8
- export declare function Mixin(base: Class, ...classes: Class[]): Class;
9
- export declare function toHump(action: string): string;
10
- export declare function toLine(name: string): string;
11
- export declare function toBool(v: any): boolean;
12
- export declare function uuid(): string;
13
- export declare function protectedFields<T>(source: T, ...keys: (keyof T)[]): T;
14
- export declare function getProperties(obj: any): any;
1
+ export declare function deepMerge<T extends any>(base: T, ...from: T[]): T;
2
+ export declare function deepClone<T extends any>(obj: T): T;
3
+ export declare function pick<T extends object, K extends keyof T>(source: T, keys?: Iterable<K>, forced?: boolean): Pick<T, K>;
4
+ export declare function omit<T, K extends keyof T>(source: T, keys?: Iterable<K>): Omit<T, K>;
5
+ export interface Class {
6
+ new (...args: any[]): any;
7
+ }
8
+ export declare function Mixin(base: Class, ...classes: Class[]): Class;
9
+ export declare function toHump(action: string): string;
10
+ export declare function toLine(name: string): string;
11
+ export declare function toBool(v: any): boolean;
12
+ export declare function uuid(): string;
13
+ export declare function protectedFields<T>(source: T, ...keys: (keyof T)[]): T;
14
+ export declare function getProperties(obj: any): any;
package/lib/utils.js CHANGED
@@ -1,150 +1,150 @@
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.getProperties = exports.protectedFields = exports.uuid = exports.toBool = exports.toLine = exports.toHump = exports.Mixin = exports.omit = exports.pick = exports.deepClone = exports.deepMerge = void 0;
27
- const crypto = __importStar(require("crypto"));
28
- // 合并对象/数组
29
- function deepMerge(base, ...from) {
30
- if (from.length === 0) {
31
- return base;
32
- }
33
- if (typeof base !== 'object') {
34
- return base;
35
- }
36
- if (Array.isArray(base)) {
37
- return base.concat(...from);
38
- }
39
- for (const item of from) {
40
- for (const key in item) {
41
- if (base.hasOwnProperty(key)) {
42
- if (typeof base[key] === 'object') {
43
- // @ts-ignore
44
- base[key] = deepMerge(base[key], item[key]);
45
- }
46
- else {
47
- // @ts-ignore
48
- base[key] = item[key];
49
- }
50
- }
51
- else {
52
- // @ts-ignore
53
- base[key] = item[key];
54
- }
55
- }
56
- }
57
- return base;
58
- }
59
- exports.deepMerge = deepMerge;
60
- // 深拷贝
61
- function deepClone(obj) {
62
- if (typeof obj !== 'object')
63
- return obj;
64
- if (!obj)
65
- return obj;
66
- //判断拷贝的obj是对象还是数组
67
- if (Array.isArray(obj))
68
- return obj.map((item) => deepClone(item));
69
- const objClone = {};
70
- for (const key in obj) {
71
- if (obj.hasOwnProperty(key)) {
72
- if (obj[key] && typeof obj[key] === "object") {
73
- objClone[key] = deepClone(obj[key]);
74
- }
75
- else {
76
- objClone[key] = obj[key];
77
- }
78
- }
79
- }
80
- return objClone;
81
- }
82
- exports.deepClone = deepClone;
83
- function pick(source, keys, forced) {
84
- if (!keys)
85
- return { ...source };
86
- const result = {};
87
- for (const key of keys) {
88
- if (forced || key in source)
89
- result[key] = source[key];
90
- }
91
- return result;
92
- }
93
- exports.pick = pick;
94
- function omit(source, keys) {
95
- if (!keys)
96
- return { ...source };
97
- const result = { ...source };
98
- for (const key of keys) {
99
- Reflect.deleteProperty(result, key);
100
- }
101
- return result;
102
- }
103
- exports.omit = omit;
104
- function Mixin(base, ...classes) {
105
- classes.forEach(ctr => {
106
- Object.getOwnPropertyNames(ctr.prototype).forEach(name => {
107
- if (name === 'constructor')
108
- return;
109
- base.prototype[name] = ctr.prototype[name];
110
- });
111
- });
112
- return base;
113
- }
114
- exports.Mixin = Mixin;
115
- function toHump(action) {
116
- return action.replace(/_[\w]/g, (s) => {
117
- return s[1].toUpperCase();
118
- });
119
- }
120
- exports.toHump = toHump;
121
- function toLine(name) {
122
- return name.replace(/([A-Z])/g, "_$1").toLowerCase();
123
- }
124
- exports.toLine = toLine;
125
- function toBool(v) {
126
- if (v === "0" || v === "false")
127
- v = false;
128
- return Boolean(v);
129
- }
130
- exports.toBool = toBool;
131
- function uuid() {
132
- let hex = crypto.randomBytes(16).toString("hex");
133
- return hex.substr(0, 8) + "-" + hex.substr(8, 4) + "-" + hex.substr(12, 4) + "-" + hex.substr(16, 4) + "-" + hex.substr(20);
134
- }
135
- exports.uuid = uuid;
136
- function protectedFields(source, ...keys) {
137
- if (!source || typeof source !== 'object')
138
- throw new Error('source must is object');
139
- return Object.fromEntries(Object.entries(source).map(([key, value]) => {
140
- return [key, keys.includes(key) ? value.split('').map(c => '*').join('') : value];
141
- }));
142
- }
143
- exports.protectedFields = protectedFields;
144
- function getProperties(obj) {
145
- if (obj.__proto__ === null) { //说明该对象已经是最顶层的对象
146
- return [];
147
- }
148
- return Object.getOwnPropertyNames(obj).concat(getProperties(obj.__proto__));
149
- }
150
- exports.getProperties = getProperties;
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.getProperties = exports.protectedFields = exports.uuid = exports.toBool = exports.toLine = exports.toHump = exports.Mixin = exports.omit = exports.pick = exports.deepClone = exports.deepMerge = void 0;
27
+ const crypto = __importStar(require("crypto"));
28
+ // 合并对象/数组
29
+ function deepMerge(base, ...from) {
30
+ if (from.length === 0) {
31
+ return base;
32
+ }
33
+ if (typeof base !== 'object') {
34
+ return base;
35
+ }
36
+ if (Array.isArray(base)) {
37
+ return base.concat(...from);
38
+ }
39
+ for (const item of from) {
40
+ for (const key in item) {
41
+ if (base.hasOwnProperty(key)) {
42
+ if (typeof base[key] === 'object') {
43
+ // @ts-ignore
44
+ base[key] = deepMerge(base[key], item[key]);
45
+ }
46
+ else {
47
+ // @ts-ignore
48
+ base[key] = item[key];
49
+ }
50
+ }
51
+ else {
52
+ // @ts-ignore
53
+ base[key] = item[key];
54
+ }
55
+ }
56
+ }
57
+ return base;
58
+ }
59
+ exports.deepMerge = deepMerge;
60
+ // 深拷贝
61
+ function deepClone(obj) {
62
+ if (typeof obj !== 'object')
63
+ return obj;
64
+ if (!obj)
65
+ return obj;
66
+ //判断拷贝的obj是对象还是数组
67
+ if (Array.isArray(obj))
68
+ return obj.map((item) => deepClone(item));
69
+ const objClone = {};
70
+ for (const key in obj) {
71
+ if (obj.hasOwnProperty(key)) {
72
+ if (obj[key] && typeof obj[key] === "object") {
73
+ objClone[key] = deepClone(obj[key]);
74
+ }
75
+ else {
76
+ objClone[key] = obj[key];
77
+ }
78
+ }
79
+ }
80
+ return objClone;
81
+ }
82
+ exports.deepClone = deepClone;
83
+ function pick(source, keys, forced) {
84
+ if (!keys)
85
+ return { ...source };
86
+ const result = {};
87
+ for (const key of keys) {
88
+ if (forced || key in source)
89
+ result[key] = source[key];
90
+ }
91
+ return result;
92
+ }
93
+ exports.pick = pick;
94
+ function omit(source, keys) {
95
+ if (!keys)
96
+ return { ...source };
97
+ const result = { ...source };
98
+ for (const key of keys) {
99
+ Reflect.deleteProperty(result, key);
100
+ }
101
+ return result;
102
+ }
103
+ exports.omit = omit;
104
+ function Mixin(base, ...classes) {
105
+ classes.forEach(ctr => {
106
+ Object.getOwnPropertyNames(ctr.prototype).forEach(name => {
107
+ if (name === 'constructor')
108
+ return;
109
+ base.prototype[name] = ctr.prototype[name];
110
+ });
111
+ });
112
+ return base;
113
+ }
114
+ exports.Mixin = Mixin;
115
+ function toHump(action) {
116
+ return action.replace(/_[\w]/g, (s) => {
117
+ return s[1].toUpperCase();
118
+ });
119
+ }
120
+ exports.toHump = toHump;
121
+ function toLine(name) {
122
+ return name.replace(/([A-Z])/g, "_$1").toLowerCase();
123
+ }
124
+ exports.toLine = toLine;
125
+ function toBool(v) {
126
+ if (v === "0" || v === "false")
127
+ v = false;
128
+ return Boolean(v);
129
+ }
130
+ exports.toBool = toBool;
131
+ function uuid() {
132
+ let hex = crypto.randomBytes(16).toString("hex");
133
+ return hex.substr(0, 8) + "-" + hex.substr(8, 4) + "-" + hex.substr(12, 4) + "-" + hex.substr(16, 4) + "-" + hex.substr(20);
134
+ }
135
+ exports.uuid = uuid;
136
+ function protectedFields(source, ...keys) {
137
+ if (!source || typeof source !== 'object')
138
+ throw new Error('source must is object');
139
+ return Object.fromEntries(Object.entries(source).map(([key, value]) => {
140
+ return [key, keys.includes(key) ? value.split('').map(c => '*').join('') : value];
141
+ }));
142
+ }
143
+ exports.protectedFields = protectedFields;
144
+ function getProperties(obj) {
145
+ if (obj.__proto__ === null) { //说明该对象已经是最顶层的对象
146
+ return [];
147
+ }
148
+ return Object.getOwnPropertyNames(obj).concat(getProperties(obj.__proto__));
149
+ }
150
+ exports.getProperties = getProperties;
package/package.json CHANGED
@@ -1,58 +1,58 @@
1
- {
2
- "name": "onebots",
3
- "version": "0.0.14",
4
- "description": "基于oicq的多例oneBot实现",
5
- "main": "lib/index.js",
6
- "bin": {
7
- "onebots": "./lib/bin.js"
8
- },
9
- "scripts": {
10
- "start": "node .",
11
- "build": "tsc --project tsconfig.json && tsc-alias -p tsconfig.json",
12
- "dev": "ts-node-dev -r tsconfig-paths/register ./src/test.ts",
13
- "pub": "npm publish --access public",
14
- "test": "echo \"Error: no test specified\" && exit 1"
15
- },
16
- "repository": {
17
- "type": "git",
18
- "url": "git+https://github.com/liucl-cn/onebots.git"
19
- },
20
- "keywords": [
21
- "onebot",
22
- "oicq",
23
- "cq-http"
24
- ],
25
- "author": "凉菜",
26
- "license": "MIT",
27
- "bugs": {
28
- "url": "https://github.com/liucl-cn/onebots/issues"
29
- },
30
- "homepage": "https://github.com/liucl-cn/onebots#readme",
31
- "devDependencies": {
32
- "@types/koa": "^2.13.4",
33
- "@types/koa__router": "^8.0.11",
34
- "@types/koa-bodyparser": "^4.3.7",
35
- "@types/node": "latest",
36
- "@types/ws": "^8.5.3",
37
- "ts-node-dev": "latest",
38
- "tsc-alias": "latest",
39
- "tsconfig-paths": "latest",
40
- "typescript": "latest"
41
- },
42
- "files": [
43
- "/lib/**/*.js",
44
- "/lib/**/*.d.ts",
45
- "/lib/*.yaml",
46
- "/**/LICENSE"
47
- ],
48
- "dependencies": {
49
- "@koa/router": "^10.1.1",
50
- "js-yaml": "^4.1.0",
51
- "koa": "^2.13.4",
52
- "koa-bodyparser": "^4.3.0",
53
- "log4js": "^6.5.2",
54
- "oicq": "^2.3.1",
55
- "oicq2-cq-enable": "^1.0.6",
56
- "ws": "^8.8.0"
57
- }
58
- }
1
+ {
2
+ "name": "onebots",
3
+ "version": "0.0.15",
4
+ "description": "基于oicq的多例oneBot实现",
5
+ "main": "lib/index.js",
6
+ "bin": {
7
+ "onebots": "./lib/bin.js"
8
+ },
9
+ "scripts": {
10
+ "start": "node .",
11
+ "build": "tsc --project tsconfig.json && tsc-alias -p tsconfig.json",
12
+ "dev": "ts-node-dev -r tsconfig-paths/register ./src/test.ts",
13
+ "pub": "npm publish --access public",
14
+ "test": "echo \"Error: no test specified\" && exit 1"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/liucl-cn/onebots.git"
19
+ },
20
+ "keywords": [
21
+ "onebot",
22
+ "oicq",
23
+ "cq-http"
24
+ ],
25
+ "author": "凉菜",
26
+ "license": "MIT",
27
+ "bugs": {
28
+ "url": "https://github.com/liucl-cn/onebots/issues"
29
+ },
30
+ "homepage": "https://github.com/liucl-cn/onebots#readme",
31
+ "devDependencies": {
32
+ "@types/koa": "^2.13.4",
33
+ "@types/koa__router": "^8.0.11",
34
+ "@types/koa-bodyparser": "^4.3.7",
35
+ "@types/node": "latest",
36
+ "@types/ws": "^8.5.3",
37
+ "ts-node-dev": "latest",
38
+ "tsc-alias": "latest",
39
+ "tsconfig-paths": "latest",
40
+ "typescript": "latest"
41
+ },
42
+ "files": [
43
+ "/lib/**/*.js",
44
+ "/lib/**/*.d.ts",
45
+ "/lib/*.yaml",
46
+ "/**/LICENSE"
47
+ ],
48
+ "dependencies": {
49
+ "@koa/router": "^10.1.1",
50
+ "js-yaml": "^4.1.0",
51
+ "koa": "^2.13.4",
52
+ "koa-bodyparser": "^4.3.0",
53
+ "log4js": "^6.5.2",
54
+ "oicq": "^2.3.1",
55
+ "oicq2-cq-enable": "^1.0.6",
56
+ "ws": "^8.8.0"
57
+ }
58
+ }
@@ -1,31 +0,0 @@
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版本的通用配置