forked from LLOneBot/LuckyLilliaBot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentities.ts
More file actions
728 lines (710 loc) · 26.4 KB
/
entities.ts
File metadata and controls
728 lines (710 loc) · 26.4 KB
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
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
import {
OB11Group,
OB11GroupMember,
OB11GroupMemberRole,
OB11Message,
OB11MessageData,
OB11MessageDataType,
OB11User,
OB11UserSex,
} from './types'
import {
AtType,
ChatType,
FaceIndex,
FaceType,
GrayTipElementSubType,
GroupMember,
GroupSimpleInfo,
JsonGrayTipBusId,
Peer,
RawMessage,
Sex,
SimpleInfo,
TipGroupElementType,
User,
} from '../ntqqapi/types'
import { EventType } from './event/OB11BaseEvent'
import { encodeCQCode } from './cqcode'
import { OB11GroupIncreaseEvent } from './event/notice/OB11GroupIncreaseEvent'
import { OB11GroupUploadNoticeEvent } from './event/notice/OB11GroupUploadNoticeEvent'
import { OB11GroupNoticeEvent } from './event/notice/OB11GroupNoticeEvent'
import { calcQQLevel, filterNullable } from '../common/utils/misc'
import { OB11GroupTitleEvent } from './event/notice/OB11GroupTitleEvent'
import { OB11GroupDecreaseEvent } from './event/notice/OB11GroupDecreaseEvent'
import { OB11FriendAddNoticeEvent } from './event/notice/OB11FriendAddNoticeEvent'
import { OB11FriendRecallNoticeEvent } from './event/notice/OB11FriendRecallNoticeEvent'
import { OB11GroupRecallNoticeEvent } from './event/notice/OB11GroupRecallNoticeEvent'
import { OB11FriendPokeEvent, OB11GroupPokeEvent } from './event/notice/OB11PokeEvent'
import { OB11BaseNoticeEvent } from './event/notice/OB11BaseNoticeEvent'
import { GroupBanEvent } from './event/notice/OB11GroupBanEvent'
import { GroupMsgEmojiLikeEvent } from './event/notice/OB11MsgEmojiLikeEvent'
import { GroupEssenceEvent } from './event/notice/OB11GroupEssenceEvent'
import { Dict, omit, pick } from 'cosmokit'
import { Context } from 'cordis'
import { selfInfo } from '@/common/globalVars'
import { pathToFileURL } from 'node:url'
import OneBot11Adapter from './adapter'
import { OB11GroupRequestEvent } from '@/onebot11/event/request/OB11GroupRequest'
export namespace OB11Entities {
export async function message(
ctx: Context,
msg: RawMessage,
rootMsgID?: string,
peer?: Peer,
): Promise<OB11Message | undefined> {
if (!msg.senderUin || msg.senderUin === '0' || msg.msgType === 1) return //跳过空消息
const {
debug,
messagePostFormat,
} = ctx.config as OneBot11Adapter.Config
const selfUin = selfInfo.uin
const msgShortId = ctx.store.createMsgShortId({ chatType: msg.chatType, peerUid: msg.peerUid }, msg.msgId)
const resMsg: OB11Message = {
self_id: Number(selfUin),
user_id: Number(msg.senderUin),
time: Number(msg.msgTime),
message_id: msgShortId,
message_seq: Number(msg.msgSeq),
message_type: msg.chatType === ChatType.Group ? 'group' : 'private',
sender: {
user_id: Number(msg.senderUin),
nickname: msg.sendNickName,
card: msg.sendMemberName ?? '',
},
raw_message: '',
font: 14,
sub_type: 'friend',
message: messagePostFormat === 'string' ? '' : [],
message_format: messagePostFormat === 'string' ? 'string' : 'array',
post_type: selfUin === msg.senderUin ? EventType.MESSAGE_SENT : EventType.MESSAGE,
getSummaryEventName(): string {
return this.post_type + '.' + this.message_type
}
}
if (debug) {
resMsg.raw = msg
}
if (msg.chatType === ChatType.Group) {
resMsg.sub_type = 'normal'
resMsg.group_id = parseInt(msg.peerUin)
resMsg.group_name = msg.peerName
// 284840486: 合并转发内部
if (msg.peerUin !== '284840486') {
try {
const member = await ctx.ntGroupApi.getGroupMember(msg.peerUin, msg.senderUid)
resMsg.sender.role = groupMemberRole(member.role)
resMsg.sender.nickname = member.nick
resMsg.sender.title = member.memberSpecialTitle ?? ''
} catch {
resMsg.sender.role = OB11GroupMemberRole.Member
resMsg.sender.title = ''
}
}
}
else if (msg.chatType === ChatType.C2C) {
resMsg.sub_type = 'friend'
resMsg.sender.nickname = (await ctx.ntUserApi.getUserSimpleInfo(msg.senderUid)).coreInfo.nick
}
else if (msg.chatType === ChatType.TempC2CFromGroup) {
resMsg.sub_type = 'group'
resMsg.temp_source = 0 //群聊
resMsg.sender.nickname = (await ctx.ntUserApi.getUserSimpleInfo(msg.senderUid)).coreInfo.nick
const ret = await ctx.ntMsgApi.getTempChatInfo(ChatType.TempC2CFromGroup, msg.senderUid)
if (ret?.result === 0) {
resMsg.sender.group_id = Number(ret.tmpChatInfo?.groupCode)
} else {
resMsg.sender.group_id = 284840486 //兜底数据
}
}
for (const element of msg.elements) {
let messageSegment: OB11MessageData | undefined
if (element.textElement && element.textElement?.atType !== AtType.Unknown) {
let qq: string
let name: string | undefined
if (element.textElement.atType === AtType.All) {
qq = 'all'
} else {
const { atNtUid, atUid, content } = element.textElement
if (atUid && atUid !== '0') {
qq = atUid
} else {
qq = await ctx.ntUserApi.getUinByUid(atNtUid)
}
name = content.replace('@', '')
}
messageSegment = {
type: OB11MessageDataType.At,
data: {
qq,
name
}
}
}
else if (element.textElement) {
const text = element.textElement.content
if (!text) {
continue
}
messageSegment = {
type: OB11MessageDataType.Text,
data: {
text
}
}
}
else if (element.replyElement) {
const { replyElement } = element
const peer = {
chatType: msg.chatType,
peerUid: msg.peerUid,
guildId: ''
}
try {
const { replayMsgSeq, replyMsgTime } = replyElement
const record = msg.records.find(msgRecord => msgRecord.msgId === replyElement.sourceMsgIdInRecords)
const senderUid = replyElement.senderUidStr || record?.senderUid
if (!record || !replyMsgTime || !senderUid) {
ctx.logger.error('找不到回复消息')
continue
}
const { msgList } = await ctx.ntMsgApi.getMsgsBySeqAndCount(peer, replayMsgSeq, 1, true, true)
let replyMsg: RawMessage | undefined
if (record.msgRandom !== '0') {
replyMsg = msgList.find((msg: RawMessage) => msg.msgRandom === record.msgRandom)
} else {
ctx.logger.info('msgRandom is missing', replyElement, record)
replyMsg = msgList[0]
}
if (!replyMsg) {
ctx.logger.error('获取不到引用的消息', replyElement)
continue
}
// 284840486: 合并消息内侧 消息具体定位不到
if (!replyMsg && msg.peerUin !== '284840486') {
ctx.logger.error('获取不到引用的消息', replyElement)
ctx.logger.warn('queryMsgs', msgList.map(e => pick(e, ['msgSeq', 'msgRandom'])), record.msgRandom)
continue
}
messageSegment = {
type: OB11MessageDataType.Reply,
data: {
id: ctx.store.createMsgShortId(peer, replyMsg ? replyMsg.msgId : record.msgId).toString()
}
}
} catch (e) {
ctx.logger.error('获取不到引用的消息', e, replyElement, (e as Error).stack)
continue
}
}
else if (element.picElement) {
const { picElement } = element
const fileSize = picElement.fileSize ?? '0'
messageSegment = {
type: OB11MessageDataType.Image,
data: {
file: picElement.fileName,
subType: picElement.picSubType,
url: await ctx.ntFileApi.getImageUrl(picElement),
file_size: fileSize,
}
}
ctx.store.addFileCache({
peerUid: msg.peerUid,
msgId: msg.msgId,
msgTime: +msg.msgTime,
chatType: msg.chatType,
elementId: element.elementId,
elementType: element.elementType,
fileName: picElement.fileName,
fileUuid: picElement.fileUuid,
fileSize,
}).then()
}
else if (element.videoElement) {
const { videoElement } = element
const videoUrl = await ctx.ntFileApi.getVideoUrl(
{
chatType: msg.chatType,
peerUid: peer?.peerUid ?? msg.peerUid,
},
rootMsgID ?? msg.msgId,
element.elementId,
)
const fileSize = videoElement.fileSize ?? '0'
messageSegment = {
type: OB11MessageDataType.Video,
data: {
file: videoElement.fileName,
url: videoUrl || pathToFileURL(videoElement.filePath).href,
path: videoElement.filePath,
file_size: fileSize,
}
}
ctx.store.addFileCache({
peerUid: msg.peerUid,
msgId: msg.msgId,
msgTime: +msg.msgTime,
chatType: msg.chatType,
elementId: element.elementId,
elementType: element.elementType,
fileName: videoElement.fileName,
fileUuid: videoElement.fileUuid!,
fileSize,
}).then()
}
else if (element.fileElement) {
const { fileElement } = element
const fileSize = fileElement.fileSize ?? '0'
messageSegment = {
type: OB11MessageDataType.File,
data: {
file: fileElement.fileName,
url: fileElement.filePath ? pathToFileURL(fileElement.filePath).href : '',
file_id: fileElement.fileUuid,
path: fileElement.filePath,
file_size: fileSize,
}
}
ctx.store.addFileCache({
peerUid: msg.peerUid,
msgId: msg.msgId,
msgTime: +msg.msgTime,
chatType: msg.chatType,
elementId: element.elementId,
elementType: element.elementType,
fileName: fileElement.fileName,
fileUuid: fileElement.fileUuid!,
fileSize,
}).then()
}
else if (element.pttElement) {
const { pttElement } = element
const fileSize = pttElement.fileSize ?? '0'
messageSegment = {
type: OB11MessageDataType.Record,
data: {
file: pttElement.fileName,
url: pathToFileURL(pttElement.filePath).href,
path: pttElement.filePath,
file_size: fileSize,
}
}
ctx.store.addFileCache({
peerUid: msg.peerUid,
msgId: msg.msgId,
msgTime: +msg.msgTime,
chatType: msg.chatType,
elementId: element.elementId,
elementType: element.elementType,
fileName: pttElement.fileName,
fileUuid: pttElement.fileUuid,
fileSize,
}).then()
}
else if (element.arkElement) {
const { arkElement } = element
const data = JSON.parse(arkElement.bytesData)
if (data.app === 'com.tencent.multimsg') {
messageSegment = {
type: OB11MessageDataType.Forward,
data: {
id: msg.msgId
}
}
} else {
messageSegment = {
type: OB11MessageDataType.Json,
data: {
data: arkElement.bytesData
}
}
}
}
else if (element.faceElement) {
const { faceElement } = element
const { faceIndex, faceType } = faceElement
if (faceType === FaceType.Poke && faceIndex === 1) {
messageSegment = {
type: OB11MessageDataType.Shake,
data: {}
}
}
else {
if (faceIndex === FaceIndex.Dice) {
messageSegment = {
type: OB11MessageDataType.Dice,
data: {
result: faceElement.resultId!
}
}
}
else if (faceIndex === FaceIndex.RPS) {
messageSegment = {
type: OB11MessageDataType.Rps,
data: {
result: faceElement.resultId!
}
}
/*} else if (faceIndex === 1 && pokeType === 1) {
messageSegment = {
type: OB11MessageDataType.shake,
data: {}
}*/
}
else {
messageSegment = {
type: OB11MessageDataType.Face,
data: {
id: faceIndex.toString(),
sub_type: faceType
}
}
}
}
}
else if (element.marketFaceElement) {
const { marketFaceElement } = element
const { emojiId } = marketFaceElement
// 取md5的前两位
const dir = emojiId.substring(0, 2)
// 获取组装url
// const url = `https://p.qpic.cn/CDN_STATIC/0/data/imgcache/htdocs/club/item/parcel/item/${dir}/${md5}/300x300.gif?max_age=31536000`
const url = `https://gxh.vip.qq.com/club/item/parcel/item/${dir}/${emojiId}/raw300.gif`
messageSegment = {
type: OB11MessageDataType.Mface,
data: {
summary: marketFaceElement.faceName!,
url,
emoji_id: emojiId,
emoji_package_id: marketFaceElement.emojiPackageId,
key: marketFaceElement.key
}
}
}
else if (element.markdownElement) {
const { markdownElement } = element
// todo: 解析闪传 markdown 获取 fileSetId
if (markdownElement?.content.startsWith('[闪传](')) {
const mqqapiUrl = markdownElement?.content.substring(5, markdownElement?.content.length - 1)
const urlJson = new URL(mqqapiUrl).searchParams.get('json')
if (urlJson) {
const jsonData = JSON.parse(urlJson)
const busId = jsonData?.busId
if (busId === 'FlashTransfer') {
const attributes: any[] = jsonData?.attributes?.attributes || []
const fileAttribute = attributes.find(a => a.viewId === 'file')
if (fileAttribute) {
const urlParams = new URL(fileAttribute.schema).searchParams
const fileSetId = urlParams.get('fileset_id') || ''
const sceneType = urlParams.get('scene_type') || ''
const fileSubAttributes: any[] = fileAttribute?.attributes || []
const titleAttribute = fileSubAttributes.find(a => a.viewId === 'title')
const title: string = titleAttribute?.text
messageSegment = {
type: OB11MessageDataType.FlashFile,
data: {
title,
file_set_id: fileSetId,
scene_type: parseInt(sceneType)
}
}
}
}
}
}
else {
messageSegment = {
type: OB11MessageDataType.Markdown,
data: {
content: markdownElement.content
}
}
}
}
else if (element.multiForwardMsgElement) {
messageSegment = {
type: OB11MessageDataType.Forward,
data: {
id: msg.msgId
}
}
} else if (element.inlineKeyboardElement) {
messageSegment = {
type: OB11MessageDataType.Keyboard,
data: {
rows: element.inlineKeyboardElement.rows.map(row => ({
buttons: row.buttons.map(button => ({
id: button.id,
render_data: {
label: button.label,
visited_label: button.visitedLabel,
style: button.style,
},
action: {
type: button.type,
permission: {
type: button.permissionType,
specify_role_ids: button.specifyRoleIds,
specify_user_ids: button.specifyTinyids,
},
unsupport_tips: button.unsupportTips,
data: button.data,
reply: button.isReply,
enter: button.enter,
},
}))
}))
}
}
}
if (messageSegment) {
const cqCode = encodeCQCode(messageSegment)
if (messagePostFormat === 'array') {
(resMsg.message as OB11MessageData[]).push(messageSegment)
}
resMsg.raw_message += cqCode
}
}
if (messagePostFormat === 'string') {
resMsg.message = resMsg.raw_message
}
return resMsg
}
export async function privateEvent(ctx: Context, msg: RawMessage): Promise<OB11BaseNoticeEvent | void> {
if (msg.chatType !== ChatType.C2C) {
return
}
if (msg.msgType !== 5 && msg.msgType !== 11) {
return
}
for (const element of msg.elements) {
if (element.grayTipElement) {
const { grayTipElement } = element
if (grayTipElement.jsonGrayTipElement?.busiId === '1061') {
const json = JSON.parse(grayTipElement.jsonGrayTipElement.jsonStr)
const param = grayTipElement.jsonGrayTipElement.xmlToJsonParam
if (param) {
return new OB11FriendPokeEvent(
Number(param.templParam.get('uin_str1')),
Number(param.templParam.get('uin_str2')),
json.items
)
}
const pokedetail: Dict[] = json.items
//筛选item带有uid的元素
const poke_uid = pokedetail.filter(item => item.uid)
if (poke_uid.length === 2) {
return new OB11FriendPokeEvent(
Number(await ctx.ntUserApi.getUinByUid(poke_uid[0].uid)),
Number(await ctx.ntUserApi.getUinByUid(poke_uid[1].uid)),
pokedetail
)
}
}
if (grayTipElement.xmlElement?.templId === '10229' || grayTipElement.jsonGrayTipElement?.busiId === JsonGrayTipBusId.AddedFriend) {
ctx.logger.info('收到好友添加消息', msg.peerUid)
const uin = +msg.peerUin || +(await ctx.ntUserApi.getUinByUid(msg.peerUid))
return new OB11FriendAddNoticeEvent(uin)
}
} else if (element.arkElement) {
const data = JSON.parse(element.arkElement.bytesData)
if (data.app === 'com.tencent.qun.invite' || (data.app === 'com.tencent.tuwen.lua' && data.bizsrc === 'qun.invite')) {
const params = new URLSearchParams(data.meta.news.jumpUrl)
const receiverUin = params.get('receiveruin')
const senderUin = params.get('senderuin')
if (receiverUin !== selfInfo.uin || senderUin !== msg.senderUin) {
return
}
ctx.logger.info('收到邀请我加群消息')
const groupCode = params.get('groupcode')
const seq = params.get('msgseq')
const flag = `${groupCode}|${seq}|1|0`
return new OB11GroupRequestEvent(
Number(groupCode),
Number(senderUin),
flag,
data.meta.news.desc,
'invite',
)
}
}
}
}
export async function groupEvent(ctx: Context, msg: RawMessage): Promise<OB11GroupNoticeEvent | void> {
if (msg.chatType !== ChatType.Group) {
return
}
if (msg.msgType !== 5 && msg.msgType !== 3) {
return
}
for (const element of msg.elements) {
if (element.fileElement) {
return new OB11GroupUploadNoticeEvent(+msg.peerUid, +msg.senderUin!, {
id: element.fileElement.fileUuid!,
name: element.fileElement.fileName,
size: parseInt(element.fileElement.fileSize),
busid: element.fileElement.fileBizId || 0,
})
} else if (element.grayTipElement) {
const grayTipElement = element.grayTipElement
if (grayTipElement.subElementType === GrayTipElementSubType.JSON) {
const json = JSON.parse(grayTipElement.jsonGrayTipElement!.jsonStr)
if (grayTipElement.jsonGrayTipElement?.busiId === '1061') {
const param = grayTipElement.jsonGrayTipElement.xmlToJsonParam!
return new OB11GroupPokeEvent(
Number(msg.peerUid),
Number(param.templParam.get('uin_str1')),
Number(param.templParam.get('uin_str2')),
json.items
)
} else if (grayTipElement.jsonGrayTipElement?.busiId === JsonGrayTipBusId.GroupEssenceMsg && json.items[2]) {
ctx.logger.info('收到群精华消息', json)
return await GroupEssenceEvent.parse(ctx, new URL(json.items[2].jp))
} else if (grayTipElement.jsonGrayTipElement?.busiId === JsonGrayTipBusId.GroupMemberTitleChanged) {
ctx.logger.info('收到群成员新头衔消息', json)
const memberUin = json.items[1].param[0]
const title = json.items[3].txt
return new OB11GroupTitleEvent(parseInt(msg.peerUid), parseInt(memberUin), title)
} else if (grayTipElement.jsonGrayTipElement?.busiId === JsonGrayTipBusId.GroupNewMemberInvited) {
ctx.logger.info('收到新人被邀请进群消息', grayTipElement)
const userId = new URL(json.items[2].jp).searchParams.get('robot_uin')
const operatorId = new URL(json.items[0].jp).searchParams.get('uin')
return new OB11GroupIncreaseEvent(Number(msg.peerUid), Number(userId), Number(operatorId), 'invite')
}
} else if (grayTipElement.subElementType === GrayTipElementSubType.Group) {
const groupElement = grayTipElement.groupElement!
if (groupElement.type === TipGroupElementType.Ban) {
ctx.logger.info('收到群成员禁言提示', groupElement)
return await GroupBanEvent.parse(ctx, groupElement, msg.peerUid)
} else if (groupElement.type === TipGroupElementType.Kicked) {
ctx.logger.info(`收到我被踢出或退群提示, 群${msg.peerUid}`, groupElement)
const { adminUid } = groupElement
return new OB11GroupDecreaseEvent(
Number(msg.peerUid),
Number(selfInfo.uin),
adminUid ? Number(await ctx.ntUserApi.getUinByUid(adminUid)) : 0,
adminUid ? 'kick_me' : 'leave'
)
} else if (groupElement.type === TipGroupElementType.MemberIncrease) {
const { memberUid, adminUid } = groupElement
if (memberUid !== selfInfo.uid) return
ctx.logger.info('收到群成员增加消息', groupElement)
const adminUin = adminUid ? await ctx.ntUserApi.getUinByUid(adminUid) : selfInfo.uin
return new OB11GroupIncreaseEvent(+msg.peerUid, +selfInfo.uin, +adminUin)
}
} else if (grayTipElement.subElementType === GrayTipElementSubType.XmlMsg) {
const xmlElement = grayTipElement.xmlElement!
if (xmlElement.templId === '10382') {
ctx.logger.info('收到表情回应我的消息', xmlElement.templParam)
return await GroupMsgEmojiLikeEvent.parse(ctx, xmlElement, msg.peerUid)
} else if (xmlElement.templId == '10179') {
ctx.logger.info('收到新人被邀请进群消息 templId: 10179', xmlElement)
const invitor = xmlElement.templParam.get('invitor')
const invitee = xmlElement.templParam.get('invitee')
if (invitor && invitee) {
return new OB11GroupIncreaseEvent(+msg.peerUid, +invitee, +invitor, 'invite')
}
}
}
}
}
}
export async function recallEvent(
ctx: Context,
msg: RawMessage,
shortId: number
): Promise<OB11FriendRecallNoticeEvent | OB11GroupRecallNoticeEvent | undefined> {
const revokeElement = msg.elements[0].grayTipElement?.revokeElement
if (msg.chatType === ChatType.Group) {
const operator = await ctx.ntGroupApi.getGroupMember(msg.peerUid, revokeElement!.operatorUid)
return new OB11GroupRecallNoticeEvent(
parseInt(msg.peerUid),
parseInt(msg.senderUin!),
parseInt(operator?.uin || msg.senderUin!),
shortId,
)
}
else {
return new OB11FriendRecallNoticeEvent(parseInt(msg.senderUin!), shortId)
}
}
export function friend(friend: User): OB11User {
return {
user_id: parseInt(friend.uin),
nickname: friend.nick,
remark: friend.remark,
sex: sex(friend.sex!),
level: (friend.qqLevel && calcQQLevel(friend.qqLevel)) || 0,
}
}
export function friends(friends: User[]): OB11User[] {
return friends.map(friend)
}
export function friendV2(raw: SimpleInfo): OB11User {
return {
...omit(raw.baseInfo, ['richBuffer', 'phoneNum']),
...omit(raw.coreInfo, ['nick']),
user_id: parseInt(raw.coreInfo.uin),
nickname: raw.coreInfo.nick,
remark: raw.coreInfo.remark || raw.coreInfo.nick,
sex: sex(raw.baseInfo.sex),
level: 0
}
}
export function friendsV2(raw: SimpleInfo[]): OB11User[] {
return filterNullable(raw).map(friendV2)
}
export function groupMemberRole(role: number): OB11GroupMemberRole {
return {
4: OB11GroupMemberRole.Owner,
3: OB11GroupMemberRole.Admin,
2: OB11GroupMemberRole.Member,
}[role] ?? OB11GroupMemberRole.Member
}
export function sex(sex: Sex): OB11UserSex {
const sexMap = {
[Sex.Unknown]: OB11UserSex.Unknown,
[Sex.Male]: OB11UserSex.Male,
[Sex.Female]: OB11UserSex.Female,
[Sex.Hidden]: OB11UserSex.Unknown
}
return sexMap[sex] ?? OB11UserSex.Unknown
}
export function groupMember(groupId: number, member: GroupMember): OB11GroupMember {
return {
group_id: groupId,
user_id: parseInt(member.uin),
nickname: member.nick,
card: member.cardName || member.nick,
sex: OB11UserSex.Unknown,
age: 0,
area: '',
level: String(member.memberRealLevel ?? 0),
qq_level: 0,
join_time: member.joinTime,
last_sent_time: member.lastSpeakTime,
title_expire_time: 0,
unfriendly: false,
card_changeable: true,
is_robot: member.isRobot,
shut_up_timestamp: member.shutUpTime,
role: groupMemberRole(member.role),
title: member.memberSpecialTitle,
}
}
export function group(group: GroupSimpleInfo): OB11Group {
return {
group_id: parseInt(group.groupCode),
group_name: group.groupName,
group_memo: '',
group_create_time: +group.createTime,
member_count: group.memberCount,
max_member_count: group.maxMember,
remark_name: group.remarkName,
}
}
export function groups(groups: GroupSimpleInfo[]): OB11Group[] {
return groups.map(group)
}
}