-
Notifications
You must be signed in to change notification settings - Fork 0
/
message.go
80 lines (73 loc) · 2.74 KB
/
message.go
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
package SakanaBot
import (
"fmt"
goqqprotobuf "github.com/littlefish12345/go-qq-protobuf"
)
func (qqClient *QQClient) ProcessMessage(pairMessage *goqqprotobuf.Message) *UniformMessageStruct {
//if qqClient.IsInit {
// return nil
//}
fmt.Println(*pairMessage.MessageHead.MessageType)
switch *pairMessage.MessageHead.MessageType {
case 9, 10, 31, 79, 97, 120, 132, 133, 166, 167:
if *pairMessage.MessageHead.C2CCmd == 11 || *pairMessage.MessageHead.C2CCmd == 175 {
return qqClient.PrivateMessageDecoder(pairMessage)
}
case 208:
return qqClient.PrivateMessageDecoder(pairMessage)
case 35, 36, 37, 45, 46, 84, 85, 86, 87:
}
return nil
}
func (qqClient *QQClient) SyncMessage(responseStruct *goqqprotobuf.GetMessageResponseStruct) {
if *responseStruct.MessageResponseType == 0 {
qqClient.SyncCookie = responseStruct.SyncCookie
qqClient.PublicAccountCookie = responseStruct.PublicAccountCookie
} else if *responseStruct.MessageResponseType == 1 {
qqClient.SyncCookie = responseStruct.SyncCookie
} else if *responseStruct.MessageResponseType == 2 {
qqClient.PublicAccountCookie = responseStruct.PublicAccountCookie
}
if responseStruct.UinPairMessages == nil {
return
}
var deleteMessageList []*goqqprotobuf.MessageItem
for _, uinPairMessage := range responseStruct.UinPairMessages {
for _, pairMessage := range uinPairMessage.Message {
deleteMessageItem := &goqqprotobuf.MessageItem{
FromUin: pairMessage.MessageHead.FromUin,
ToUin: pairMessage.MessageHead.ToUin,
MessageType: pairMessage.MessageHead.MessageType,
MessageSeqence: pairMessage.MessageHead.MessageSeqence,
MessageUid: pairMessage.MessageHead.MessageUid,
}
deleteMessageList = append(deleteMessageList, deleteMessageItem)
if (int64(*uinPairMessage.LastReadTime) & 0xFFFFFFFF) > int64(*pairMessage.MessageHead.MessageTime) {
continue
}
uniformMessage := qqClient.ProcessMessage(pairMessage)
if uniformMessage != nil {
fmt.Println(uniformMessage.SenderIsFriend, uniformMessage.SenderNickname, uniformMessage.SenderUin)
if uniformMessage.MessageType == MessageTypeVoice {
fmt.Println(uniformMessage.VoiceMessage)
} else if uniformMessage.MessageType == MessageTypeRichText {
for _, element := range uniformMessage.RichTextMessage {
fmt.Println(element)
if element.RichTextElementType == RichTextElementTypeReply {
for _, elem := range element.ReplyElement.Elements {
fmt.Println(elem)
}
}
}
}
fmt.Println()
}
}
}
if deleteMessageList != nil {
qqClient.RecvPack(qqClient.SendPack(qqClient.BuildDeleteMessageRequestPack(deleteMessageList)))
}
if *responseStruct.SyncFlag != MessageSyncFlagStop {
qqClient.GetMessage(*responseStruct.SyncFlag)
}
}