mirror of
https://github.com/Mrs4s/MiraiGo.git
synced 2025-05-04 11:07:40 +08:00
add event: NewFriendEvent.
This commit is contained in:
parent
626638e899
commit
7a84cfae67
@ -39,7 +39,7 @@ qq-android协议的golang实现 移植于mirai
|
||||
- [x] 群成员权限变更
|
||||
- [x] 收到邀请进群通知
|
||||
- [x] 收到其他用户进群请求
|
||||
- [ ] 新好友
|
||||
- [x] 新好友
|
||||
- [x] 新好友请求
|
||||
- [x] 客户端离线
|
||||
|
||||
|
@ -546,6 +546,17 @@ func decodeOnlinePushReqPacket(c *QQClient, seq uint16, payload []byte) (interfa
|
||||
})
|
||||
}
|
||||
}
|
||||
case 0xB3:
|
||||
b3 := pb.SubB3{}
|
||||
if err := proto.Unmarshal(probuf, &b3); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
frd := &FriendInfo{
|
||||
Uin: b3.MsgAddFrdNotify.Uin,
|
||||
Nickname: b3.MsgAddFrdNotify.Nick,
|
||||
}
|
||||
c.FriendList = append(c.FriendList, frd)
|
||||
c.dispatchNewFriendEvent(&NewFriendEvent{Friend: frd})
|
||||
case 0xD4:
|
||||
d4 := pb.SubD4{}
|
||||
if err := proto.Unmarshal(probuf, &d4); err != nil {
|
||||
|
@ -150,6 +150,10 @@ type (
|
||||
client *QQClient
|
||||
}
|
||||
|
||||
NewFriendEvent struct {
|
||||
Friend *FriendInfo
|
||||
}
|
||||
|
||||
groupMemberListResponse struct {
|
||||
NextUin int64
|
||||
list []*GroupMemberInfo
|
||||
|
@ -1,6 +1,7 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/Mrs4s/MiraiGo/message"
|
||||
"sync"
|
||||
)
|
||||
@ -20,6 +21,7 @@ type eventHandlers struct {
|
||||
groupInvitedHandlers []func(*QQClient, *GroupInvitedRequest)
|
||||
joinRequestHandlers []func(*QQClient, *UserJoinGroupRequest)
|
||||
friendRequestHandlers []func(*QQClient, *NewFriendRequest)
|
||||
newFriendHandlers []func(*QQClient, *NewFriendEvent)
|
||||
disconnectHandlers []func(*QQClient, *ClientDisconnectedEvent)
|
||||
groupMessageReceiptHandlers sync.Map
|
||||
}
|
||||
@ -88,6 +90,10 @@ func (c *QQClient) OnNewFriendRequest(f func(*QQClient, *NewFriendRequest)) {
|
||||
c.eventHandlers.friendRequestHandlers = append(c.eventHandlers.friendRequestHandlers, f)
|
||||
}
|
||||
|
||||
func (c *QQClient) OnNewFriendAdded(f func(*QQClient, *NewFriendEvent)) {
|
||||
c.eventHandlers.newFriendHandlers = append(c.eventHandlers.newFriendHandlers, f)
|
||||
}
|
||||
|
||||
func (c *QQClient) OnDisconnected(f func(*QQClient, *ClientDisconnectedEvent)) {
|
||||
c.eventHandlers.disconnectHandlers = append(c.eventHandlers.disconnectHandlers, f)
|
||||
}
|
||||
@ -267,6 +273,17 @@ func (c *QQClient) dispatchNewFriendRequest(r *NewFriendRequest) {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *QQClient) dispatchNewFriendEvent(e *NewFriendEvent) {
|
||||
if e == nil {
|
||||
return
|
||||
}
|
||||
for _, f := range c.eventHandlers.newFriendHandlers {
|
||||
cover(func() {
|
||||
f(c, e)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (c *QQClient) dispatchDisconnectEvent(e *ClientDisconnectedEvent) {
|
||||
if e == nil {
|
||||
return
|
||||
@ -281,7 +298,7 @@ func (c *QQClient) dispatchDisconnectEvent(e *ClientDisconnectedEvent) {
|
||||
func cover(f func()) {
|
||||
defer func() {
|
||||
if pan := recover(); pan != nil {
|
||||
|
||||
fmt.Println("event error:", pan)
|
||||
}
|
||||
}()
|
||||
f()
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.25.0
|
||||
// protoc v3.12.3
|
||||
// protoc v3.11.4
|
||||
// source: data.proto
|
||||
|
||||
package pb
|
||||
@ -2259,6 +2259,116 @@ func (x *Sub8AMsgInfo) GetDevSeq() int32 {
|
||||
return 0
|
||||
}
|
||||
|
||||
type SubB3 struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Type int32 `protobuf:"varint,1,opt,name=type,proto3" json:"type,omitempty"`
|
||||
MsgAddFrdNotify *SubB3AddFrdNotify `protobuf:"bytes,2,opt,name=msgAddFrdNotify,proto3" json:"msgAddFrdNotify,omitempty"`
|
||||
}
|
||||
|
||||
func (x *SubB3) Reset() {
|
||||
*x = SubB3{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_data_proto_msgTypes[23]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *SubB3) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*SubB3) ProtoMessage() {}
|
||||
|
||||
func (x *SubB3) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_data_proto_msgTypes[23]
|
||||
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 SubB3.ProtoReflect.Descriptor instead.
|
||||
func (*SubB3) Descriptor() ([]byte, []int) {
|
||||
return file_data_proto_rawDescGZIP(), []int{23}
|
||||
}
|
||||
|
||||
func (x *SubB3) GetType() int32 {
|
||||
if x != nil {
|
||||
return x.Type
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *SubB3) GetMsgAddFrdNotify() *SubB3AddFrdNotify {
|
||||
if x != nil {
|
||||
return x.MsgAddFrdNotify
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type SubB3AddFrdNotify struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Uin int64 `protobuf:"varint,1,opt,name=uin,proto3" json:"uin,omitempty"`
|
||||
Nick string `protobuf:"bytes,5,opt,name=nick,proto3" json:"nick,omitempty"`
|
||||
}
|
||||
|
||||
func (x *SubB3AddFrdNotify) Reset() {
|
||||
*x = SubB3AddFrdNotify{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_data_proto_msgTypes[24]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *SubB3AddFrdNotify) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*SubB3AddFrdNotify) ProtoMessage() {}
|
||||
|
||||
func (x *SubB3AddFrdNotify) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_data_proto_msgTypes[24]
|
||||
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 SubB3AddFrdNotify.ProtoReflect.Descriptor instead.
|
||||
func (*SubB3AddFrdNotify) Descriptor() ([]byte, []int) {
|
||||
return file_data_proto_rawDescGZIP(), []int{24}
|
||||
}
|
||||
|
||||
func (x *SubB3AddFrdNotify) GetUin() int64 {
|
||||
if x != nil {
|
||||
return x.Uin
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *SubB3AddFrdNotify) GetNick() string {
|
||||
if x != nil {
|
||||
return x.Nick
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
var File_data_proto protoreflect.FileDescriptor
|
||||
|
||||
var file_data_proto_rawDesc = []byte{
|
||||
@ -2603,8 +2713,17 @@ var file_data_proto_rawDesc = []byte{
|
||||
0x4e, 0x75, 0x6d, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x6b, 0x67, 0x49, 0x6e, 0x64, 0x65, 0x78, 0x18,
|
||||
0x08, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x70, 0x6b, 0x67, 0x49, 0x6e, 0x64, 0x65, 0x78, 0x12,
|
||||
0x16, 0x0a, 0x06, 0x64, 0x65, 0x76, 0x53, 0x65, 0x71, 0x18, 0x09, 0x20, 0x01, 0x28, 0x05, 0x52,
|
||||
0x06, 0x64, 0x65, 0x76, 0x53, 0x65, 0x71, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62,
|
||||
0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
0x06, 0x64, 0x65, 0x76, 0x53, 0x65, 0x71, 0x22, 0x59, 0x0a, 0x05, 0x53, 0x75, 0x62, 0x42, 0x33,
|
||||
0x12, 0x12, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04,
|
||||
0x74, 0x79, 0x70, 0x65, 0x12, 0x3c, 0x0a, 0x0f, 0x6d, 0x73, 0x67, 0x41, 0x64, 0x64, 0x46, 0x72,
|
||||
0x64, 0x4e, 0x6f, 0x74, 0x69, 0x66, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x12, 0x2e,
|
||||
0x53, 0x75, 0x62, 0x42, 0x33, 0x41, 0x64, 0x64, 0x46, 0x72, 0x64, 0x4e, 0x6f, 0x74, 0x69, 0x66,
|
||||
0x79, 0x52, 0x0f, 0x6d, 0x73, 0x67, 0x41, 0x64, 0x64, 0x46, 0x72, 0x64, 0x4e, 0x6f, 0x74, 0x69,
|
||||
0x66, 0x79, 0x22, 0x39, 0x0a, 0x11, 0x53, 0x75, 0x62, 0x42, 0x33, 0x41, 0x64, 0x64, 0x46, 0x72,
|
||||
0x64, 0x4e, 0x6f, 0x74, 0x69, 0x66, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x69, 0x6e, 0x18, 0x01,
|
||||
0x20, 0x01, 0x28, 0x03, 0x52, 0x03, 0x75, 0x69, 0x6e, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x69, 0x63,
|
||||
0x6b, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x69, 0x63, 0x6b, 0x42, 0x06, 0x5a,
|
||||
0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
}
|
||||
|
||||
var (
|
||||
@ -2619,7 +2738,7 @@ func file_data_proto_rawDescGZIP() []byte {
|
||||
return file_data_proto_rawDescData
|
||||
}
|
||||
|
||||
var file_data_proto_msgTypes = make([]protoimpl.MessageInfo, 23)
|
||||
var file_data_proto_msgTypes = make([]protoimpl.MessageInfo, 25)
|
||||
var file_data_proto_goTypes = []interface{}{
|
||||
(*DeviceInfo)(nil), // 0: DeviceInfo
|
||||
(*RequestBody)(nil), // 1: RequestBody
|
||||
@ -2644,6 +2763,8 @@ var file_data_proto_goTypes = []interface{}{
|
||||
(*SubD4)(nil), // 20: SubD4
|
||||
(*Sub8A)(nil), // 21: Sub8A
|
||||
(*Sub8AMsgInfo)(nil), // 22: Sub8AMsgInfo
|
||||
(*SubB3)(nil), // 23: SubB3
|
||||
(*SubB3AddFrdNotify)(nil), // 24: SubB3AddFrdNotify
|
||||
}
|
||||
var file_data_proto_depIdxs = []int32{
|
||||
2, // 0: RequestBody.rpt_config_list:type_name -> ConfigSeq
|
||||
@ -2660,11 +2781,12 @@ var file_data_proto_depIdxs = []int32{
|
||||
18, // 11: NotifyMsgBody.optMsgRecall:type_name -> MessageRecallReminder
|
||||
19, // 12: MessageRecallReminder.recalledMsgList:type_name -> RecalledMessageMeta
|
||||
22, // 13: Sub8A.msg_info:type_name -> Sub8AMsgInfo
|
||||
14, // [14:14] is the sub-list for method output_type
|
||||
14, // [14:14] is the sub-list for method input_type
|
||||
14, // [14:14] is the sub-list for extension type_name
|
||||
14, // [14:14] is the sub-list for extension extendee
|
||||
0, // [0:14] is the sub-list for field type_name
|
||||
24, // 14: SubB3.msgAddFrdNotify:type_name -> SubB3AddFrdNotify
|
||||
15, // [15:15] is the sub-list for method output_type
|
||||
15, // [15:15] is the sub-list for method input_type
|
||||
15, // [15:15] is the sub-list for extension type_name
|
||||
15, // [15:15] is the sub-list for extension extendee
|
||||
0, // [0:15] is the sub-list for field type_name
|
||||
}
|
||||
|
||||
func init() { file_data_proto_init() }
|
||||
@ -2949,6 +3071,30 @@ func file_data_proto_init() {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_data_proto_msgTypes[23].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*SubB3); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_data_proto_msgTypes[24].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*SubB3AddFrdNotify); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
type x struct{}
|
||||
out := protoimpl.TypeBuilder{
|
||||
@ -2956,7 +3102,7 @@ func file_data_proto_init() {
|
||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||
RawDescriptor: file_data_proto_rawDesc,
|
||||
NumEnums: 0,
|
||||
NumMessages: 23,
|
||||
NumMessages: 25,
|
||||
NumExtensions: 0,
|
||||
NumServices: 0,
|
||||
},
|
||||
|
@ -245,3 +245,13 @@ message Sub8AMsgInfo {
|
||||
int32 pkgIndex = 8;
|
||||
int32 devSeq = 9;
|
||||
}
|
||||
|
||||
message SubB3 {
|
||||
int32 type = 1;
|
||||
SubB3AddFrdNotify msgAddFrdNotify = 2;
|
||||
}
|
||||
|
||||
message SubB3AddFrdNotify {
|
||||
int64 uin = 1;
|
||||
string nick = 5;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user