This repository has been archived by the owner on Jan 5, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathindex.d.ts
504 lines (481 loc) · 11.8 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
import * as Axios from 'axios';
interface BaseResponse<ResultType> {
retcode: number,
result: ResultType
}
interface VfwebqqResult {
vfwebqq: string
}
interface Login2Result {
cip: number,
f: number,
index: number,
port: number,
psessionid: string,
status: string,
uin: number,
user_state: number,
vfwebqq: string
}
interface UserFriendsResult {
friends: Array<{
flag: number,
uin: number,
categories: number
}>,
marknames: Array<{}>,
categories: Array<{}>,
vipinfo: Array<{
u: number,
is_vip: 1 | 0,
vip_level: number
}>,
info: Array<{
face: number,
flag: number,
nick: string,
uin: string
}>
}
interface GroupListResult {
gmasklist: Array<any>,
gnamelist: Array<{
flag: number,
name: string,
gid: number,
code: number
}>,
gmarklist: Array<any>
}
interface DiscuListResult {
dnamelist: Array<{
name: string,
did: number
}>
}
interface OnlineBuddyResult {
[index: number]: {
client_type: number,
status: string,
uin: number
}
}
interface RecentListResult {
[index: number]: {
type: 0 | 1 | 2,
uin: number
}
}
interface UserDetailInfo {
face: number,
birthday: {
month: number,
year: number,
day: number
},
occupation: string,
phone: string,
allow: number,
college: string,
uin: number,
constel: number,
blood: number,
homepage: string,
stat: number,
vip_info: number,
country: string,
city: string,
personal: string,
nick: string,
shengxiao: number,
email: string,
province: string,
gender: string,
mobile: string
}
interface BubbyGroupMensInfo {
gname: string,
mems: Array<{ name: string, uin: number }>
}
interface GroupDetailInfo {
stats: Array<{
client_type: number,
uin: number,
stat: number
}>,
minfo: Array<{
nick: string,
province: string,
gender: string,
uin: number,
country: string,
city: string
}>,
ginfo: {
face: number,
memo: string,
class: number,
fingermemo: string,
code: number,
createtime: number,
flag: number,
level: number,
name: string,
gid: number,
owner: number,
members: Array<{
muin: number,
mflag: number
}>,
option: number
},
cards: Array<{
muin: number,
card: string
}>,
vipinfo: Array<{
vip_level: number,
u: number,
is_vip: number
}>
}
interface DiscuDetailInfo {
info: {
did: number,
discu_name: string,
mem_list: Array<{
mem_uin: number,
ruin: number
}>
},
mem_info: Array<{
nick: string,
uin: number
}>,
mem_status: Array<{
client_type: number,
status: string,
uin: number
}>
}
interface QQOptions {
app?: {
clientid?: number,
appid?: number,
/**
* Login method. Can be `{ QQ.LOGIN.QR | QQ.LOGIN.PWD }` .
* Using QR Code login at default.
*/
login?: 0 | 1;
/**
* max retry count when sending message.
* when `retcode !== 0`, should retry. Depends on WebQQ.
*/
maxSendRetry: 2 | number,
/**
* max allow count that "short poll" happens continuously.
* "short poll" means a poll less than 3000ms and does not contain msg.
*/
maxShortAllow: 3 | number
},
font?: {
name?: string,
size?: number,
style?: Array<number> | [0, 0, 0],
color?: string | '000000'
},
auth?: {
/** QQ id to use in id/pwd login */
u: string,
/** QQ pwd to use in id/pwd login. should NOT encrypt */
p: string
},
cookiePath?: string | '/tmp/qq-bot.cookie',
qrcodePath?: string | '/tmp/code.png'
}
export class QQ {
/** login method constants */
static LOGIN: {
/** scan QR Code */
QR: 0,
/** use id/pwd. specify in constructor. */
PWD: 1
}
constructor(options: QQOptions)
options: QQOptions
tokens: {
uin: string,
ptwebqq: string,
vfwebqq: string,
psessionid: string
}
selfInfo: UserDetailInfo
buddy: {
friends: Array<{
flag: number,
uin: number,
categories: number
}>,
marknames: Array<{
uin: number,
markname: string,
type: number
}>,
categories: Array<{
index: number,
sort: number,
name: string
}>,
vipinfo: Array<{
vip_level: number,
u: number,
is_vip: number
}>,
info: Array<{
face: number,
flag: number,
nick: string,
uin: number
}>
};
discu: Array<{
did: number,
name: string,
info?: DiscuDetailInfo
}>
group: Array<{
flag: number,
name: string,
/**
* use this for send group msg
*/
gid: number,
/**
* use this for get group info
*/
code: number,
info?: GroupDetailInfo
}>
client: HttpClient
messageAgent: MessageAgent
/**
* true if QQBot still online/trying to online
*/
_alive: boolean
run(): Promise<void>
login(): Promise<void>
getSelfInfo(): Promise<UserDetailInfo>
getBuddy(): Promise<UserFriendsResult>
getOnlineBuddies(): Promise<OnlineBuddyResult>
getGroup(): Promise<GroupListResult>
getDiscu(): Promise<DiscuListResult>
getBuddyName(uin: number): Promise<string>
getDiscuName(did: number): Promise<string>
getDiscuInfo(uin: number): Promise<DiscuDetailInfo>
getNameInDiscu(uin: number, did: number): Promise<string>
getGroupName(gIdOrCode: number): Promise<string>
getGroupInfo(code: number): Promise<GroupDetailInfo>
getNameInGroup(uin: number, gIdOrCode: number): Promise<string>
logMessage(msg: Object): void
handelMsgRecv(msg: Object): Promise<void>
loopPoll(): Promise<void>
innerSendMsg(url: string, key: number, id: number, content: string): Promise<boolean>
sendBuddyMsg(uin: number | string, content: string): Promise<boolean>
sendDiscuMsg(did: number | string, content: string): Promise<boolean>
sendGroupMsg(gid: number | string, content: string): Promise<boolean>
on(event: string, listener?: (...args: any[]) => void): void
/**
* login start. use `login-success` if u want to catch
* login success event.
*
* @param {'login'} event
* @memberof QQ
*/
on(event: 'login')
/**
* start re-login using cookie
*
* @param {'cookie-relogin'} event
* @memberof QQ
*/
on(event: 'cookie-relogin')
/**
* QR-Code downloaded, about to scan
*
* @param {'qr'} event
* @param {string} qrcodePath /path/to/qrcode.png
* @param {ArrayBuffer} qrCode binary QR-Code data
* @memberof QQ
*/
on(event: 'qr', listener: (qrcodePath: string, qrCode: ArrayBuffer) => void)
/**
* QR-Code downloaded, about to scan
*
* @param {'qr'} event
* @param {string} qrcodePath /path/to/qrcode.png
* @param {ArrayBuffer} qrCode binary QR-Code data
* @memberof QQ
*/
on(event: 'qr-expire')
/**
* re-login using cookie but cookie has expired
*
* @param {'cookie-expire'} event
* @memberof QQ
*/
on(event: 'cookie-expire')
on(event: 'login-success')
/**
* receive a message
*
* @param {'msg'} event
* @param {ReceivedMsgType} msgParsed
* @param {*} msg unparsed raw polling result
* @memberof QQ
*/
on(event: 'msg', listener: (msgParsed: ReceivedMsgType, msg: any) => void)
/**
* receive a buddy message
*
* @param {'buddy'} event
* @param {ReceivedMsgType} msgParsed
* @param {*} msg unparsed raw polling result
* @memberof QQ
*/
on(event: 'buddy', listener: (msgParsed: ReceivedMsgType, msg: any) => void)
/**
* receive a discu message
*
* @param {'discu'} event
* @param {ReceivedMsgType} msgParsed
* @param {*} msg unparsed raw polling result
* @memberof QQ
*/
on(event: 'discu', listener: (msgParsed: ReceivedMsgType, msg: any) => void)
/**
* receive a group message
*
* @param {'group'} event
* @param {ReceivedMsgType} msgParsed
* @param {*} msg unparsed raw polling result
* @memberof QQ
*/
on(event: 'group', listener: (msgParsed: ReceivedMsgType, msg: any) => void)
/**
* poll will start
*
* @param {'start-poll'} event
* @memberof QQ
*/
on(event: 'start-poll')
/**
* a poll finished
*
* @param {'polling'} event
* @param {*} msg unpareed raw polling result
* @memberof QQ
*/
on(event: 'polling', listener: (msg: any) => void)
on(event: 'disconnect')
/**
* error when handling messages
*
* @param {'error'} event
* @param {Error} err
* @memberof QQ
*/
on(event: 'error', listener: (err: Error) => void)
/**
* about to send message
*
* @param {'send'} event
* @param {SentMsgType} msg
* @memberof QQ
*/
on(event: 'send', listener: (msg: SentMsgType) => void)
/**
* about to send message to buddy
*
* @param {'send-buddy'} event
* @param {SentMsgType} msg
* @memberof QQ
*/
on(event: 'send-buddy', listener: (msg: SentMsgType) => void)
/**
* about to send message to discu
*
* @param {'send-discu'} event
* @param {SentMsgType} msg
* @memberof QQ
*/
on(event: 'send-discu', listener: (msg: SentMsgType) => void)
/**
* about to send message to group
*
* @param {'send-group'} event
* @param {SentMsgType} msg
* @memberof QQ
*/
on(event: 'send-group', listener: (msg: SentMsgType) => void)
}
interface ReceivedMsgType {
id: number,
name: string,
type: 'buddy' | 'discu' | 'group',
content: string,
groupId?: number,
groupName?: string,
discuId?: number,
discuName?: string
}
interface SentMsgType {
id: number,
type: 'buddy' | 'discu' | 'group',
content: string
}
interface ClientRequestConfig extends Axios.AxiosRequestConfig {
headers?: {
Origin?: string,
Referer?: string
}
}
interface MessageFont {
name: string | '宋体',
size: number | 10,
style: [number, number, number] | [0, 0, 0],
color: string | '000000'
}
declare class MessageAgent {
msg_id: number
clientid: number | 53999199
psessionid: string
font: MessageFont
readonly defaultMsg: {
face: 537,
clientid: number | 53999199,
msg_id: number,
psessionid: string
}
build(typeOrKeyType, id, content): {
face: 537,
clientid: number | 53999199,
msg_id: number,
psessionid: string,
to?: number,
group_uin?: number,
did?: number,
content: string,
font: MessageFont
}
}
export class HttpClient {
clientHeaders: { Cookie: string, 'User-Agent': string }
setCookie(arg: string | Object): void
updateCookie(arg: string | Array<string>): void
getCookie(key?: string): void
getCookiestring(): string
static mkFormR(payload: Object): string
post(config: ClientRequestConfig): Promise<any>
get(urlOrConfig: string | ClientRequestConfig): Promise<any>
}
export function shortenUrl(urlOrUrls: string | Array<string>): string | Array<string>;