1
+ /*
2
+ * Copyright 2019-2021 Mamoe Technologies and contributors.
3
+ *
4
+ * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
5
+ * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
6
+ *
7
+ * https://github.com/mamoe/mirai/blob/dev/LICENSE
8
+ */
9
+
10
+ package net.mamoe.mirai.internal.notice.processors
11
+
12
+ import net.mamoe.kjbb.JvmBlockingBridge
13
+ import net.mamoe.mirai.contact.MemberPermission
14
+ import net.mamoe.mirai.event.events.FriendMessageSyncEvent
15
+ import net.mamoe.mirai.event.events.GroupMessageSyncEvent
16
+ import net.mamoe.mirai.internal.network.components.NoticePipelineContext.Companion.KEY_FROM_SYNC
17
+ import net.mamoe.mirai.internal.network.components.SsoProcessor
18
+ import net.mamoe.mirai.message.data.content
19
+ import org.junit.jupiter.api.Test
20
+ import kotlin.test.assertEquals
21
+ import kotlin.test.assertIs
22
+
23
+ @JvmBlockingBridge
24
+ internal class MessageSyncTest : AbstractNoticeProcessorTest () {
25
+
26
+ @Test
27
+ suspend fun `can receive group sync from macOS client` () {
28
+ suspend fun runTest () = use {
29
+ net.mamoe.mirai.internal.network.protocol.data.proto.MsgOnlinePush .PbPushMsg (
30
+ msg = net.mamoe.mirai.internal.network.protocol.data.proto.MsgComm .Msg (
31
+ msgHead = net.mamoe.mirai.internal.network.protocol.data.proto.MsgComm .MsgHead (
32
+ fromUin = 1230002 ,
33
+ toUin = 1230002 ,
34
+ msgType = 82 ,
35
+ msgSeq = 1772 ,
36
+ msgTime = 1640029614 ,
37
+ msgUid = 144115188088832082 ,
38
+ groupInfo = net.mamoe.mirai.internal.network.protocol.data.proto.MsgComm .GroupInfo (
39
+ groupCode = 2230203 ,
40
+ groupType = 1 ,
41
+ groupInfoSeq = 657 ,
42
+ groupCard = " user2" ,
43
+ groupLevel = 1 ,
44
+ groupCardType = 2 ,
45
+ groupName = " testtest" .toByteArray(), /* 74 65 73 74 74 65 73 74 */
46
+ ),
47
+ fromAppid = 1001 ,
48
+ fromInstid = 537067835 ,
49
+ userActive = 1 ,
50
+ ),
51
+ msgBody = net.mamoe.mirai.internal.network.protocol.data.proto.ImMsgBody .MsgBody (
52
+ richText = net.mamoe.mirai.internal.network.protocol.data.proto.ImMsgBody .RichText (
53
+ attr = net.mamoe.mirai.internal.network.protocol.data.proto.ImMsgBody .Attr (
54
+ codePage = 0 ,
55
+ time = 1640029614 ,
56
+ random = 25984994 ,
57
+ size = 9 ,
58
+ effect = 0 ,
59
+ charSet = 134 ,
60
+ pitchAndFamily = 0 ,
61
+ fontName = " Helvetica" ,
62
+ ),
63
+ elems = mutableListOf (
64
+ net.mamoe.mirai.internal.network.protocol.data.proto.ImMsgBody .Elem (
65
+ text = net.mamoe.mirai.internal.network.protocol.data.proto.ImMsgBody .Text (
66
+ str = " s" ,
67
+ ),
68
+ ),
69
+ net.mamoe.mirai.internal.network.protocol.data.proto.ImMsgBody .Elem (
70
+ elemFlags2 = net.mamoe.mirai.internal.network.protocol.data.proto.ImMsgBody .ElemFlags2 (
71
+ msgRptCnt = 1 ,
72
+ ),
73
+ ),
74
+ net.mamoe.mirai.internal.network.protocol.data.proto.ImMsgBody .Elem (
75
+ generalFlags = net.mamoe.mirai.internal.network.protocol.data.proto.ImMsgBody .GeneralFlags (
76
+ pbReserve = " " .hexToBytes(),
77
+ ),
78
+ ),
79
+ net.mamoe.mirai.internal.network.protocol.data.proto.ImMsgBody .Elem (
80
+ extraInfo = net.mamoe.mirai.internal.network.protocol.data.proto.ImMsgBody .ExtraInfo (
81
+ nick = " user2" ,
82
+ level = 1 ,
83
+ groupMask = 1 ,
84
+ ),
85
+ ),
86
+ ),
87
+ ),
88
+ ),
89
+ ),
90
+ svrip = 1579509002 ,
91
+ generalFlag = 1 ,
92
+ )
93
+ }
94
+
95
+ setBot(1230002 ).apply {
96
+ addGroup(2230203L , 1230001 ).apply {
97
+ addMember(1230001 , permission = MemberPermission .OWNER )
98
+ addMember(1230002 , permission = MemberPermission .MEMBER )
99
+ }
100
+ }
101
+
102
+ runTest().toList().run {
103
+ assertEquals(1 , size, toString())
104
+ get(0 ).run {
105
+ assertIs<GroupMessageSyncEvent >(this )
106
+ assertEquals(2230203 , group.id)
107
+ assertEquals(1230002 , sender.id)
108
+ assertEquals(" s" , message.content)
109
+ }
110
+ }
111
+
112
+ }
113
+
114
+
115
+ @Test
116
+ suspend fun `can receive friend sync from macOS client` () {
117
+ suspend fun runTest () = use {
118
+ bot.components[SsoProcessor ].firstLoginSucceed = true
119
+ attributes[KEY_FROM_SYNC ] = true
120
+
121
+ net.mamoe.mirai.internal.network.protocol.data.proto.MsgComm .Msg (
122
+ msgHead = net.mamoe.mirai.internal.network.protocol.data.proto.MsgComm .MsgHead (
123
+ fromUin = 1230002 ,
124
+ toUin = 1230001 ,
125
+ msgType = 166 ,
126
+ c2cCmd = 11 ,
127
+ msgSeq = 13887 ,
128
+ msgTime = 1640030199 ,
129
+ msgUid = 72057594845425959 ,
130
+ fromAppid = 1001 ,
131
+ fromInstid = 537067835 ,
132
+ userActive = 1 ,
133
+ ),
134
+ msgBody = net.mamoe.mirai.internal.network.protocol.data.proto.ImMsgBody .MsgBody (
135
+ richText = net.mamoe.mirai.internal.network.protocol.data.proto.ImMsgBody .RichText (
136
+ attr = net.mamoe.mirai.internal.network.protocol.data.proto.ImMsgBody .Attr (
137
+ codePage = 0 ,
138
+ time = 1640030199 ,
139
+ random = 807498023 ,
140
+ size = 9 ,
141
+ effect = 0 ,
142
+ charSet = 134 ,
143
+ pitchAndFamily = 0 ,
144
+ fontName = " Helvetica" ,
145
+ ),
146
+ elems = mutableListOf (
147
+ net.mamoe.mirai.internal.network.protocol.data.proto.ImMsgBody .Elem (
148
+ text = net.mamoe.mirai.internal.network.protocol.data.proto.ImMsgBody .Text (
149
+ str = " hi" ,
150
+ ),
151
+ ),
152
+ net.mamoe.mirai.internal.network.protocol.data.proto.ImMsgBody .Elem (
153
+ ),
154
+ net.mamoe.mirai.internal.network.protocol.data.proto.ImMsgBody .Elem (
155
+ generalFlags = net.mamoe.mirai.internal.network.protocol.data.proto.ImMsgBody .GeneralFlags (
156
+ pbReserve = " 78 00 C8 01 00 F0 01 00 F8 01 00 90 02 00 CA 04 00" .hexToBytes(),
157
+ ),
158
+ ),
159
+ ),
160
+ ),
161
+ ),
162
+ )
163
+ }
164
+
165
+ setBot(1230002 ).apply {
166
+ addFriend(1230001 )
167
+ }
168
+
169
+ runTest().toList().run {
170
+ assertEquals(1 , size, toString())
171
+ get(0 ).run {
172
+ assertIs<FriendMessageSyncEvent >(this )
173
+ assertEquals(1230001 , friend.id)
174
+ assertEquals(" hi" , message.content)
175
+ }
176
+ }
177
+
178
+ }
179
+ }
0 commit comments