onebots 0.2.6 → 0.4.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.
- package/lib/config.sample.yaml +33 -0
- package/lib/db.d.ts +8 -9
- package/lib/db.js +38 -56
- package/lib/onebot.js +1 -1
- package/lib/server/app.js +2 -3
- package/lib/service/V11/index.d.ts +2 -1
- package/lib/service/V11/index.js +6 -5
- package/lib/service/V11/utils.js +16 -8
- package/lib/service/V12/action/common.d.ts +4 -2
- package/lib/service/V12/action/common.js +50 -0
- package/lib/service/V12/action/friend.js +1 -1
- package/lib/service/V12/action/group.js +1 -1
- package/lib/service/V12/action/guild.js +1 -1
- package/lib/service/V12/index.d.ts +19 -2
- package/lib/service/V12/index.js +29 -8
- package/lib/service/V12/utils.d.ts +2 -2
- package/lib/service/V12/utils.js +10 -0
- package/package.json +3 -2
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
port: 6727 # 监听端口
|
|
2
|
+
log_level: info # 日志等级
|
|
3
|
+
platform: 5 # 机器人客户端协议(1:Android 2:APad 3:Watch 4:IMac 5:IPad)
|
|
4
|
+
timeout: 30 #登录超时时间(秒)
|
|
5
|
+
general: # 通用配置,在单个配置省略时的默认值
|
|
6
|
+
V11: # oneBotV11的通用配置
|
|
7
|
+
heartbeat: 3 # 心跳间隔 (秒)
|
|
8
|
+
access_token: '' # 访问api的token
|
|
9
|
+
post_timeout: 15 # 上报超时时间,(秒)
|
|
10
|
+
secret: '' # 上报数据的sha1签名密钥
|
|
11
|
+
rate_limit_interval: 4 # ws心跳间隔(秒)
|
|
12
|
+
post_message_format: string # "string"或"array"
|
|
13
|
+
reconnect_interval: 3 # 重连间隔 (秒)
|
|
14
|
+
use_http: true # 是否使用 http
|
|
15
|
+
enable_cors: true # 是否允许跨域
|
|
16
|
+
use_ws: true # 是否使用websocket
|
|
17
|
+
http_reverse: [ ] # http上报地址
|
|
18
|
+
ws_reverse: [ ] # 反向ws连接地址
|
|
19
|
+
V12: # oneBotV12的通用配置
|
|
20
|
+
heartbeat: 3 # 心跳间隔 (秒)
|
|
21
|
+
access_token: '' # 访问api的token
|
|
22
|
+
request_timeout: 15 # 上报超时时间 (秒)
|
|
23
|
+
reconnect_interval: 3 # 重连间隔 (秒)
|
|
24
|
+
enable_cors: true # 是否允许跨域
|
|
25
|
+
use_http: true # 是否启用http
|
|
26
|
+
use_ws: true # 是否启用 websocket
|
|
27
|
+
webhook: [ ] # http 上报地址
|
|
28
|
+
ws_reverse: [ ] # 反向ws连接地址
|
|
29
|
+
# 每个账号的单独配置(用于覆盖通用配置)
|
|
30
|
+
123456789:
|
|
31
|
+
version: V11 # 使用的oneBot版本
|
|
32
|
+
password: abcedfghi # 账号密码,未配置则扫码登陆
|
|
33
|
+
# 。。。其他配置项参见上方对应oneBot版本的通用配置
|
package/lib/db.d.ts
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
import { Keys, Value } from "@zhinjs/shared";
|
|
2
|
+
export declare class Database<T extends object = object> {
|
|
2
3
|
private readonly path;
|
|
3
4
|
private data;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
get(key:
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
delete(key: string, escape?: boolean): boolean;
|
|
10
|
-
write(): void;
|
|
5
|
+
constructor(path: string);
|
|
6
|
+
sync(defaultValue: T): void;
|
|
7
|
+
get<K extends Keys<T>>(key: K): Value<T, K>;
|
|
8
|
+
delete<K extends Keys<T>>(key: K): boolean;
|
|
9
|
+
set<K extends Keys<T>>(key: K, value: Value<T, K>): void;
|
|
11
10
|
}
|
|
12
|
-
export declare namespace
|
|
11
|
+
export declare namespace Database {
|
|
13
12
|
interface Config {
|
|
14
13
|
path: string;
|
|
15
14
|
force?: boolean;
|
package/lib/db.js
CHANGED
|
@@ -1,76 +1,58 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.Database = void 0;
|
|
4
4
|
const fs_1 = require("fs");
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
const shared_1 = require("@zhinjs/shared");
|
|
6
|
+
class Database {
|
|
7
|
+
constructor(path) {
|
|
7
8
|
this.path = path;
|
|
8
9
|
this.data = {};
|
|
9
|
-
this.raw_data = '{}';
|
|
10
10
|
if (!this.path.toLowerCase().endsWith('.json'))
|
|
11
11
|
this.path = this.path + '.json';
|
|
12
|
-
if (!(0, fs_1.existsSync)(this.path)
|
|
13
|
-
(0, fs_1.writeFileSync)(this.path,
|
|
14
|
-
}
|
|
15
|
-
try {
|
|
16
|
-
const raw_data = (0, fs_1.readFileSync)(this.path, 'utf8');
|
|
17
|
-
this.raw_data = raw_data || this.raw_data;
|
|
18
|
-
this.data = JSON.parse(this.raw_data);
|
|
19
|
-
}
|
|
20
|
-
catch (error) {
|
|
21
|
-
const { message } = error;
|
|
22
|
-
if (!message.includes('ENOENT: no such file or directory')) {
|
|
23
|
-
throw error;
|
|
24
|
-
}
|
|
12
|
+
if (!(0, fs_1.existsSync)(this.path)) {
|
|
13
|
+
(0, fs_1.writeFileSync)(this.path, "", "utf-8");
|
|
25
14
|
}
|
|
26
15
|
}
|
|
27
|
-
|
|
28
|
-
const func = new Function(`return this.data.${key}`);
|
|
29
|
-
const _this = this;
|
|
30
|
-
let result;
|
|
16
|
+
sync(defaultValue) {
|
|
31
17
|
try {
|
|
32
|
-
|
|
18
|
+
this.data = JSON.parse((0, fs_1.readFileSync)(this.path, 'utf-8'));
|
|
33
19
|
}
|
|
34
20
|
catch {
|
|
35
|
-
|
|
21
|
+
this.data = defaultValue;
|
|
22
|
+
(0, fs_1.writeFileSync)(this.path, JSON.stringify(defaultValue, null, 2), "utf-8");
|
|
36
23
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
24
|
+
}
|
|
25
|
+
get(key) {
|
|
26
|
+
const value = (0, shared_1.getValue)(this.data, key);
|
|
27
|
+
if (typeof value !== 'object')
|
|
28
|
+
return value;
|
|
29
|
+
const saveValue = () => {
|
|
30
|
+
this.set(key, value);
|
|
31
|
+
};
|
|
32
|
+
return new Proxy(value, {
|
|
33
|
+
set(target, k, v) {
|
|
34
|
+
const res = Reflect.set(target, k, v);
|
|
35
|
+
saveValue();
|
|
36
|
+
return res;
|
|
37
|
+
},
|
|
38
|
+
deleteProperty(target, p) {
|
|
39
|
+
const res = Reflect.deleteProperty(target, p);
|
|
40
|
+
saveValue();
|
|
41
|
+
return res;
|
|
40
42
|
},
|
|
41
|
-
|
|
42
|
-
const res = Reflect.
|
|
43
|
-
|
|
43
|
+
defineProperty(target, p, r) {
|
|
44
|
+
const res = Reflect.defineProperty(target, p, r);
|
|
45
|
+
saveValue();
|
|
44
46
|
return res;
|
|
45
47
|
}
|
|
46
|
-
})
|
|
47
|
-
}
|
|
48
|
-
set(key, value, escape = true) {
|
|
49
|
-
const func = new Function('value', `return this.data.${key}=value`);
|
|
50
|
-
let result = escape ? func.apply(this, [value]) : this.data[key] = value;
|
|
51
|
-
this.write();
|
|
52
|
-
return result;
|
|
48
|
+
});
|
|
53
49
|
}
|
|
54
|
-
|
|
55
|
-
return
|
|
50
|
+
delete(key) {
|
|
51
|
+
return (0, shared_1.deleteValue)(this.data, key);
|
|
56
52
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
this.
|
|
60
|
-
return result;
|
|
61
|
-
}
|
|
62
|
-
write() {
|
|
63
|
-
try {
|
|
64
|
-
const raw_data = JSON.stringify(this.data);
|
|
65
|
-
if (raw_data !== this.raw_data) {
|
|
66
|
-
(0, fs_1.writeFileSync)(this.path, raw_data);
|
|
67
|
-
this.raw_data = raw_data;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
catch (error) {
|
|
71
|
-
this.data = JSON.parse(this.raw_data);
|
|
72
|
-
throw error;
|
|
73
|
-
}
|
|
53
|
+
set(key, value) {
|
|
54
|
+
(0, shared_1.setValue)(this.data, key, value);
|
|
55
|
+
return (0, fs_1.writeFileSync)(this.path, JSON.stringify(this.data, null, 2), 'utf-8');
|
|
74
56
|
}
|
|
75
57
|
}
|
|
76
|
-
exports.
|
|
58
|
+
exports.Database = Database;
|
package/lib/onebot.js
CHANGED
|
@@ -196,5 +196,5 @@ var OneBotStatus;
|
|
|
196
196
|
(function (OneBotStatus) {
|
|
197
197
|
OneBotStatus[OneBotStatus["Good"] = 0] = "Good";
|
|
198
198
|
OneBotStatus[OneBotStatus["Bad"] = 1] = "Bad";
|
|
199
|
-
})(OneBotStatus
|
|
199
|
+
})(OneBotStatus || (exports.OneBotStatus = OneBotStatus = {}));
|
|
200
200
|
exports.BOOLS = ["no_cache", "auto_escape", "as_long", "enable", "reject_add_request", "is_dismiss", "approve", "block"];
|
package/lib/server/app.js
CHANGED
|
@@ -202,10 +202,10 @@ class App extends koa_1.default {
|
|
|
202
202
|
}
|
|
203
203
|
}
|
|
204
204
|
}
|
|
205
|
+
exports.App = App;
|
|
205
206
|
_a = App;
|
|
206
207
|
App.configDir = path.join(os.homedir(), '.onebots');
|
|
207
208
|
App.configPath = path.join(_a.configDir, 'config.yaml');
|
|
208
|
-
exports.App = App;
|
|
209
209
|
function createApp(config = 'config.yaml') {
|
|
210
210
|
if (typeof config === 'string') {
|
|
211
211
|
config = path.resolve(process.cwd(), config);
|
|
@@ -241,5 +241,4 @@ exports.defineConfig = defineConfig;
|
|
|
241
241
|
},
|
|
242
242
|
log_level: 'info',
|
|
243
243
|
};
|
|
244
|
-
})(App
|
|
245
|
-
exports.App = App;
|
|
244
|
+
})(App || (exports.App = App = {}));
|
|
@@ -43,7 +43,7 @@ export declare class V11 extends EventEmitter implements OneBot.Base {
|
|
|
43
43
|
/**
|
|
44
44
|
* 创建反向ws
|
|
45
45
|
*/
|
|
46
|
-
protected _createWsr(url: string):
|
|
46
|
+
protected _createWsr(url: string): void;
|
|
47
47
|
/**
|
|
48
48
|
* 快速操作
|
|
49
49
|
*/
|
|
@@ -83,6 +83,7 @@ export declare namespace V11 {
|
|
|
83
83
|
access_token?: string;
|
|
84
84
|
post_timeout?: number;
|
|
85
85
|
enable_cors?: boolean;
|
|
86
|
+
enable_reissue?: boolean;
|
|
86
87
|
rate_limit_interval?: number;
|
|
87
88
|
post_message_format?: 'string' | 'array';
|
|
88
89
|
heartbeat?: number;
|
package/lib/service/V11/index.js
CHANGED
|
@@ -161,12 +161,13 @@ class V11 extends events_1.EventEmitter {
|
|
|
161
161
|
});
|
|
162
162
|
}
|
|
163
163
|
startWsReverse(url) {
|
|
164
|
-
|
|
164
|
+
this._createWsr(url);
|
|
165
165
|
this.on('dispatch', (serialized) => {
|
|
166
|
-
|
|
166
|
+
for (const ws of this.wsr) {
|
|
167
167
|
ws.send(serialized, (err) => {
|
|
168
|
-
if (err)
|
|
168
|
+
if (err) {
|
|
169
169
|
this.logger.error(`反向WS(${ws.url})上报事件失败: ` + err.message);
|
|
170
|
+
}
|
|
170
171
|
else
|
|
171
172
|
this.logger.debug(`反向WS(${ws.url})上报事件成功: ` + serialized);
|
|
172
173
|
});
|
|
@@ -331,7 +332,6 @@ class V11 extends events_1.EventEmitter {
|
|
|
331
332
|
this._createWsr(url);
|
|
332
333
|
}, this.config.reconnect_interval * 1000);
|
|
333
334
|
});
|
|
334
|
-
return ws;
|
|
335
335
|
}
|
|
336
336
|
/**
|
|
337
337
|
* 快速操作
|
|
@@ -491,6 +491,7 @@ exports.V11 = V11;
|
|
|
491
491
|
reconnect_interval: 3,
|
|
492
492
|
use_http: true,
|
|
493
493
|
enable_cors: true,
|
|
494
|
+
enable_reissue: false,
|
|
494
495
|
use_ws: true,
|
|
495
496
|
http_reverse: [],
|
|
496
497
|
ws_reverse: []
|
|
@@ -505,4 +506,4 @@ exports.V11 = V11;
|
|
|
505
506
|
};
|
|
506
507
|
}
|
|
507
508
|
V11.genMetaEvent = genMetaEvent;
|
|
508
|
-
})(V11
|
|
509
|
+
})(V11 || (exports.V11 = V11 = {}));
|
package/lib/service/V11/utils.js
CHANGED
|
@@ -4,16 +4,24 @@ exports.processMessage = void 0;
|
|
|
4
4
|
const utils_1 = require("../../utils");
|
|
5
5
|
const utils_2 = require("icqq-cq-enable/lib/utils");
|
|
6
6
|
async function processMessage(message, source) {
|
|
7
|
-
const
|
|
8
|
-
let quote =
|
|
7
|
+
const elements = typeof message === 'string' ? (0, utils_2.fromCqcode)(message) : (0, utils_2.fromSegment)(message);
|
|
8
|
+
let quote = elements.find(e => e.type === 'reply');
|
|
9
9
|
if (quote)
|
|
10
|
-
(0, utils_1.remove)(
|
|
11
|
-
let music =
|
|
10
|
+
(0, utils_1.remove)(elements, quote);
|
|
11
|
+
let music = elements.find(e => e.type === 'music');
|
|
12
12
|
if (music)
|
|
13
|
-
(0, utils_1.remove)(
|
|
14
|
-
let share =
|
|
13
|
+
(0, utils_1.remove)(elements, music);
|
|
14
|
+
let share = elements.find(e => e.type === 'share');
|
|
15
15
|
if (share)
|
|
16
|
-
(0, utils_1.remove)(
|
|
17
|
-
|
|
16
|
+
(0, utils_1.remove)(elements, share);
|
|
17
|
+
for (const element of elements) {
|
|
18
|
+
if (['image', 'video', 'audio'].includes(element.type)) {
|
|
19
|
+
if (element['file_id']?.startsWith('base64://'))
|
|
20
|
+
element['file_id'] = Buffer.from(element['file_id'].slice(9), 'base64');
|
|
21
|
+
if (element['file']?.startsWith('base64://'))
|
|
22
|
+
element['file'] = Buffer.from(element['file'].slice(9), 'base64');
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return { element: elements, quote: quote || source, share, music };
|
|
18
26
|
}
|
|
19
27
|
exports.processMessage = processMessage;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { V12 } from '../../../service/V12';
|
|
2
2
|
import { Action } from "./";
|
|
3
|
-
import { V11 } from "../../../service/V11";
|
|
4
3
|
export declare class CommonAction {
|
|
5
4
|
sendMessage(): void;
|
|
6
5
|
/**
|
|
@@ -18,7 +17,7 @@ export declare class CommonAction {
|
|
|
18
17
|
* 获取 Cookies
|
|
19
18
|
* @param domain {string} 域名
|
|
20
19
|
*/
|
|
21
|
-
getCookies(this:
|
|
20
|
+
getCookies(this: V12, domain: string): string;
|
|
22
21
|
getStatus(this: V12): {
|
|
23
22
|
good: boolean;
|
|
24
23
|
bots: {
|
|
@@ -40,4 +39,7 @@ export declare class CommonAction {
|
|
|
40
39
|
login(this: V12, password?: string): Promise<unknown>;
|
|
41
40
|
logout(this: V12, keepalive?: boolean): Promise<unknown>;
|
|
42
41
|
getSupportedActions(this: V12): string[];
|
|
42
|
+
uploadFile(this: V12, type: 'url' | 'path' | 'data', name: string, url?: string, path?: string, data?: string, sha256?: string, headers?: Record<string, any>): string;
|
|
43
|
+
uploadFileFragmented(this: V12, stage: 'prepare' | 'transfer' | 'finish', name?: string, total_size?: number, file_id?: string, offset?: number, data?: string, sha256?: string): string | true;
|
|
44
|
+
getFile(this: V12, file_id: string): V12.FileInfo;
|
|
43
45
|
}
|
|
@@ -5,6 +5,8 @@ const icqq_1 = require("icqq");
|
|
|
5
5
|
const utils_1 = require("../../../utils");
|
|
6
6
|
const onebot_1 = require("../../../onebot");
|
|
7
7
|
const utils_2 = require("../../../utils");
|
|
8
|
+
const crypto_1 = require("crypto");
|
|
9
|
+
const sha = (data) => (0, crypto_1.createHash)("sha1").update(data).digest();
|
|
8
10
|
class CommonAction {
|
|
9
11
|
sendMessage() { }
|
|
10
12
|
/**
|
|
@@ -119,5 +121,53 @@ class CommonAction {
|
|
|
119
121
|
return key !== 'constructor';
|
|
120
122
|
}).map(utils_2.toLine);
|
|
121
123
|
}
|
|
124
|
+
uploadFile(type, name, url, path, data, sha256, headers) {
|
|
125
|
+
const fileInfo = {
|
|
126
|
+
name,
|
|
127
|
+
url,
|
|
128
|
+
type,
|
|
129
|
+
path,
|
|
130
|
+
data,
|
|
131
|
+
sha256,
|
|
132
|
+
headers
|
|
133
|
+
};
|
|
134
|
+
return this.saveFile(fileInfo);
|
|
135
|
+
}
|
|
136
|
+
uploadFileFragmented(stage, name, total_size, file_id, offset, data, sha256) {
|
|
137
|
+
switch (stage) {
|
|
138
|
+
case "prepare": {
|
|
139
|
+
if (!name || !total_size)
|
|
140
|
+
throw new Error('请输入name和total_size');
|
|
141
|
+
return this.saveFile({
|
|
142
|
+
name,
|
|
143
|
+
type: 'data',
|
|
144
|
+
total_size,
|
|
145
|
+
data: Buffer.alloc(0).toString('base64')
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
case "transfer": {
|
|
149
|
+
if (!file_id || !offset || !data)
|
|
150
|
+
throw new Error('请输入file_id、offset和data');
|
|
151
|
+
const fileInfo = this.getFile(file_id);
|
|
152
|
+
fileInfo.data = Buffer.concat([
|
|
153
|
+
Buffer.from(fileInfo.data),
|
|
154
|
+
Buffer.from(data)
|
|
155
|
+
]).toString('base64');
|
|
156
|
+
return true;
|
|
157
|
+
}
|
|
158
|
+
case "finish": {
|
|
159
|
+
if (!file_id || sha256)
|
|
160
|
+
throw new Error('请输入file_id和sha256');
|
|
161
|
+
const fileInfo = this.getFile(file_id);
|
|
162
|
+
if (sha(Buffer.from(fileInfo.data)).toString('hex') === sha256)
|
|
163
|
+
return file_id;
|
|
164
|
+
this.delFile(file_id);
|
|
165
|
+
throw new Error('文件已被篡改');
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
getFile(file_id) {
|
|
170
|
+
return this.getFile(file_id);
|
|
171
|
+
}
|
|
122
172
|
}
|
|
123
173
|
exports.CommonAction = CommonAction;
|
|
@@ -16,7 +16,7 @@ class FriendAction {
|
|
|
16
16
|
* @param source {import('onebots/lib/service/v12').SegmentElem<'reply'>} 引用内容
|
|
17
17
|
*/
|
|
18
18
|
async sendPrivateMsg(user_id, message, source) {
|
|
19
|
-
let { element, quote, music, share } = await utils_1.processMessage.apply(this
|
|
19
|
+
let { element, quote, music, share } = await utils_1.processMessage.apply(this, [message, source]);
|
|
20
20
|
if (music)
|
|
21
21
|
await this.client.pickFriend(user_id).shareMusic(music.data.platform, music.data.id);
|
|
22
22
|
if (share)
|
|
@@ -10,7 +10,7 @@ class GroupAction {
|
|
|
10
10
|
* @param source {import('onebots/lib/service/v12').SegmentElem<'reply'>} 引用内容
|
|
11
11
|
*/
|
|
12
12
|
async sendGroupMsg(group_id, message, source) {
|
|
13
|
-
let { element, quote, music, share } = await utils_1.processMessage.apply(this
|
|
13
|
+
let { element, quote, music, share } = await utils_1.processMessage.apply(this, [message, source]);
|
|
14
14
|
if (music)
|
|
15
15
|
await this.client.pickGroup(group_id).shareMusic(music.data.platform, music.data.id);
|
|
16
16
|
if (share)
|
|
@@ -19,7 +19,7 @@ class GuildAction {
|
|
|
19
19
|
* @param message {import('icqq/lib/service').Sendable} 消息
|
|
20
20
|
*/
|
|
21
21
|
async sendGuildMsg(guild_id, channel_id, message) {
|
|
22
|
-
const { element } = await utils_1.processMessage.apply(this
|
|
22
|
+
const { element } = await utils_1.processMessage.apply(this, [message]);
|
|
23
23
|
if (!element.length)
|
|
24
24
|
return;
|
|
25
25
|
return await this.client.sendGuildMsg(guild_id, channel_id, element);
|
|
@@ -22,7 +22,13 @@ export declare class V12 extends EventEmitter implements OneBot.Base {
|
|
|
22
22
|
private db;
|
|
23
23
|
constructor(oneBot: OneBot<'V12'>, client: Client, config: V12.Config);
|
|
24
24
|
get history(): V12.Payload<keyof Action>[];
|
|
25
|
-
|
|
25
|
+
getFile(file_id: string): V12.FileInfo;
|
|
26
|
+
delFile(file_id: string): boolean;
|
|
27
|
+
saveFile(fileInfo: V12.FileInfo): string;
|
|
28
|
+
get files(): ({
|
|
29
|
+
file_id: string;
|
|
30
|
+
} & V12.FileInfo)[];
|
|
31
|
+
set history(value: any[]);
|
|
26
32
|
start(path?: string): void;
|
|
27
33
|
private startHttp;
|
|
28
34
|
private startWebhook;
|
|
@@ -47,7 +53,7 @@ export declare class V12 extends EventEmitter implements OneBot.Base {
|
|
|
47
53
|
/**
|
|
48
54
|
* 创建反向ws
|
|
49
55
|
*/
|
|
50
|
-
protected _createWsr(url: string, config: V12.WsReverseConfig):
|
|
56
|
+
protected _createWsr(url: string, config: V12.WsReverseConfig): void;
|
|
51
57
|
/**
|
|
52
58
|
* 处理ws消息
|
|
53
59
|
*/
|
|
@@ -132,6 +138,7 @@ export declare namespace V12 {
|
|
|
132
138
|
request_timeout?: number;
|
|
133
139
|
reconnect_interval?: number;
|
|
134
140
|
enable_cors?: boolean;
|
|
141
|
+
enable_reissue?: boolean;
|
|
135
142
|
use_http?: boolean | HttpConfig;
|
|
136
143
|
webhook?: (string | WebhookConfig)[];
|
|
137
144
|
use_ws?: boolean | WsConfig;
|
|
@@ -220,4 +227,14 @@ export declare namespace V12 {
|
|
|
220
227
|
params: Record<string, any>;
|
|
221
228
|
echo?: number;
|
|
222
229
|
};
|
|
230
|
+
type FileInfo = {
|
|
231
|
+
type: 'url' | 'path' | 'data';
|
|
232
|
+
name: string;
|
|
233
|
+
url?: string;
|
|
234
|
+
headers?: Record<string, any>;
|
|
235
|
+
path?: string;
|
|
236
|
+
data?: string;
|
|
237
|
+
sha256?: string;
|
|
238
|
+
total_size?: number;
|
|
239
|
+
};
|
|
223
240
|
}
|
package/lib/service/V12/index.js
CHANGED
|
@@ -28,15 +28,35 @@ class V12 extends events_1.EventEmitter {
|
|
|
28
28
|
this.version = 'V12';
|
|
29
29
|
this.timestamp = Date.now();
|
|
30
30
|
this.wsr = new Set();
|
|
31
|
-
this.db = new db_1.
|
|
32
|
-
|
|
33
|
-
this.history = [];
|
|
31
|
+
this.db = new db_1.Database((0, path_1.join)(app_1.App.configDir, 'data', this.oneBot.uin + '.json'));
|
|
32
|
+
this.db.sync({ eventBuffer: [], files: {} });
|
|
34
33
|
this.action = new action_1.Action();
|
|
35
34
|
this.logger = this.oneBot.app.getLogger(this.oneBot.uin, this.version);
|
|
36
35
|
}
|
|
37
36
|
get history() {
|
|
38
37
|
return this.db.get('eventBuffer');
|
|
39
38
|
}
|
|
39
|
+
getFile(file_id) {
|
|
40
|
+
return this.db.get(`files.${file_id}`);
|
|
41
|
+
}
|
|
42
|
+
delFile(file_id) {
|
|
43
|
+
const files = this.db.get(`files`);
|
|
44
|
+
return delete files[file_id];
|
|
45
|
+
}
|
|
46
|
+
saveFile(fileInfo) {
|
|
47
|
+
const file_id = (0, utils_2.uuid)();
|
|
48
|
+
this.db.set(`files.${file_id}`, fileInfo);
|
|
49
|
+
return file_id;
|
|
50
|
+
}
|
|
51
|
+
get files() {
|
|
52
|
+
const files = this.db.get('files');
|
|
53
|
+
return Object.keys(files).map((file_id) => {
|
|
54
|
+
return {
|
|
55
|
+
file_id,
|
|
56
|
+
...files[file_id]
|
|
57
|
+
};
|
|
58
|
+
});
|
|
59
|
+
}
|
|
40
60
|
set history(value) {
|
|
41
61
|
this.db.set('eventBuffer', value);
|
|
42
62
|
}
|
|
@@ -250,10 +270,10 @@ class V12 extends events_1.EventEmitter {
|
|
|
250
270
|
});
|
|
251
271
|
}
|
|
252
272
|
startWsReverse(config) {
|
|
253
|
-
|
|
273
|
+
this._createWsr(config.url, config);
|
|
254
274
|
this.on('dispatch', (unserialized) => {
|
|
255
275
|
const serialized = JSON.stringify(unserialized);
|
|
256
|
-
|
|
276
|
+
for (const ws of this.wsr) {
|
|
257
277
|
ws.send(serialized, (err) => {
|
|
258
278
|
if (err)
|
|
259
279
|
this.logger.error(`反向WS(${ws.url})上报事件失败: ` + err.message);
|
|
@@ -360,7 +380,7 @@ class V12 extends events_1.EventEmitter {
|
|
|
360
380
|
action = "send_" + params.detail_type + "_msg";
|
|
361
381
|
}
|
|
362
382
|
else if (params.user_id)
|
|
363
|
-
action = "
|
|
383
|
+
action = "send_private_Msg";
|
|
364
384
|
else if (params.group_id)
|
|
365
385
|
action = "send_group_msg";
|
|
366
386
|
else if (params.discuss_id)
|
|
@@ -387,6 +407,7 @@ class V12 extends events_1.EventEmitter {
|
|
|
387
407
|
}
|
|
388
408
|
let ret, result;
|
|
389
409
|
try {
|
|
410
|
+
console.log(method, args);
|
|
390
411
|
ret = this.action[method].apply(this, args);
|
|
391
412
|
}
|
|
392
413
|
catch (e) {
|
|
@@ -521,7 +542,6 @@ class V12 extends events_1.EventEmitter {
|
|
|
521
542
|
this.startWsReverse(config);
|
|
522
543
|
}, this.config.reconnect_interval * 1000);
|
|
523
544
|
});
|
|
524
|
-
return ws;
|
|
525
545
|
}
|
|
526
546
|
/**
|
|
527
547
|
* 处理ws消息
|
|
@@ -637,6 +657,7 @@ exports.V12 = V12;
|
|
|
637
657
|
request_timeout: 15,
|
|
638
658
|
reconnect_interval: 3,
|
|
639
659
|
enable_cors: true,
|
|
660
|
+
enable_reissue: false,
|
|
640
661
|
use_http: true,
|
|
641
662
|
use_ws: true,
|
|
642
663
|
webhook: [],
|
|
@@ -673,4 +694,4 @@ exports.V12 = V12;
|
|
|
673
694
|
};
|
|
674
695
|
}
|
|
675
696
|
V12.formatPayload = formatPayload;
|
|
676
|
-
})(V12
|
|
697
|
+
})(V12 || (exports.V12 = V12 = {}));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MessageElem } from "icqq";
|
|
2
2
|
import { V12 } from "../../service/V12";
|
|
3
|
-
export declare function processMessage(this:
|
|
3
|
+
export declare function processMessage(this: V12, message: V12.Sendable, source?: V12.SegmentElem<'reply'>): Promise<{
|
|
4
4
|
element: MessageElem[];
|
|
5
5
|
music?: V12.SegmentElem<'music'>;
|
|
6
6
|
share?: V12.SegmentElem<'share'>;
|
package/lib/service/V12/utils.js
CHANGED
|
@@ -25,6 +25,16 @@ async function processMessage(message, source) {
|
|
|
25
25
|
'forward', 'node',
|
|
26
26
|
'music', 'share', 'xml', 'json', 'location', // 分享类
|
|
27
27
|
].includes(n.type));
|
|
28
|
+
segments.forEach(seg => {
|
|
29
|
+
if (['image', 'video', 'audio'].includes(seg.type)) {
|
|
30
|
+
const { file_id } = seg.data;
|
|
31
|
+
const fileInfo = this.getFile(file_id);
|
|
32
|
+
if (fileInfo)
|
|
33
|
+
seg.data['file_id'] = fileInfo.url || fileInfo.path || `base64://${fileInfo.data}`;
|
|
34
|
+
if (seg.data['file_id']?.startsWith('base64://'))
|
|
35
|
+
seg.data['file_id'] = Buffer.from(seg.data['file_id'].slice(9), 'base64');
|
|
36
|
+
}
|
|
37
|
+
});
|
|
28
38
|
const element = V12_1.V12.fromSegment(segments);
|
|
29
39
|
return { element, quote: quote || source, share, music };
|
|
30
40
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "onebots",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "基于icqq的多例oneBot实现",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=16"
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
},
|
|
12
12
|
"scripts": {
|
|
13
13
|
"start": "node .",
|
|
14
|
-
"build": "tsc --project tsconfig.json && tsc-alias -p tsconfig.json",
|
|
14
|
+
"build": "tsc --project tsconfig.json && tsc-alias -p tsconfig.json && cp -r src/config.sample.yaml lib/config.sample.yaml",
|
|
15
15
|
"dev": "ts-node-dev -r tsconfig-paths/register ./src/bin.ts -c config.yaml",
|
|
16
16
|
"pub": "npm publish --access public",
|
|
17
17
|
"docs:dev": "vitepress dev docs --port 8989",
|
|
@@ -54,6 +54,7 @@
|
|
|
54
54
|
],
|
|
55
55
|
"dependencies": {
|
|
56
56
|
"@koa/router": "^10.1.1",
|
|
57
|
+
"@zhinjs/shared": "^0.0.9",
|
|
57
58
|
"icqq": "^0.3.6",
|
|
58
59
|
"icqq-cq-enable": "^1.0.0",
|
|
59
60
|
"js-yaml": "^4.1.0",
|