1
0
mirror of https://github.com/Mrs4s/MiraiGo.git synced 2025-05-04 19:17:38 +08:00

supported LeaveGroupEvent.

This commit is contained in:
Mrs4s 2020-07-14 02:40:22 +08:00
parent c4107d335f
commit c6b4c61122
7 changed files with 137 additions and 30 deletions

View File

@ -15,6 +15,5 @@ qq-android协议的golang实现 移植于Mirai
| 好友消息发送 | 正在做| | 好友消息发送 | 正在做|
| 群消息接受 |完成| | 群消息接受 |完成|
| 群消息发送 | 50% (仅支持 文本/图片/表情)| | 群消息发送 | 50% (仅支持 文本/图片/表情)|
| QQ各种事件 | 正在做, 已支持 群内禁言/群内消息撤回/加群 | | QQ各种事件 | 正在做, 已支持 群内禁言/群内消息撤回/加群/新成员进群 |
| MiraiGo文档 | 咕咕| | MiraiGo文档 | 咕咕|
| QQ协议说明文档| 自用整理 有空了应该会做|

View File

@ -14,6 +14,7 @@ import (
"math/rand" "math/rand"
"net" "net"
"strconv" "strconv"
"sync"
"sync/atomic" "sync/atomic"
"time" "time"
) )
@ -57,6 +58,8 @@ type QQClient struct {
messageSeq int32 messageSeq int32
groupDataTransSeq int32 groupDataTransSeq int32
eventHandlers *eventHandlers eventHandlers *eventHandlers
groupListLock *sync.Mutex
} }
type loginSigInfo struct { type loginSigInfo struct {
@ -109,6 +112,7 @@ func NewClientMd5(uin int64, passwordMd5 [16]byte) *QQClient {
messageSeq: 22911, messageSeq: 22911,
ksid: []byte("|454001228437590|A8.2.7.27f6ea96"), ksid: []byte("|454001228437590|A8.2.7.27f6ea96"),
eventHandlers: &eventHandlers{}, eventHandlers: &eventHandlers{},
groupListLock: new(sync.Mutex),
} }
rand.Read(cli.RandomKey) rand.Read(cli.RandomKey)
return cli return cli
@ -267,6 +271,8 @@ func (c *QQClient) ReloadGroupList() error {
} }
func (c *QQClient) GetGroupList() ([]*GroupInfo, error) { func (c *QQClient) GetGroupList() ([]*GroupInfo, error) {
c.groupListLock.Lock()
defer c.groupListLock.Unlock()
rsp, err := c.sendAndWait(c.buildGroupListRequestPacket()) rsp, err := c.sendAndWait(c.buildGroupListRequestPacket())
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -385,6 +385,24 @@ func decodeOnlinePushReqPacket(c *QQClient, seq uint16, payload []byte) (interfa
} }
} }
} }
if m.MsgType == 528 {
vr := jce.NewJceReader(m.VMsg)
subType := vr.ReadInt64(0)
probuf := vr.ReadAny(10).([]byte)
switch subType {
case 0xD4:
d4 := pb.SubD4{}
if err := proto.Unmarshal(probuf, &d4); err != nil {
return nil, err
}
if g := c.FindGroup(d4.Uin); g != nil {
if err := c.ReloadGroupList(); err != nil {
return nil, err
}
c.dispatchLeaveGroupEvent(&GroupLeaveEvent{Group: g})
}
}
}
} }
return nil, nil return nil, nil
@ -396,5 +414,26 @@ func decodeOnlinePushTransPacket(c *QQClient, seq uint16, payload []byte) (inter
if err != nil { if err != nil {
return nil, err return nil, err
} }
data := binary.NewReader(info.MsgData)
if info.MsgType == 34 {
data.ReadInt32()
data.ReadByte()
_ = int64(uint32(data.ReadInt32()))
typ := int32(data.ReadByte())
operator := int64(uint32(data.ReadInt32()))
switch typ {
case 0x03:
if g := c.FindGroup(info.FromUin); g != nil {
if err = c.ReloadGroupList(); err != nil {
return nil, err
}
c.dispatchLeaveGroupEvent(&GroupLeaveEvent{
Group: g,
Operator: g.FindMember(operator),
})
}
}
}
return nil, nil return nil, nil
} }

View File

