github.com/LagrangeDev/LagrangeGo@v0.0.0-20240512064304-ad4a85e10cb4/client/event/group.go (about) 1 package event 2 3 import ( 4 "github.com/LagrangeDev/LagrangeGo/client/packets/pb/message" 5 "github.com/LagrangeDev/LagrangeGo/utils" 6 ) 7 8 type ( 9 GroupEvent struct { 10 GroupUin uint32 11 } 12 13 GroupMute struct { 14 GroupEvent 15 OperatorUid string 16 TargetUid string // when TargetUid is empty, mute all members 17 Duration uint32 // Duration == math.MaxUint32 when means mute all 18 } 19 20 GroupRecall struct { 21 GroupEvent 22 AuthorUid string 23 OperatorUid string 24 Sequence uint64 25 Time uint32 26 Random uint32 27 } 28 29 GroupMemberJoinRequest struct { 30 GroupEvent 31 TargetUid string 32 InvitorUid string 33 Answer string // 问题:(.*)答案:(.*) 34 } 35 36 GroupMemberIncrease struct { 37 GroupEvent 38 MemberUid string 39 InvitorUid string 40 JoinType uint32 41 } 42 43 GroupMemberDecrease struct { 44 GroupEvent 45 MemberUid string 46 OperatorUid string 47 ExitType uint32 48 } 49 ) 50 51 type GroupInvite struct { 52 GroupUin uint32 53 InvitorUid string 54 } 55 56 func (gmd *GroupMemberDecrease) IsKicked() bool { 57 return gmd.ExitType == 131 || gmd.ExitType == 3 58 } 59 60 // ParseRequestJoinNotice 主动加群 61 func ParseRequestJoinNotice(event *message.GroupJoin) *GroupMemberJoinRequest { 62 return &GroupMemberJoinRequest{ 63 GroupEvent: GroupEvent{ 64 GroupUin: event.GroupUin, 65 }, 66 TargetUid: event.TargetUid, 67 Answer: event.RequestField.Unwrap(), 68 } 69 } 70 71 // ParseRequestInvitationNotice 邀请加群 72 func ParseRequestInvitationNotice(event *message.GroupInvitation) *GroupMemberJoinRequest { 73 if event.Cmd == 87 { 74 inn := event.Info.Inner 75 return &GroupMemberJoinRequest{ 76 GroupEvent: GroupEvent{ 77 GroupUin: inn.GroupUin, 78 }, 79 TargetUid: inn.TargetUid, 80 InvitorUid: inn.InvitorUid, 81 } 82 } 83 return nil 84 } 85 86 // ParseInviteNotice 被邀请加群 87 func ParseInviteNotice(event *message.GroupInvite) *GroupInvite { 88 return &GroupInvite{ 89 GroupUin: event.GroupUin, 90 InvitorUid: event.InvitorUid, 91 } 92 } 93 94 func ParseMemberIncreaseEvent(event *message.GroupChange) *GroupMemberIncrease { 95 return &GroupMemberIncrease{ 96 GroupEvent: GroupEvent{ 97 GroupUin: event.GroupUin, 98 }, 99 MemberUid: event.MemberUid, 100 InvitorUid: utils.B2S(event.Operator), 101 JoinType: event.IncreaseType, 102 } 103 } 104 105 func ParseMemberDecreaseEvent(event *message.GroupChange) *GroupMemberDecrease { 106 return &GroupMemberDecrease{ 107 GroupEvent: GroupEvent{ 108 GroupUin: event.GroupUin, 109 }, 110 MemberUid: event.MemberUid, 111 OperatorUid: utils.B2S(event.Operator), 112 ExitType: event.DecreaseType, 113 } 114 } 115 116 func ParseGroupRecallEvent(event *message.NotifyMessageBody) *GroupRecall { 117 info := event.Recall.RecallMessages[0] 118 result := GroupRecall{ 119 GroupEvent: GroupEvent{ 120 GroupUin: event.GroupUin, 121 }, 122 AuthorUid: info.AuthorUid, 123 OperatorUid: event.Recall.OperatorUid.Unwrap(), 124 Sequence: info.Sequence, 125 Time: info.Time, 126 Random: info.Random, 127 } 128 return &result 129 } 130 131 func ParseGroupMuteEvent(event *message.GroupMute) *GroupMute { 132 return &GroupMute{ 133 GroupEvent: GroupEvent{ 134 GroupUin: event.GroupUin, 135 }, 136 OperatorUid: event.OperatorUid.Unwrap(), 137 TargetUid: event.Data.State.TargetUid.Unwrap(), 138 Duration: event.Data.State.Duration, 139 } 140 }