onebots 0.0.18 → 0.0.19
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/onebot.d.ts +1 -1
- package/lib/onebot.js +8 -10
- package/lib/service/V11/index.d.ts +1 -0
- package/lib/service/V11/index.js +3 -0
- package/lib/service/V12/action/common.d.ts +1 -0
- package/lib/service/V12/action/common.js +1 -0
- package/lib/service/V12/index.d.ts +7 -3
- package/lib/service/V12/index.js +34 -29
- package/package.json +1 -1
package/lib/onebot.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ export declare class OneBot<V extends OneBot.Version> extends EventEmitter {
|
|
|
21
21
|
start(): Promise<void>;
|
|
22
22
|
startListen(): void;
|
|
23
23
|
stop(force?: boolean): Promise<void>;
|
|
24
|
-
dispatch(data: any): void;
|
|
24
|
+
dispatch(event: any, data: any): void;
|
|
25
25
|
}
|
|
26
26
|
export declare enum OneBotStatus {
|
|
27
27
|
Good = 0,
|
package/lib/onebot.js
CHANGED
|
@@ -101,10 +101,10 @@ class OneBot extends events_1.EventEmitter {
|
|
|
101
101
|
await this.client.login(this.password);
|
|
102
102
|
}
|
|
103
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));
|
|
104
|
+
this.client.on('system', this.dispatch.bind(this, 'system'));
|
|
105
|
+
this.client.on('notice', this.dispatch.bind(this, 'notice'));
|
|
106
|
+
this.client.on('request', this.dispatch.bind(this, 'request'));
|
|
107
|
+
this.client.on('message', this.dispatch.bind(this, 'message'));
|
|
108
108
|
for (const instance of this.instances) {
|
|
109
109
|
instance.start(this.instances.length > 1 ? '/' + instance.version : undefined);
|
|
110
110
|
}
|
|
@@ -113,14 +113,12 @@ class OneBot extends events_1.EventEmitter {
|
|
|
113
113
|
for (const instance of this.instances) {
|
|
114
114
|
await instance.stop(force);
|
|
115
115
|
}
|
|
116
|
-
this.client.
|
|
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));
|
|
116
|
+
this.client.removeAllListeners();
|
|
120
117
|
}
|
|
121
|
-
dispatch(data) {
|
|
118
|
+
dispatch(event, data) {
|
|
122
119
|
for (const instance of this.instances) {
|
|
123
|
-
instance.
|
|
120
|
+
const result = instance.format(event, data);
|
|
121
|
+
instance.dispatch(result);
|
|
124
122
|
}
|
|
125
123
|
}
|
|
126
124
|
}
|
|
@@ -33,6 +33,7 @@ export declare class V11 extends EventEmitter implements OneBot.Base {
|
|
|
33
33
|
private startWs;
|
|
34
34
|
private startWsReverse;
|
|
35
35
|
stop(force?: boolean): Promise<void>;
|
|
36
|
+
format(_: any, data: any): any;
|
|
36
37
|
dispatch(data: any): void;
|
|
37
38
|
private _httpRequestHandler;
|
|
38
39
|
/**
|
package/lib/service/V11/index.js
CHANGED
|
@@ -29,6 +29,12 @@ export declare class V12 extends EventEmitter implements OneBot.Base {
|
|
|
29
29
|
private startWs;
|
|
30
30
|
private startWsReverse;
|
|
31
31
|
stop(force?: boolean): Promise<void>;
|
|
32
|
+
format<E extends keyof V12.BotEventMap>(event: E, ...args: [V12.BotEventMap[E]]): {
|
|
33
|
+
self_id: number;
|
|
34
|
+
time: number;
|
|
35
|
+
detail_type: E;
|
|
36
|
+
sub_type: string;
|
|
37
|
+
} & Omit<V12.BotEventMap[E], E>;
|
|
32
38
|
dispatch(data: Record<string, any>): void;
|
|
33
39
|
apply(req: any): Promise<string>;
|
|
34
40
|
private _httpRequestHandler;
|
|
@@ -162,11 +168,9 @@ export declare namespace V12 {
|
|
|
162
168
|
};
|
|
163
169
|
function success<T extends any>(data: T, retcode?: Result<T>['retcode'], echo?: string): Result<T>;
|
|
164
170
|
function error(message: string, retcode?: Result<null>['retcode'], echo?: string): Result<null>;
|
|
165
|
-
function
|
|
171
|
+
function formatPayload<K extends keyof BotEventMap>(uin: number, type: K, data: Omit<BotEventMap[K], K>): {
|
|
166
172
|
self_id: number;
|
|
167
173
|
time: number;
|
|
168
|
-
type: string;
|
|
169
|
-
status: string;
|
|
170
174
|
detail_type: K;
|
|
171
175
|
sub_type: string;
|
|
172
176
|
} & Omit<BotEventMap[K], K>;
|
package/lib/service/V12/index.js
CHANGED
|
@@ -87,7 +87,7 @@ class V12 extends events_1.EventEmitter {
|
|
|
87
87
|
});
|
|
88
88
|
if (this.config.heartbeat) {
|
|
89
89
|
this.heartbeat = setInterval(() => {
|
|
90
|
-
this.dispatch(V12.
|
|
90
|
+
this.dispatch(V12.formatPayload(this.client.uin, 'heartbeat', {
|
|
91
91
|
detail_type: "heartbeat",
|
|
92
92
|
interval: new Date().getTime() + this.config.heartbeat * 1000
|
|
93
93
|
}));
|
|
@@ -208,11 +208,11 @@ class V12 extends events_1.EventEmitter {
|
|
|
208
208
|
(0, fs_1.rmSync)(this.client.dir, { force: true, recursive: true });
|
|
209
209
|
}
|
|
210
210
|
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
data = { args: data || [] };
|
|
211
|
+
format(event, ...args) {
|
|
212
|
+
const data = (typeof args[0]) === 'object' ? args.shift() || {} : {};
|
|
214
213
|
data.type = data.post_type;
|
|
215
214
|
if (!data.type) {
|
|
215
|
+
data.type = 'meta';
|
|
216
216
|
data.detail_type = 'online';
|
|
217
217
|
if (data.image) {
|
|
218
218
|
data.type = 'login';
|
|
@@ -230,6 +230,28 @@ class V12 extends events_1.EventEmitter {
|
|
|
230
230
|
data.detial_type = 'error';
|
|
231
231
|
}
|
|
232
232
|
}
|
|
233
|
+
if (data.type === 'notice') {
|
|
234
|
+
switch (data.detail_type) {
|
|
235
|
+
case 'friend':
|
|
236
|
+
data.detail_type += data.sub_type;
|
|
237
|
+
break;
|
|
238
|
+
case 'group':
|
|
239
|
+
if (['increase', 'decrease'].includes(data.sub_type))
|
|
240
|
+
data.detail_type = 'group_member_' + data.sub_type;
|
|
241
|
+
else if (data.sub_type === 'recall')
|
|
242
|
+
data.detail_type = 'group_message_delete';
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
if (data.type === 'system')
|
|
246
|
+
data.type = 'meta';
|
|
247
|
+
data.alt_message = data.raw_message;
|
|
248
|
+
data.self = this.action.getSelfInfo.apply(this);
|
|
249
|
+
if (!data.detail_type)
|
|
250
|
+
data.detail_type = data.message_type || data.notice_type || data.request_type || data.system_type;
|
|
251
|
+
data.message = data.type === 'message' ? V12.toSegment(data.message) : data.message;
|
|
252
|
+
return V12.formatPayload(this.client.uin, event, data);
|
|
253
|
+
}
|
|
254
|
+
dispatch(data) {
|
|
233
255
|
const payload = {
|
|
234
256
|
id: (0, utils_1.uuid)(),
|
|
235
257
|
impl: 'oicq_onebot',
|
|
@@ -239,24 +261,8 @@ class V12 extends events_1.EventEmitter {
|
|
|
239
261
|
platform: 'qq',
|
|
240
262
|
user_id: `${this.client.uin}`
|
|
241
263
|
},
|
|
242
|
-
|
|
243
|
-
detail_type: data.message_type || data.notice_type || data.request_type || data.system_type,
|
|
244
|
-
...V12.genMetaEvent(this.client.uin, data.type, data),
|
|
245
|
-
message: data.type === 'message' ? V12.toSegment(data.message) : data.message,
|
|
246
|
-
type: data.type || 'meta',
|
|
264
|
+
...data,
|
|
247
265
|
};
|
|
248
|
-
if (payload.type === 'notice') {
|
|
249
|
-
switch (payload.detail_type) {
|
|
250
|
-
case 'friend':
|
|
251
|
-
payload.detail_type += payload.sub_type;
|
|
252
|
-
break;
|
|
253
|
-
case 'group':
|
|
254
|
-
if (['increase', 'decrease'].includes(payload.sub_type))
|
|
255
|
-
payload.detail_type = 'group_member_' + payload.sub_type;
|
|
256
|
-
else if (payload.sub_type === 'recall')
|
|
257
|
-
payload.detail_type = 'group_message_delete';
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
266
|
this.emit('dispatch', payload);
|
|
261
267
|
}
|
|
262
268
|
async apply(req) {
|
|
@@ -265,7 +271,7 @@ class V12 extends events_1.EventEmitter {
|
|
|
265
271
|
let is_async = action.includes("_async");
|
|
266
272
|
if (is_async)
|
|
267
273
|
action = action.replace("_async", "");
|
|
268
|
-
if (action === '
|
|
274
|
+
if (action === 'send_message') {
|
|
269
275
|
if (["private", "group", "discuss", 'channel'].includes(params.detail_type)) {
|
|
270
276
|
action = "send_" + params.detail_type + "_msg";
|
|
271
277
|
}
|
|
@@ -483,8 +489,8 @@ class V12 extends events_1.EventEmitter {
|
|
|
483
489
|
}));
|
|
484
490
|
}
|
|
485
491
|
});
|
|
486
|
-
this.dispatch(V12.
|
|
487
|
-
this.dispatch(V12.
|
|
492
|
+
this.dispatch(V12.formatPayload(this.client.uin, "connect", this.action.getVersion.apply(this)));
|
|
493
|
+
this.dispatch(V12.formatPayload(this.client.uin, "status_update", this.action.getStatus.apply(this)));
|
|
488
494
|
}
|
|
489
495
|
}
|
|
490
496
|
exports.V12 = V12;
|
|
@@ -553,16 +559,15 @@ exports.V12 = V12;
|
|
|
553
559
|
};
|
|
554
560
|
}
|
|
555
561
|
V12.error = error;
|
|
556
|
-
function
|
|
557
|
-
|
|
562
|
+
function formatPayload(uin, type, data) {
|
|
563
|
+
const result = {
|
|
558
564
|
self_id: uin,
|
|
559
565
|
time: Math.floor(Date.now() / 1000),
|
|
560
|
-
type: "meta",
|
|
561
|
-
status: 'ok',
|
|
562
566
|
detail_type: type,
|
|
563
567
|
sub_type: '',
|
|
564
568
|
...data
|
|
565
569
|
};
|
|
570
|
+
return result;
|
|
566
571
|
}
|
|
567
|
-
V12.
|
|
572
|
+
V12.formatPayload = formatPayload;
|
|
568
573
|
})(V12 = exports.V12 || (exports.V12 = {}));
|