onebots 0.0.23 → 0.0.24
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/db.d.ts +1 -1
- package/lib/db.js +8 -20
- package/lib/service/V12/index.d.ts +3 -0
- package/lib/service/V12/index.js +3 -3
- package/package.json +1 -1
package/lib/db.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export declare class Db extends EventEmitter {
|
|
|
9
9
|
set(key: string, value: any, escape?: boolean): any;
|
|
10
10
|
has(key: string, escape?: boolean): boolean;
|
|
11
11
|
delete(key: string, escape?: boolean): boolean;
|
|
12
|
-
write():
|
|
12
|
+
write(): void;
|
|
13
13
|
}
|
|
14
14
|
export declare namespace Db {
|
|
15
15
|
interface Config {
|
package/lib/db.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Db = void 0;
|
|
4
4
|
const fs_1 = require("fs");
|
|
5
|
-
const promises_1 = require("fs/promises");
|
|
6
5
|
const events_1 = require("events");
|
|
7
6
|
class Db extends events_1.EventEmitter {
|
|
8
7
|
constructor(path, force_create = true) {
|
|
@@ -38,33 +37,22 @@ class Db extends events_1.EventEmitter {
|
|
|
38
37
|
throw new Error('不可达的位置:' + key.toString());
|
|
39
38
|
}
|
|
40
39
|
return result && typeof result === 'object' ? new Proxy(result, {
|
|
41
|
-
get(target, p) {
|
|
42
|
-
return target
|
|
40
|
+
get(target, p, receiver) {
|
|
41
|
+
return Reflect.get(target, p, receiver);
|
|
43
42
|
},
|
|
44
43
|
set(target, p, value, receiver) {
|
|
45
|
-
const result = target
|
|
46
|
-
_this.
|
|
44
|
+
const result = Reflect.set(target, p, value, receiver);
|
|
45
|
+
_this.set(`${key}.${value}`, value);
|
|
47
46
|
return result;
|
|
48
47
|
}
|
|
49
48
|
}) : result;
|
|
50
49
|
}
|
|
51
50
|
set(key, value, escape = true) {
|
|
52
51
|
const func = new Function('value', `return this.data.${key}=value`);
|
|
53
|
-
|
|
54
|
-
let result;
|
|
55
|
-
result = escape ? func.apply(this, [value]) : this.data[key] = value;
|
|
52
|
+
let result = escape ? func.apply(this, [value]) : this.data[key] = value;
|
|
56
53
|
this.raw_data = JSON.stringify(this.data, null, 2);
|
|
57
54
|
this.write();
|
|
58
|
-
return 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;
|
|
55
|
+
return result;
|
|
68
56
|
}
|
|
69
57
|
has(key, escape = true) {
|
|
70
58
|
return escape ? new Function(`return !!this.data.${key}`).apply(this) : !!this.data[key];
|
|
@@ -74,11 +62,11 @@ class Db extends events_1.EventEmitter {
|
|
|
74
62
|
this.write();
|
|
75
63
|
return result;
|
|
76
64
|
}
|
|
77
|
-
|
|
65
|
+
write() {
|
|
78
66
|
try {
|
|
79
67
|
const raw_data = JSON.stringify(this.data, null, 2);
|
|
80
68
|
if (raw_data !== this.raw_data) {
|
|
81
|
-
|
|
69
|
+
(0, fs_1.writeFileSync)(this.path, raw_data);
|
|
82
70
|
this.raw_data = raw_data;
|
|
83
71
|
}
|
|
84
72
|
}
|
|
@@ -34,6 +34,7 @@ export declare class V12 extends EventEmitter implements OneBot.Base {
|
|
|
34
34
|
self_id: number;
|
|
35
35
|
time: number;
|
|
36
36
|
detail_type: E;
|
|
37
|
+
type: string;
|
|
37
38
|
sub_type: string;
|
|
38
39
|
} & Omit<V12.BotEventMap[E], E>;
|
|
39
40
|
dispatch(data: Record<string, any>): void;
|
|
@@ -155,6 +156,7 @@ export declare namespace V12 {
|
|
|
155
156
|
type BotEventMap = {
|
|
156
157
|
system: Record<string, any>;
|
|
157
158
|
connect: {
|
|
159
|
+
type: any;
|
|
158
160
|
detail_type: 'connect';
|
|
159
161
|
version: ReturnType<Action['getVersion']>;
|
|
160
162
|
};
|
|
@@ -183,6 +185,7 @@ export declare namespace V12 {
|
|
|
183
185
|
self_id: number;
|
|
184
186
|
time: number;
|
|
185
187
|
detail_type: K;
|
|
188
|
+
type: string;
|
|
186
189
|
sub_type: string;
|
|
187
190
|
} & Omit<BotEventMap[K], K>;
|
|
188
191
|
}
|
package/lib/service/V12/index.js
CHANGED
|
@@ -478,7 +478,7 @@ class V12 extends events_1.EventEmitter {
|
|
|
478
478
|
};
|
|
479
479
|
if (config.access_token)
|
|
480
480
|
headers.Authorization = "Bearer " + config.access_token;
|
|
481
|
-
const ws = new ws_1.WebSocket(url, { headers });
|
|
481
|
+
const ws = new ws_1.WebSocket(url, '12.onebots.v0.0.15', { headers });
|
|
482
482
|
ws.on("error", (err) => {
|
|
483
483
|
this.logger.error(err.message);
|
|
484
484
|
});
|
|
@@ -618,14 +618,14 @@ exports.V12 = V12;
|
|
|
618
618
|
}
|
|
619
619
|
V12.error = error;
|
|
620
620
|
function formatPayload(uin, type, data) {
|
|
621
|
-
|
|
621
|
+
return {
|
|
622
622
|
self_id: uin,
|
|
623
623
|
time: Math.floor(Date.now() / 1000),
|
|
624
624
|
detail_type: type,
|
|
625
|
+
type: 'meta',
|
|
625
626
|
sub_type: '',
|
|
626
627
|
...data
|
|
627
628
|
};
|
|
628
|
-
return result;
|
|
629
629
|
}
|
|
630
630
|
V12.formatPayload = formatPayload;
|
|
631
631
|
})(V12 = exports.V12 || (exports.V12 = {}));
|