@ -76,6 +76,11 @@ type (
Time int32 Time int32
} }
GroupLeaveEvent struct {
Group *GroupInfo
Operator *GroupMemberInfo
}
groupMemberListResponse struct { groupMemberListResponse struct {
NextUin int64 NextUin int64
list []*GroupMemberInfo list []*GroupMemberInfo

View File

@ -1,43 +1,21 @@
package client package client
import ( import (
"errors"
"github.com/Mrs4s/MiraiGo/message" "github.com/Mrs4s/MiraiGo/message"
"sync" "sync"
) )
var ErrEventUndefined = errors.New("event undefined")
type eventHandlers struct { type eventHandlers struct {
privateMessageHandlers []func(*QQClient, *message.PrivateMessage) privateMessageHandlers []func(*QQClient, *message.PrivateMessage)
groupMessageHandlers []func(*QQClient, *message.GroupMessage) groupMessageHandlers []func(*QQClient, *message.GroupMessage)
groupMuteEventHandlers []func(*QQClient, *GroupMuteEvent) groupMuteEventHandlers []func(*QQClient, *GroupMuteEvent)
groupRecalledHandlers []func(*QQClient, *GroupMessageRecalledEvent) groupRecalledHandlers []func(*QQClient, *GroupMessageRecalledEvent)
joinGroupHandlers []func(*QQClient, *GroupInfo) joinGroupHandlers []func(*QQClient, *GroupInfo)
leaveGroupHandlers []func(*QQClient, *GroupLeaveEvent)
memberJoinedHandlers []func(*QQClient, *GroupInfo, *GroupMemberInfo) memberJoinedHandlers []func(*QQClient, *GroupInfo, *GroupMemberInfo)
groupMessageReceiptHandlers sync.Map groupMessageReceiptHandlers sync.Map
} }
func (c *QQClient) OnEvent(i interface{}) error {
switch f := i.(type) {
case func(*QQClient, *message.PrivateMessage):
c.OnPrivateMessage(f)
case func(*QQClient, *message.GroupMessage):
c.OnGroupMessage(f)
case func(*QQClient, *GroupMuteEvent):
c.OnGroupMuted(f)
case func(*QQClient, *GroupMessageRecalledEvent):
c.OnGroupMessageRecalled(f)
case func(*QQClient, *GroupInfo):
c.OnJoinGroup(f)
case func(*QQClient, *GroupInfo, *GroupMemberInfo):
c.OnGroupMemberJoined(f)
default:
return ErrEventUndefined
}
return nil
}
func (c *QQClient) OnPrivateMessage(f func(*QQClient, *message.PrivateMessage)) { func (c *QQClient) OnPrivateMessage(f func(*QQClient, *message.PrivateMessage)) {
c.eventHandlers.privateMessageHandlers = append(c.eventHandlers.privateMessageHandlers, f) c.eventHandlers.privateMessageHandlers = append(c.eventHandlers.privateMessageHandlers, f)
} }
@ -62,6 +40,10 @@ func (c *QQClient) OnJoinGroup(f func(*QQClient, *GroupInfo)) {
c.eventHandlers.joinGroupHandlers = append(c.eventHandlers.joinGroupHandlers, f) c.eventHandlers.joinGroupHandlers = append(c.eventHandlers.joinGroupHandlers, f)
} }
func (c *QQClient) OnLeaveGroup(f func(*QQClient, *GroupLeaveEvent)) {
c.eventHandlers.leaveGroupHandlers = append(c.eventHandlers.leaveGroupHandlers, f)
}
func (c *QQClient) OnGroupMemberJoined(f func(*QQClient, *GroupInfo, *GroupMemberInfo)) { func (c *QQClient) OnGroupMemberJoined(f func(*QQClient, *GroupInfo, *GroupMemberInfo)) {
c.eventHandlers.memberJoinedHandlers = append(c.eventHandlers.memberJoinedHandlers, f) c.eventHandlers.memberJoinedHandlers = append(c.eventHandlers.memberJoinedHandlers, f)
} }
@ -139,6 +121,17 @@ func (c *QQClient) dispatchJoinGroupEvent(group *GroupInfo) {
} }
} }
func (c *QQClient) dispatchLeaveGroupEvent(e *GroupLeaveEvent) {
if e == nil {
return
}
for _, f := range c.eventHandlers.leaveGroupHandlers {
cover(func() {
f(c, e)
})
}
}
func (c *QQClient) dispatchNewMemberEvent(group *GroupInfo, mem *GroupMemberInfo) { func (c *QQClient) dispatchNewMemberEvent(group *GroupInfo, mem *GroupMemberInfo) {
if group == nil || mem == nil { if group == nil || mem == nil {
return return

View File

@ -1711,6 +1711,53 @@ func (x *RecalledMessageMeta) GetAuthorUin() int64 {
return 0 return 0
} }
type SubD4 struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Uin int64 `protobuf:"varint,1,opt,name=uin,proto3" json:"uin,omitempty"`
}
func (x *SubD4) Reset() {
*x = SubD4{}
if protoimpl.UnsafeEnabled {
mi := &file_data_proto_msgTypes[18]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *SubD4) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*SubD4) ProtoMessage() {}
func (x *SubD4) ProtoReflect() protoreflect.Message {
mi := &file_data_proto_msgTypes[18]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use SubD4.ProtoReflect.Descriptor instead.
func (*SubD4) Descriptor() ([]byte, []int) {
return file_data_proto_rawDescGZIP(), []int{18}
}
func (x *SubD4) GetUin() int64 {
if x != nil {
return x.Uin
}
return 0
}
var File_data_proto protoreflect.FileDescriptor var File_data_proto protoreflect.FileDescriptor
var file_data_proto_rawDesc = []byte{ var file_data_proto_rawDesc = []byte{
@ -1971,8 +2018,9 @@ var file_data_proto_rawDesc = []byte{
0x6d, 0x73, 0x67, 0x46, 0x6c, 0x61, 0x67, 0x18, 0x05, 0x20, 0x01, 0x28, 0x05, 0x52, 0x07, 0x6d, 0x6d, 0x73, 0x67, 0x46, 0x6c, 0x61, 0x67, 0x18, 0x05, 0x20, 0x01, 0x28, 0x05, 0x52, 0x07, 0x6d,
0x73, 0x67, 0x46, 0x6c, 0x61, 0x67, 0x12, 0x1c, 0x0a, 0x09, 0x61, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x73, 0x67, 0x46, 0x6c, 0x61, 0x67, 0x12, 0x1c, 0x0a, 0x09, 0x61, 0x75, 0x74, 0x68, 0x6f, 0x72,
0x55, 0x69, 0x6e, 0x18, 0x06, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x61, 0x75, 0x74, 0x68, 0x6f, 0x55, 0x69, 0x6e, 0x18, 0x06, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x61, 0x75, 0x74, 0x68, 0x6f,
0x72, 0x55, 0x69, 0x6e, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x72, 0x55, 0x69, 0x6e, 0x22, 0x19, 0x0a, 0x05, 0x53, 0x75, 0x62, 0x44, 0x34, 0x12, 0x10, 0x0a,
0x6f, 0x74, 0x6f, 0x33, 0x03, 0x75, 0x69, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x03, 0x75, 0x69, 0x6e, 0x42,
0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
} }
var ( var (
@ -1987,7 +2035,7 @@ func file_data_proto_rawDescGZIP() []byte {
return file_data_proto_rawDescData return file_data_proto_rawDescData
} }
var file_data_proto_msgTypes = make([]protoimpl.MessageInfo, 18) var file_data_proto_msgTypes = make([]protoimpl.MessageInfo, 19)
var file_data_proto_goTypes = []interface{}{ var file_data_proto_goTypes = []interface{}{
(*DeviceInfo)(nil), // 0: DeviceInfo (*DeviceInfo)(nil), // 0: DeviceInfo
(*RequestBody)(nil), // 1: RequestBody (*RequestBody)(nil), // 1: RequestBody
@ -2007,6 +2055,7 @@ var file_data_proto_goTypes = []interface{}{
(*NotifyMsgBody)(nil), // 15: NotifyMsgBody (*NotifyMsgBody)(nil), // 15: NotifyMsgBody
(*MessageRecallReminder)(nil), // 16: MessageRecallReminder (*MessageRecallReminder)(nil), // 16: MessageRecallReminder
(*RecalledMessageMeta)(nil), // 17: RecalledMessageMeta (*RecalledMessageMeta)(nil), // 17: RecalledMessageMeta
(*SubD4)(nil), // 18: SubD4
} }
var file_data_proto_depIdxs = []int32{ var file_data_proto_depIdxs = []int32{
2, // 0: RequestBody.rpt_config_list:type_name -> ConfigSeq 2, // 0: RequestBody.rpt_config_list:type_name -> ConfigSeq
@ -2249,6 +2298,18 @@ func file_data_proto_init() {
return nil return nil
} }
} }
file_data_proto_msgTypes[18].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*SubD4); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
} }
type x struct{} type x struct{}
out := protoimpl.TypeBuilder{ out := protoimpl.TypeBuilder{
@ -2256,7 +2317,7 @@ func file_data_proto_init() {
GoPackagePath: reflect.TypeOf(x{}).PkgPath(), GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_data_proto_rawDesc, RawDescriptor: file_data_proto_rawDesc,
NumEnums: 0, NumEnums: 0,
NumMessages: 18, NumMessages: 19,
NumExtensions: 0, NumExtensions: 0,
NumServices: 0, NumServices: 0,
}, },

View File

@ -180,3 +180,7 @@ message RecalledMessageMeta {
int32 msgFlag = 5; int32 msgFlag = 5;
int64 authorUin = 6; int64 authorUin = 6;
} }
message SubD4 {
int64 uin = 1;
}