From 6ec90124ff4638f917bab8a2f3df56f847193acf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=84=91=E8=A2=8B=E9=87=8C=E8=BF=9B=E8=8A=B1=E7=94=9F?= =?UTF-8?q?=E4=BA=86?= <109732988+Redmomn@users.noreply.github.com> Date: Fri, 6 Dec 2024 13:30:34 +0800 Subject: [PATCH] [Core] fix operator in kick event (#704) --- .../Packets/Message/Notify/GroupChange.cs | 34 +++++++++++++++---- .../Service/Message/PushMessageService.cs | 14 ++++++-- 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/Lagrange.Core/Internal/Packets/Message/Notify/GroupChange.cs b/Lagrange.Core/Internal/Packets/Message/Notify/GroupChange.cs index bcb9fe19b..100b4a3f2 100644 --- a/Lagrange.Core/Internal/Packets/Message/Notify/GroupChange.cs +++ b/Lagrange.Core/Internal/Packets/Message/Notify/GroupChange.cs @@ -8,16 +8,36 @@ namespace Lagrange.Core.Internal.Packets.Message.Notify; internal class GroupChange { [ProtoMember(1)] public uint GroupUin { get; set; } - + [ProtoMember(2)] public uint Flag { get; set; } - + [ProtoMember(3)] public string MemberUid { get; set; } - + [ProtoMember(4)] public uint DecreaseType { get; set; } // 131 Kick 130 Exit - - [ProtoMember(5)] public string? OperatorUid { get; set; } - + + [ProtoMember(5)] public byte[]? Operator { get; set; } + [ProtoMember(6)] public uint IncreaseType { get; set; } - + [ProtoMember(7)] public byte[]? Field7 { get; set; } +} + +[ProtoContract] +internal class OperatorInfo +{ + [ProtoMember(1)] public OperatorField1 Operator { get; set; } +} + +[ProtoContract] +internal class OperatorField1 +{ + [ProtoMember(1)] public string? Uid { get; set; } + + [ProtoMember(2)] public uint Field2 { get; set; } + + [ProtoMember(3)] public byte[]? Field3 { get; set; } + + [ProtoMember(4)] public uint Field4 { get; set; } + + [ProtoMember(5)] public byte[]? Field5 { get; set; } } \ No newline at end of file diff --git a/Lagrange.Core/Internal/Service/Message/PushMessageService.cs b/Lagrange.Core/Internal/Service/Message/PushMessageService.cs index 04c1406aa..018ec2d39 100644 --- a/Lagrange.Core/Internal/Service/Message/PushMessageService.cs +++ b/Lagrange.Core/Internal/Service/Message/PushMessageService.cs @@ -1,3 +1,4 @@ +using System.Text; using Lagrange.Core.Common; using Lagrange.Core.Internal.Event; using Lagrange.Core.Internal.Event.Message; @@ -88,14 +89,23 @@ protected override bool Parse(Span input, BotKeystore keystore, BotAppInfo case PkgType.GroupMemberIncreaseNotice when message.Message.Body?.MsgContent is { } content: { var increase = Serializer.Deserialize(content.AsSpan()); - var increaseEvent = GroupSysIncreaseEvent.Result(increase.GroupUin, increase.MemberUid, increase.OperatorUid, increase.DecreaseType); + var increaseEvent = GroupSysIncreaseEvent.Result(increase.GroupUin, increase.MemberUid, Encoding.UTF8.GetString(increase.Operator.AsSpan()), increase.DecreaseType); extraEvents.Add(increaseEvent); break; } case PkgType.GroupMemberDecreaseNotice when message.Message.Body?.MsgContent is { } content: { var decrease = Serializer.Deserialize(content.AsSpan()); - var decreaseEvent = GroupSysDecreaseEvent.Result(decrease.GroupUin, decrease.MemberUid, decrease.OperatorUid, decrease.DecreaseType); + GroupSysDecreaseEvent decreaseEvent; + if (decrease.DecreaseType == 3) // 3 是bot自身被踢出,Operator字段会是一个protobuf + { + var op = Serializer.Deserialize(decrease.Operator.AsSpan()); + decreaseEvent = GroupSysDecreaseEvent.Result(decrease.GroupUin, decrease.MemberUid, op.Operator.Uid, decrease.DecreaseType); + } + else + { + decreaseEvent = GroupSysDecreaseEvent.Result(decrease.GroupUin, decrease.MemberUid, Encoding.UTF8.GetString(decrease.Operator.AsSpan()), decrease.DecreaseType); + } extraEvents.Add(decreaseEvent); break; }