onebots 0.0.17 → 0.0.18
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/service/V12/index.d.ts +56 -4
- package/lib/service/V12/index.js +50 -21
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
|
-
import { Client } from "oicq";
|
|
3
|
+
import { Client, EventMap, MessageElem, Sendable } from "oicq";
|
|
4
4
|
import { Config } from './config';
|
|
5
5
|
import { OneBot } from "../../onebot";
|
|
6
6
|
import { Action } from "./action";
|
|
@@ -46,6 +46,47 @@ export declare class V12 extends EventEmitter implements OneBot.Base {
|
|
|
46
46
|
protected _webSocketHandler(ws: WebSocket): void;
|
|
47
47
|
}
|
|
48
48
|
export declare namespace V12 {
|
|
49
|
+
function fromSegment(msgList: SegmentElem | string | number | (SegmentElem | string | number)[]): MessageElem[];
|
|
50
|
+
function toSegment(msgList: Sendable): SegmentElem<keyof SegmentMap>[];
|
|
51
|
+
interface SegmentMap {
|
|
52
|
+
face: {
|
|
53
|
+
id: number;
|
|
54
|
+
text: string;
|
|
55
|
+
};
|
|
56
|
+
text: {
|
|
57
|
+
text: string;
|
|
58
|
+
};
|
|
59
|
+
mention: {
|
|
60
|
+
user_id: string;
|
|
61
|
+
};
|
|
62
|
+
mention_all: null;
|
|
63
|
+
image: {
|
|
64
|
+
file_id: string;
|
|
65
|
+
};
|
|
66
|
+
voice: {
|
|
67
|
+
file_id: string;
|
|
68
|
+
};
|
|
69
|
+
audio: {
|
|
70
|
+
file_id: string;
|
|
71
|
+
};
|
|
72
|
+
file: {
|
|
73
|
+
file_id: string;
|
|
74
|
+
};
|
|
75
|
+
location: {
|
|
76
|
+
latitude: number;
|
|
77
|
+
longitude: number;
|
|
78
|
+
title: string;
|
|
79
|
+
content: string;
|
|
80
|
+
};
|
|
81
|
+
reply: {
|
|
82
|
+
message_id: string;
|
|
83
|
+
user_id: string;
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
type SegmentElem<K extends keyof SegmentMap = keyof SegmentMap> = {
|
|
87
|
+
type: K;
|
|
88
|
+
data: SegmentMap[K];
|
|
89
|
+
};
|
|
49
90
|
interface Config {
|
|
50
91
|
heartbeat?: number;
|
|
51
92
|
access_token?: string;
|
|
@@ -94,7 +135,8 @@ export declare namespace V12 {
|
|
|
94
135
|
params: any;
|
|
95
136
|
echo?: string;
|
|
96
137
|
}
|
|
97
|
-
type
|
|
138
|
+
type BotEventMap = {
|
|
139
|
+
system: Record<string, any>;
|
|
98
140
|
connect: {
|
|
99
141
|
detail_type: 'connect';
|
|
100
142
|
version: ReturnType<Action['getVersion']>;
|
|
@@ -107,15 +149,25 @@ export declare namespace V12 {
|
|
|
107
149
|
detail_type: 'status_update';
|
|
108
150
|
status: ReturnType<Action['getStatus']>;
|
|
109
151
|
};
|
|
152
|
+
} & TransformEventMap;
|
|
153
|
+
type TransformEventMap = {
|
|
154
|
+
[P in keyof EventMap]: TransformEventParams<Parameters<EventMap[P]>>;
|
|
155
|
+
};
|
|
156
|
+
type TransformEventParams<T extends any[]> = T extends [infer L, ...infer R] ? L extends object ? L & {
|
|
157
|
+
args: R;
|
|
158
|
+
} : {
|
|
159
|
+
args: [L, ...R];
|
|
160
|
+
} : {
|
|
161
|
+
args: T;
|
|
110
162
|
};
|
|
111
163
|
function success<T extends any>(data: T, retcode?: Result<T>['retcode'], echo?: string): Result<T>;
|
|
112
164
|
function error(message: string, retcode?: Result<null>['retcode'], echo?: string): Result<null>;
|
|
113
|
-
function genMetaEvent<K extends keyof
|
|
165
|
+
function genMetaEvent<K extends keyof BotEventMap>(uin: number, type: K, data: Omit<BotEventMap[K], K>): {
|
|
114
166
|
self_id: number;
|
|
115
167
|
time: number;
|
|
116
168
|
type: string;
|
|
117
169
|
status: string;
|
|
118
170
|
detail_type: K;
|
|
119
171
|
sub_type: string;
|
|
120
|
-
} & Omit<
|
|
172
|
+
} & Omit<BotEventMap[K], K>;
|
|
121
173
|
}
|
package/lib/service/V12/index.js
CHANGED
|
@@ -13,7 +13,6 @@ const url_1 = require("url");
|
|
|
13
13
|
const http_1 = __importDefault(require("http"));
|
|
14
14
|
const https_1 = __importDefault(require("https"));
|
|
15
15
|
const ws_1 = require("ws");
|
|
16
|
-
const oicq2_cq_enable_1 = require("oicq2-cq-enable");
|
|
17
16
|
const utils_1 = require("../../utils");
|
|
18
17
|
const db_1 = require("../../db");
|
|
19
18
|
const app_1 = require("../../server/app");
|
|
@@ -212,22 +211,23 @@ class V12 extends events_1.EventEmitter {
|
|
|
212
211
|
dispatch(data) {
|
|
213
212
|
if (!data || typeof data !== "object")
|
|
214
213
|
data = { args: data || [] };
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
data
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
data.
|
|
214
|
+
data.type = data.post_type;
|
|
215
|
+
if (!data.type) {
|
|
216
|
+
data.detail_type = 'online';
|
|
217
|
+
if (data.image) {
|
|
218
|
+
data.type = 'login';
|
|
219
|
+
data.detail_type = 'qrcode';
|
|
220
|
+
}
|
|
221
|
+
else if (data.url) {
|
|
222
|
+
data.type = 'login';
|
|
223
|
+
data.detail_type = 'slider';
|
|
224
224
|
if (data.phone) {
|
|
225
|
-
data.
|
|
225
|
+
data.detail_type = 'device';
|
|
226
226
|
}
|
|
227
227
|
}
|
|
228
228
|
else if (data.message) {
|
|
229
|
-
data.
|
|
230
|
-
data.
|
|
229
|
+
data.type = 'login';
|
|
230
|
+
data.detial_type = 'error';
|
|
231
231
|
}
|
|
232
232
|
}
|
|
233
233
|
const payload = {
|
|
@@ -239,10 +239,11 @@ class V12 extends events_1.EventEmitter {
|
|
|
239
239
|
platform: 'qq',
|
|
240
240
|
user_id: `${this.client.uin}`
|
|
241
241
|
},
|
|
242
|
-
type: data.post_type || 'meta',
|
|
243
242
|
alt_message: data.raw_message,
|
|
244
243
|
detail_type: data.message_type || data.notice_type || data.request_type || data.system_type,
|
|
245
|
-
...data,
|
|
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',
|
|
246
247
|
};
|
|
247
248
|
if (payload.type === 'notice') {
|
|
248
249
|
switch (payload.detail_type) {
|
|
@@ -292,12 +293,7 @@ class V12 extends events_1.EventEmitter {
|
|
|
292
293
|
if (onebot_1.BOOLS.includes(k))
|
|
293
294
|
params[k] = (0, utils_1.toBool)(params[k]);
|
|
294
295
|
if (k === 'message') {
|
|
295
|
-
|
|
296
|
-
params[k] = (0, oicq2_cq_enable_1.fromCqcode)(params[k]);
|
|
297
|
-
}
|
|
298
|
-
else {
|
|
299
|
-
params[k] = (0, oicq2_cq_enable_1.fromSegment)(params[k]);
|
|
300
|
-
}
|
|
296
|
+
params[k] = V12.fromSegment(params[k]);
|
|
301
297
|
}
|
|
302
298
|
args.push(params[k]);
|
|
303
299
|
}
|
|
@@ -493,6 +489,39 @@ class V12 extends events_1.EventEmitter {
|
|
|
493
489
|
}
|
|
494
490
|
exports.V12 = V12;
|
|
495
491
|
(function (V12) {
|
|
492
|
+
function fromSegment(msgList) {
|
|
493
|
+
msgList = [].concat(msgList);
|
|
494
|
+
return msgList.map((msg) => {
|
|
495
|
+
if (typeof msg !== 'object')
|
|
496
|
+
msg = String(msg);
|
|
497
|
+
if (typeof msg === 'string') {
|
|
498
|
+
return { type: 'text', text: msg };
|
|
499
|
+
}
|
|
500
|
+
const { type, data, ...other } = msg;
|
|
501
|
+
return {
|
|
502
|
+
type: type.replace('mention', 'at').replace('at_all', 'at'),
|
|
503
|
+
...other,
|
|
504
|
+
...data
|
|
505
|
+
};
|
|
506
|
+
});
|
|
507
|
+
}
|
|
508
|
+
V12.fromSegment = fromSegment;
|
|
509
|
+
function toSegment(msgList) {
|
|
510
|
+
msgList = [].concat(msgList);
|
|
511
|
+
return msgList.map((msg) => {
|
|
512
|
+
if (typeof msg === 'string')
|
|
513
|
+
return { type: 'text', data: { text: msg } };
|
|
514
|
+
let { type, ...other } = msg;
|
|
515
|
+
return {
|
|
516
|
+
type: type === 'at' ? other['qq'] ? 'mention' : "mention_all" : type,
|
|
517
|
+
data: {
|
|
518
|
+
...other,
|
|
519
|
+
user_id: other['qq']
|
|
520
|
+
}
|
|
521
|
+
};
|
|
522
|
+
});
|
|
523
|
+
}
|
|
524
|
+
V12.toSegment = toSegment;
|
|
496
525
|
V12.defaultConfig = {
|
|
497
526
|
heartbeat: 3,
|
|
498
527
|
access_token: '',
|