Skip to content

Commit

Permalink
[Core] fix operator in kick event (#704)
Browse files Browse the repository at this point in the history
  • Loading branch information
Redmomn authored Dec 6, 2024
1 parent 967c232 commit 6ec9012
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 9 deletions.
34 changes: 27 additions & 7 deletions Lagrange.Core/Internal/Packets/Message/Notify/GroupChange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
14 changes: 12 additions & 2 deletions Lagrange.Core/Internal/Service/Message/PushMessageService.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Text;
using Lagrange.Core.Common;
using Lagrange.Core.Internal.Event;
using Lagrange.Core.Internal.Event.Message;
Expand Down Expand Up @@ -88,14 +89,23 @@ protected override bool Parse(Span<byte> input, BotKeystore keystore, BotAppInfo
case PkgType.GroupMemberIncreaseNotice when message.Message.Body?.MsgContent is { } content:
{
var increase = Serializer.Deserialize<GroupChange>(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<GroupChange>(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<OperatorInfo>(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;
}
Expand Down

0 comments on commit 6ec9012

Please sign in to comment.