From 5ea82a0af56b1af1c1e92acda71acbe846d4521f Mon Sep 17 00:00:00 2001 From: Huang Youzhen Date: Mon, 28 Jul 2025 02:28:03 +0800 Subject: [PATCH 1/8] =?UTF-8?q?[NativeAPI]=20=E4=BF=AE=E5=A4=8D=20BotKeyst?= =?UTF-8?q?ore=20=E4=BC=A0=E9=80=92=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Lagrange.Core.NativeAPI/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lagrange.Core.NativeAPI/Program.cs b/Lagrange.Core.NativeAPI/Program.cs index 08153242..269667c7 100644 --- a/Lagrange.Core.NativeAPI/Program.cs +++ b/Lagrange.Core.NativeAPI/Program.cs @@ -19,7 +19,7 @@ public static int Initialize(IntPtr botConfigPtr, IntPtr keystorePtr) if (keystorePtr != IntPtr.Zero) { var keystoreStruct = Marshal.PtrToStructure(keystorePtr); - var keystore = keystoreStruct; + var keystore = keystoreStruct.ToKeystoreWithoutFree(); Contexts.Add(new Context(BotFactory.Create(botConfig, keystore))); } else From 1b556a49026387b10c618b564a302c8081e0b3c5 Mon Sep 17 00:00:00 2001 From: Huang Youzhen Date: Tue, 29 Jul 2025 21:42:09 +0800 Subject: [PATCH 2/8] [NativeAPI] Fix Reply Enitity incorrect Initialization --- .../Message/Entity/ReplyEntityStruct.cs | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/Lagrange.Core.NativeAPI/NativeModel/Message/Entity/ReplyEntityStruct.cs b/Lagrange.Core.NativeAPI/NativeModel/Message/Entity/ReplyEntityStruct.cs index d3ac2734..bef982be 100644 --- a/Lagrange.Core.NativeAPI/NativeModel/Message/Entity/ReplyEntityStruct.cs +++ b/Lagrange.Core.NativeAPI/NativeModel/Message/Entity/ReplyEntityStruct.cs @@ -10,13 +10,13 @@ public struct ReplyEntityStruct public ReplyEntityStruct() { } public ulong SrcUid; - + public int SrcSequence; - + public IntPtr Source; public int SourceType; - + public static implicit operator ReplyEntityStruct(ReplyEntity entity) { var type = entity.Source switch @@ -26,15 +26,25 @@ public static implicit operator ReplyEntityStruct(ReplyEntity entity) BotStranger => 3, _ => 0 }; - + var sourcePtr = type switch { - 1 => Marshal.AllocHGlobal(Marshal.SizeOf()), - 2 => Marshal.AllocHGlobal(Marshal.SizeOf()), - 3 => Marshal.AllocHGlobal(Marshal.SizeOf()), + 1 => Marshal.AllocHGlobal(Marshal.SizeOf()), + 2 => Marshal.AllocHGlobal(Marshal.SizeOf()), + 3 => Marshal.AllocHGlobal(Marshal.SizeOf()), _ => IntPtr.Zero }; - + + if (entity.Source != null && sourcePtr != 0) + { + switch (type) + { + case 1: Marshal.StructureToPtr((BotFriendStruct)(BotFriend)entity.Source, sourcePtr, false); break; + case 2: Marshal.StructureToPtr((BotGroupMemberStruct)(BotGroupMember)entity.Source, sourcePtr, false); break; + case 3: Marshal.StructureToPtr((BotStrangerStruct)(BotStranger)entity.Source, sourcePtr, false); break; + } + } + return new ReplyEntityStruct { SrcUid = entity.SrcUid, From 4f96fe02a104d4eb2ea276336aebd5b54a70edcb Mon Sep 17 00:00:00 2001 From: Huang Youzhen Date: Sat, 2 Aug 2025 13:14:55 +0800 Subject: [PATCH 3/8] =?UTF-8?q?[NativeAPI]=20=E4=BF=AE=E5=A4=8D=E8=B0=83?= =?UTF-8?q?=E7=94=A8=20SendGroupMessage=20=E6=96=B9=E6=B3=95=E6=97=B6?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E6=B6=88=E6=81=AF=E7=BB=93=E6=9E=84=E4=BD=93?= =?UTF-8?q?=E6=9E=84=E9=80=A0=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../NativeModel/Message/BotMessageStruct.cs | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/Lagrange.Core.NativeAPI/NativeModel/Message/BotMessageStruct.cs b/Lagrange.Core.NativeAPI/NativeModel/Message/BotMessageStruct.cs index 83846e4e..135acacb 100644 --- a/Lagrange.Core.NativeAPI/NativeModel/Message/BotMessageStruct.cs +++ b/Lagrange.Core.NativeAPI/NativeModel/Message/BotMessageStruct.cs @@ -1,4 +1,4 @@ -using System.Runtime.InteropServices; +using System.Runtime.InteropServices; using System.Text; using Lagrange.Core.Common.Entity; using Lagrange.Core.Message; @@ -13,19 +13,19 @@ namespace Lagrange.Core.NativeAPI.NativeModel.Message public struct BotMessageStruct { public BotMessageStruct() { } - + //需要手动释放 public IntPtr Contact = IntPtr.Zero; public IntPtr Receiver = IntPtr.Zero; - + public BotGroupStruct Group = new(); - + public int Type = 0; - + public ByteArrayNative Time = new(); public IntPtr Entities = IntPtr.Zero; - + public int EntityLength = 0; public static implicit operator BotMessageStruct(BotMessage message) @@ -39,8 +39,19 @@ public static implicit operator BotMessageStruct(BotMessage message) type = (int)MessageType.Group; contact = Marshal.AllocHGlobal(Marshal.SizeOf()); Marshal.StructureToPtr((BotGroupMemberStruct)(BotGroupMember)message.Contact, contact, false); - receiver = Marshal.AllocHGlobal(Marshal.SizeOf()); - Marshal.StructureToPtr((BotGroupMemberStruct)(BotGroupMember)message.Receiver, receiver, false); + + switch (message.Receiver) + { + case BotGroup: + receiver = Marshal.AllocHGlobal(Marshal.SizeOf()); + Marshal.StructureToPtr((BotGroupStruct)(BotGroup)message.Receiver, receiver, false); + break; + case BotGroupMember: + receiver = Marshal.AllocHGlobal(Marshal.SizeOf()); + Marshal.StructureToPtr((BotGroupMemberStruct)(BotGroupMember)message.Receiver, receiver, false); + break; + } + break; case MessageType.Private: type = (int)MessageType.Private; @@ -129,7 +140,7 @@ public static implicit operator BotMessageStruct(BotMessage message) IntPtr entityPtr = entitiesPtr + i * Marshal.SizeOf(); Marshal.StructureToPtr(entities[i], entityPtr, false); } - + return new BotMessageStruct() { Contact = contact, From be657aca7e866102a4875feee53c5eeb1cbfa697 Mon Sep 17 00:00:00 2001 From: Huang Youzhen Date: Tue, 5 Aug 2025 19:32:32 +0800 Subject: [PATCH 4/8] =?UTF-8?q?[NativeAPI]=20=E5=BC=A5=E8=A1=A5=E4=BA=86?= =?UTF-8?q?=20BotMessageStruct=20=E7=9A=84=20Group=20=E6=88=90=E5=91=98?= =?UTF-8?q?=E7=BC=BA=E6=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../NativeModel/Message/BotMessageStruct.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Lagrange.Core.NativeAPI/NativeModel/Message/BotMessageStruct.cs b/Lagrange.Core.NativeAPI/NativeModel/Message/BotMessageStruct.cs index 135acacb..64601a3d 100644 --- a/Lagrange.Core.NativeAPI/NativeModel/Message/BotMessageStruct.cs +++ b/Lagrange.Core.NativeAPI/NativeModel/Message/BotMessageStruct.cs @@ -145,7 +145,12 @@ public static implicit operator BotMessageStruct(BotMessage message) { Contact = contact, Receiver = receiver, - // Group = message.Group ?? new BotGroupStruct(), + Group = message.Receiver switch + { + BotGroup => (BotGroupStruct)message.Receiver, + BotGroupMember => ((BotGroupMember)message.Receiver).Group, + _ => new BotGroupStruct(), + }, Type = type, Time = Encoding.UTF8.GetBytes(message.Time.ToString("O")), Entities = entitiesPtr, From 6d11220950270bec30ca8201c29fe6ecace39197 Mon Sep 17 00:00:00 2001 From: Huang Youzhen Date: Tue, 5 Aug 2025 22:51:28 +0800 Subject: [PATCH 5/8] =?UTF-8?q?[NativeAPI]=20=E8=A7=A3=E5=86=B3BotMessageS?= =?UTF-8?q?truct=E6=9E=84=E9=80=A0=E4=B8=AD=E8=BD=AC=E6=8D=A2=E9=9A=90?= =?UTF-8?q?=E6=82=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../NativeModel/Message/BotMessageStruct.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Lagrange.Core.NativeAPI/NativeModel/Message/BotMessageStruct.cs b/Lagrange.Core.NativeAPI/NativeModel/Message/BotMessageStruct.cs index 64601a3d..426276f9 100644 --- a/Lagrange.Core.NativeAPI/NativeModel/Message/BotMessageStruct.cs +++ b/Lagrange.Core.NativeAPI/NativeModel/Message/BotMessageStruct.cs @@ -42,13 +42,13 @@ public static implicit operator BotMessageStruct(BotMessage message) switch (message.Receiver) { - case BotGroup: + case BotGroup group: receiver = Marshal.AllocHGlobal(Marshal.SizeOf()); - Marshal.StructureToPtr((BotGroupStruct)(BotGroup)message.Receiver, receiver, false); + Marshal.StructureToPtr((BotGroupStruct)group, receiver, false); break; - case BotGroupMember: + case BotGroupMember member: receiver = Marshal.AllocHGlobal(Marshal.SizeOf()); - Marshal.StructureToPtr((BotGroupMemberStruct)(BotGroupMember)message.Receiver, receiver, false); + Marshal.StructureToPtr((BotGroupMemberStruct)member, receiver, false); break; } @@ -147,8 +147,8 @@ public static implicit operator BotMessageStruct(BotMessage message) Receiver = receiver, Group = message.Receiver switch { - BotGroup => (BotGroupStruct)message.Receiver, - BotGroupMember => ((BotGroupMember)message.Receiver).Group, + BotGroup group => (BotGroupStruct)group, + BotGroupMember member => member.Group, _ => new BotGroupStruct(), }, Type = type, From 047a9443e1fa0dce8dc9923eb12822665bb3570e Mon Sep 17 00:00:00 2001 From: Huang Youzhen Date: Sun, 17 Aug 2025 02:08:14 +0800 Subject: [PATCH 6/8] =?UTF-8?q?[Core=20&=20NativeAPI]=20=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=20Core=20=E6=96=B0=E5=A2=9E=EF=BC=8C=E5=B9=B6=E7=BA=A0?= =?UTF-8?q?=E6=AD=A3=E4=BA=86=20Core=20=E4=B8=AD=E7=9A=84=E5=B0=8F?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../NativeModel/ReverseEventCountStruct.cs | 6 +- .../BotGroupInviteNotificationEventStruct.cs | 27 ++++++++ .../BotGroupJoinNotificationEventStruct.cs | 27 ++++++++ .../BotGroupMemberDecreaseEventStruct.cs | 31 +++++++++ .../Event/BotGroupNudgeEventStruct.cs | 31 +++++++++ .../Event/ReverseEventCountStruct.cs | 6 +- .../NativeModel/Message/BotStrangerStruct.cs | 34 ++++++++-- .../BotGroupInviteNotificationReverseEvent.cs | 18 +++++ .../BotGroupJoinNotificationReverseEvent.cs | 18 +++++ .../BotGroupMemberDecreaseReverseEvent.cs | 18 +++++ .../ReverseEvent/BotGroupNudgeReverseEvent.cs | 18 +++++ .../ReverseEvent/EventEntryPoint.cs | 68 ++++++++++++++++++- .../ReverseEvent/ReverseEventInvoker.cs | 16 ++++- .../EventArgs/BotGroupMemberDecreaseEvent.cs | 2 +- 14 files changed, 308 insertions(+), 12 deletions(-) create mode 100644 Lagrange.Core.NativeAPI/NativeModel/Event/BotGroupInviteNotificationEventStruct.cs create mode 100644 Lagrange.Core.NativeAPI/NativeModel/Event/BotGroupJoinNotificationEventStruct.cs create mode 100644 Lagrange.Core.NativeAPI/NativeModel/Event/BotGroupMemberDecreaseEventStruct.cs create mode 100644 Lagrange.Core.NativeAPI/NativeModel/Event/BotGroupNudgeEventStruct.cs create mode 100644 Lagrange.Core.NativeAPI/ReverseEvent/BotGroupInviteNotificationReverseEvent.cs create mode 100644 Lagrange.Core.NativeAPI/ReverseEvent/BotGroupJoinNotificationReverseEvent.cs create mode 100644 Lagrange.Core.NativeAPI/ReverseEvent/BotGroupMemberDecreaseReverseEvent.cs create mode 100644 Lagrange.Core.NativeAPI/ReverseEvent/BotGroupNudgeReverseEvent.cs diff --git a/Lagrange.Core.NativeAPI.Test/NativeModel/ReverseEventCountStruct.cs b/Lagrange.Core.NativeAPI.Test/NativeModel/ReverseEventCountStruct.cs index a36dacd5..22e9941c 100644 --- a/Lagrange.Core.NativeAPI.Test/NativeModel/ReverseEventCountStruct.cs +++ b/Lagrange.Core.NativeAPI.Test/NativeModel/ReverseEventCountStruct.cs @@ -1,4 +1,4 @@ -using System.Runtime.InteropServices; +using System.Runtime.InteropServices; namespace Lagrange.Core.NativeAPI.Test.NativeModel; @@ -8,6 +8,10 @@ public struct ReverseEventCountStruct public ReverseEventCountStruct() { } public int BotCaptchaEventCount = 0; + public int BotGroupInviteNotificationEventCount = 0; + public int BotGroupJoinNotificationEventCount = 0; + public int BotGroupMemberDecreaseEventCount = 0; + public int BotGroupNudgeEventCount = 0; public int BotLoginEventCount = 0; public int BotLogEventCount = 0; public int BotMessageEventCount = 0; diff --git a/Lagrange.Core.NativeAPI/NativeModel/Event/BotGroupInviteNotificationEventStruct.cs b/Lagrange.Core.NativeAPI/NativeModel/Event/BotGroupInviteNotificationEventStruct.cs new file mode 100644 index 00000000..325f1d03 --- /dev/null +++ b/Lagrange.Core.NativeAPI/NativeModel/Event/BotGroupInviteNotificationEventStruct.cs @@ -0,0 +1,27 @@ +using System.Runtime.InteropServices; +using Lagrange.Core.Common.Entity; +using Lagrange.Core.Events.EventArgs; + +namespace Lagrange.Core.NativeAPI.NativeModel.Event +{ + [StructLayout(LayoutKind.Sequential)] + public struct BotGroupInviteNotificationEventStruct(BotGroupInviteNotification notification) : IEventStruct + { + public BotGroupInviteNotification Notification = notification; + + //public static implicit operator BotGroupMemberDecreaseEvent(BotGroupMemberDecreaseEventStruct e) + //{ + // return new BotGroupMemberDecreaseEvent( + // e.GroupUin, e.UserUin, e.OperatorUin + // ); + //} + + public static implicit operator BotGroupInviteNotificationEventStruct(BotGroupInviteNotificationEvent e) + { + return new BotGroupInviteNotificationEventStruct() + { + Notification = e.Notification + }; + } + } +} \ No newline at end of file diff --git a/Lagrange.Core.NativeAPI/NativeModel/Event/BotGroupJoinNotificationEventStruct.cs b/Lagrange.Core.NativeAPI/NativeModel/Event/BotGroupJoinNotificationEventStruct.cs new file mode 100644 index 00000000..dbd3b6be --- /dev/null +++ b/Lagrange.Core.NativeAPI/NativeModel/Event/BotGroupJoinNotificationEventStruct.cs @@ -0,0 +1,27 @@ +using System.Runtime.InteropServices; +using Lagrange.Core.Common.Entity; +using Lagrange.Core.Events.EventArgs; + +namespace Lagrange.Core.NativeAPI.NativeModel.Event +{ + [StructLayout(LayoutKind.Sequential)] + public struct BotGroupJoinNotificationEventStruct(BotGroupJoinNotification notification) : IEventStruct + { + public BotGroupJoinNotification Notification = notification; + + //public static implicit operator BotGroupJoinNotificationEvent(BotGroupJoinNotificationEventStruct e) + //{ + // return new BotGroupJoinNotificationEvent( + // e.Notification + // ); + //} + + public static implicit operator BotGroupJoinNotificationEventStruct(BotGroupJoinNotificationEvent e) + { + return new BotGroupJoinNotificationEventStruct() + { + Notification = e.Notification + }; + } + } +} \ No newline at end of file diff --git a/Lagrange.Core.NativeAPI/NativeModel/Event/BotGroupMemberDecreaseEventStruct.cs b/Lagrange.Core.NativeAPI/NativeModel/Event/BotGroupMemberDecreaseEventStruct.cs new file mode 100644 index 00000000..9778522b --- /dev/null +++ b/Lagrange.Core.NativeAPI/NativeModel/Event/BotGroupMemberDecreaseEventStruct.cs @@ -0,0 +1,31 @@ +using System.Runtime.InteropServices; +using Lagrange.Core.Events.EventArgs; + +namespace Lagrange.Core.NativeAPI.NativeModel.Event +{ + [StructLayout(LayoutKind.Sequential)] + public struct BotGroupMemberDecreaseEventStruct : IEventStruct + { + public BotGroupMemberDecreaseEventStruct() { } + public Int64 GroupUin = 0; + public Int64 UserUin = 0; + public Int64 OperatorUin = 0; + + //public static implicit operator BotGroupMemberDecreaseEvent(BotGroupMemberDecreaseEventStruct e) + //{ + // return new BotGroupMemberDecreaseEvent( + // e.GroupUin, e.UserUin, e.OperatorUin + // ); + //} + + public static implicit operator BotGroupMemberDecreaseEventStruct(BotGroupMemberDecreaseEvent e) + { + return new BotGroupMemberDecreaseEventStruct() + { + GroupUin = e.GroupUin, + UserUin = e.UserUin, + OperatorUin = e.OperatorUin ?? 0 + }; + } + } +} \ No newline at end of file diff --git a/Lagrange.Core.NativeAPI/NativeModel/Event/BotGroupNudgeEventStruct.cs b/Lagrange.Core.NativeAPI/NativeModel/Event/BotGroupNudgeEventStruct.cs new file mode 100644 index 00000000..46101cff --- /dev/null +++ b/Lagrange.Core.NativeAPI/NativeModel/Event/BotGroupNudgeEventStruct.cs @@ -0,0 +1,31 @@ +using System.Runtime.InteropServices; +using Lagrange.Core.Events.EventArgs; + +namespace Lagrange.Core.NativeAPI.NativeModel.Event +{ + [StructLayout(LayoutKind.Sequential)] + public struct BotGroupNudgeEventStruct : IEventStruct + { + public BotGroupNudgeEventStruct() { } + public Int64 GroupUin = 0; + public Int64 OperatorUin = 0; + public Int64 TargetUin = 0; + + public static implicit operator BotGroupNudgeEvent(BotGroupNudgeEventStruct e) + { + return new BotGroupNudgeEvent( + e.GroupUin, e.OperatorUin, e.TargetUin + ); + } + + public static implicit operator BotGroupNudgeEventStruct(BotGroupNudgeEvent e) + { + return new BotGroupNudgeEventStruct() + { + GroupUin = e.GroupUin, + OperatorUin = e.OperatorUin, + TargetUin = e.TargetUin + }; + } + } +} \ No newline at end of file diff --git a/Lagrange.Core.NativeAPI/NativeModel/Event/ReverseEventCountStruct.cs b/Lagrange.Core.NativeAPI/NativeModel/Event/ReverseEventCountStruct.cs index caffb702..f0e9e98a 100644 --- a/Lagrange.Core.NativeAPI/NativeModel/Event/ReverseEventCountStruct.cs +++ b/Lagrange.Core.NativeAPI/NativeModel/Event/ReverseEventCountStruct.cs @@ -1,4 +1,4 @@ -using System.Runtime.InteropServices; +using System.Runtime.InteropServices; namespace Lagrange.Core.NativeAPI.NativeModel.Event { @@ -8,6 +8,10 @@ public struct ReverseEventCountStruct public ReverseEventCountStruct() { } public int BotCaptchaEventCount = 0; + public int BotGroupInviteNotificationEventCount = 0; + public int BotGroupJoinNotificationEventCount = 0; + public int BotGroupMemberDecreaseEventCount = 0; + public int BotGroupNudgeEventCount = 0; public int BotLoginEventCount = 0; public int BotLogEventCount = 0; public int BotMessageEventCount = 0; diff --git a/Lagrange.Core.NativeAPI/NativeModel/Message/BotStrangerStruct.cs b/Lagrange.Core.NativeAPI/NativeModel/Message/BotStrangerStruct.cs index 10e96a8f..4b46768d 100644 --- a/Lagrange.Core.NativeAPI/NativeModel/Message/BotStrangerStruct.cs +++ b/Lagrange.Core.NativeAPI/NativeModel/Message/BotStrangerStruct.cs @@ -1,5 +1,6 @@ -using System.Runtime.InteropServices; +using System.Runtime.InteropServices; using System.Text; +using Lagrange.Core.Common; using Lagrange.Core.Common.Entity; using Lagrange.Core.NativeAPI.NativeModel.Common; @@ -12,17 +13,33 @@ public BotStrangerStruct() { } public long Uin = 0; public ByteArrayNative Nickname = new(); public ByteArrayNative Uid = new(); + public ByteArrayNative PersonalSign = new(); + public ByteArrayNative Remark = new(); + public ulong Level = new(); + public int Gender = 0; + public long RegistrationTime = 0; + public long Birthday = 0; + public ulong Age = 0; + public ByteArrayNative QID = new(); public long Source = 0; - + public static implicit operator BotStranger(BotStrangerStruct stranger) { return new BotStranger( stranger.Uin, Encoding.UTF8.GetString(stranger.Nickname), - Encoding.UTF8.GetString(stranger.Uid) + Encoding.UTF8.GetString(stranger.Uid), + Encoding.UTF8.GetString(stranger.PersonalSign), + Encoding.UTF8.GetString(stranger.Remark), + stranger.Level, + (BotGender)stranger.Gender, + DateTimeOffset.FromUnixTimeSeconds(stranger.RegistrationTime).LocalDateTime, + DateTimeOffset.FromUnixTimeSeconds(stranger.Birthday).LocalDateTime, + stranger.Age, + Encoding.UTF8.GetString(stranger.QID) ); } - + public static implicit operator BotStrangerStruct(BotStranger stranger) { return new BotStrangerStruct() @@ -30,7 +47,14 @@ public static implicit operator BotStrangerStruct(BotStranger stranger) Uin = stranger.Uin, Nickname = Encoding.UTF8.GetBytes(stranger.Nickname), Uid = Encoding.UTF8.GetBytes(stranger.Uid), - Source = stranger.Source + PersonalSign = Encoding.UTF8.GetBytes(stranger.PersonalSign), + Remark = Encoding.UTF8.GetBytes(stranger.Remark), + Level = stranger.Level, + Gender = (int)stranger.Gender, + RegistrationTime = new DateTimeOffset(stranger.RegistrationTime).ToUnixTimeSeconds(), + Birthday = new DateTimeOffset(stranger.Birthday ?? new()).ToUnixTimeSeconds(), + Age = stranger.Age, + QID = Encoding.UTF8.GetBytes(stranger.QID) }; } } diff --git a/Lagrange.Core.NativeAPI/ReverseEvent/BotGroupInviteNotificationReverseEvent.cs b/Lagrange.Core.NativeAPI/ReverseEvent/BotGroupInviteNotificationReverseEvent.cs new file mode 100644 index 00000000..4471c059 --- /dev/null +++ b/Lagrange.Core.NativeAPI/ReverseEvent/BotGroupInviteNotificationReverseEvent.cs @@ -0,0 +1,18 @@ +using Lagrange.Core.Events.EventArgs; +using Lagrange.Core.NativeAPI.NativeModel; +using Lagrange.Core.NativeAPI.NativeModel.Event; +using Lagrange.Core.NativeAPI.ReverseEvent.Abstract; + +namespace Lagrange.Core.NativeAPI.ReverseEvent +{ + public class BotGroupInviteNotificationReverseEvent : ReverseEventBase + { + public override void RegisterEventHandler(BotContext context) + { + context.EventInvoker.RegisterEvent((ctx, e) => + { + Events.Add((BotGroupInviteNotificationEventStruct)e); + }); + } + } +} \ No newline at end of file diff --git a/Lagrange.Core.NativeAPI/ReverseEvent/BotGroupJoinNotificationReverseEvent.cs b/Lagrange.Core.NativeAPI/ReverseEvent/BotGroupJoinNotificationReverseEvent.cs new file mode 100644 index 00000000..a290efad --- /dev/null +++ b/Lagrange.Core.NativeAPI/ReverseEvent/BotGroupJoinNotificationReverseEvent.cs @@ -0,0 +1,18 @@ +using Lagrange.Core.Events.EventArgs; +using Lagrange.Core.NativeAPI.NativeModel; +using Lagrange.Core.NativeAPI.NativeModel.Event; +using Lagrange.Core.NativeAPI.ReverseEvent.Abstract; + +namespace Lagrange.Core.NativeAPI.ReverseEvent +{ + public class BotGroupJoinNotificationReverseEvent : ReverseEventBase + { + public override void RegisterEventHandler(BotContext context) + { + context.EventInvoker.RegisterEvent((ctx, e) => + { + Events.Add((BotGroupJoinNotificationEventStruct)e); + }); + } + } +} \ No newline at end of file diff --git a/Lagrange.Core.NativeAPI/ReverseEvent/BotGroupMemberDecreaseReverseEvent.cs b/Lagrange.Core.NativeAPI/ReverseEvent/BotGroupMemberDecreaseReverseEvent.cs new file mode 100644 index 00000000..48657bb9 --- /dev/null +++ b/Lagrange.Core.NativeAPI/ReverseEvent/BotGroupMemberDecreaseReverseEvent.cs @@ -0,0 +1,18 @@ +using Lagrange.Core.Events.EventArgs; +using Lagrange.Core.NativeAPI.NativeModel; +using Lagrange.Core.NativeAPI.NativeModel.Event; +using Lagrange.Core.NativeAPI.ReverseEvent.Abstract; + +namespace Lagrange.Core.NativeAPI.ReverseEvent +{ + public class BotGroupMemberDecreaseReverseEvent : ReverseEventBase + { + public override void RegisterEventHandler(BotContext context) + { + context.EventInvoker.RegisterEvent((ctx, e) => + { + Events.Add((BotGroupMemberDecreaseEventStruct)e); + }); + } + } +} \ No newline at end of file diff --git a/Lagrange.Core.NativeAPI/ReverseEvent/BotGroupNudgeReverseEvent.cs b/Lagrange.Core.NativeAPI/ReverseEvent/BotGroupNudgeReverseEvent.cs new file mode 100644 index 00000000..28e4a7c2 --- /dev/null +++ b/Lagrange.Core.NativeAPI/ReverseEvent/BotGroupNudgeReverseEvent.cs @@ -0,0 +1,18 @@ +using Lagrange.Core.Events.EventArgs; +using Lagrange.Core.NativeAPI.NativeModel; +using Lagrange.Core.NativeAPI.NativeModel.Event; +using Lagrange.Core.NativeAPI.ReverseEvent.Abstract; + +namespace Lagrange.Core.NativeAPI.ReverseEvent +{ + public class BotGroupNudgeReverseEvent : ReverseEventBase + { + public override void RegisterEventHandler(BotContext context) + { + context.EventInvoker.RegisterEvent((ctx, e) => + { + Events.Add((BotGroupNudgeEventStruct)e); + }); + } + } +} \ No newline at end of file diff --git a/Lagrange.Core.NativeAPI/ReverseEvent/EventEntryPoint.cs b/Lagrange.Core.NativeAPI/ReverseEvent/EventEntryPoint.cs index 0ea99b07..54e83c50 100644 --- a/Lagrange.Core.NativeAPI/ReverseEvent/EventEntryPoint.cs +++ b/Lagrange.Core.NativeAPI/ReverseEvent/EventEntryPoint.cs @@ -1,4 +1,4 @@ -using System.Runtime.InteropServices; +using System.Runtime.InteropServices; using Lagrange.Core.Events; using Lagrange.Core.NativeAPI.NativeModel.Event; using Lagrange.Core.NativeAPI.ReverseEvent.Abstract; @@ -13,6 +13,10 @@ public static IntPtr GetEventCount(int index) var eventCount = new ReverseEventCountStruct { BotCaptchaEventCount = Program.Contexts[index].EventInvoker.BotCaptchaEvent.Events.Count, + BotGroupInviteNotificationEventCount = Program.Contexts[index].EventInvoker.BotGroupInviteNotificationEvent.Events.Count, + BotGroupJoinNotificationEventCount = Program.Contexts[index].EventInvoker.BotGroupJoinNotificationEvent.Events.Count, + BotGroupMemberDecreaseEventCount = Program.Contexts[index].EventInvoker.BotGroupMemberDecreaseEvent.Events.Count, + BotGroupNudgeEventCount = Program.Contexts[index].EventInvoker.BotGroupNudgeEvent.Events.Count, BotLoginEventCount = Program.Contexts[index].EventInvoker.BotLoginEvent.Events.Count, BotLogEventCount = Program.Contexts[index].EventInvoker.BotLogEvent.Events.Count, BotMessageEventCount = Program.Contexts[index].EventInvoker.BotMessageEvent.Events.Count, @@ -44,7 +48,67 @@ public static IntPtr GetCaptchaEvent(int index) return eventPtr; } - + + [UnmanagedCallersOnly(EntryPoint = "GroupInviteNotificationEvent")] + public static IntPtr GetGroupInviteNotificationEvent(int index) + { + if (index >= Program.Contexts.Count) + { + return IntPtr.Zero; + } + + var botGroupInviteNotificationEvent = Program.Contexts[index].EventInvoker.BotGroupInviteNotificationEvent; + + IntPtr eventPtr = GetEventStructPtr(botGroupInviteNotificationEvent); + + return eventPtr; + } + + [UnmanagedCallersOnly(EntryPoint = "GetGroupJoinNotificationEvent")] + public static IntPtr GetGroupJoinNotificationEvent(int index) + { + if (index >= Program.Contexts.Count) + { + return IntPtr.Zero; + } + + var botGroupJoinNotificationEvent = Program.Contexts[index].EventInvoker.BotGroupJoinNotificationEvent; + + IntPtr eventPtr = GetEventStructPtr(botGroupJoinNotificationEvent); + + return eventPtr; + } + + [UnmanagedCallersOnly(EntryPoint = "GetGroupMemberDecreaseEvent")] + public static IntPtr GetGroupMemberDecreaseEvent(int index) + { + if (index >= Program.Contexts.Count) + { + return IntPtr.Zero; + } + + var botGroupMemberDecreaseEvent = Program.Contexts[index].EventInvoker.BotGroupMemberDecreaseEvent; + + IntPtr eventPtr = GetEventStructPtr(botGroupMemberDecreaseEvent); + + return eventPtr; + } + + [UnmanagedCallersOnly(EntryPoint = "GetGroupNudgeEvent")] + public static IntPtr GetGroupNudgeEvent(int index) + { + if (index >= Program.Contexts.Count) + { + return IntPtr.Zero; + } + + var botGroupNudgeEvent = Program.Contexts[index].EventInvoker.BotGroupNudgeEvent; + + IntPtr eventPtr = GetEventStructPtr(botGroupNudgeEvent); + + return eventPtr; + } + [UnmanagedCallersOnly(EntryPoint = "GetLoginEvent")] public static IntPtr GetLoginEvent(int index) { diff --git a/Lagrange.Core.NativeAPI/ReverseEvent/ReverseEventInvoker.cs b/Lagrange.Core.NativeAPI/ReverseEvent/ReverseEventInvoker.cs index 898d3425..73bf6404 100644 --- a/Lagrange.Core.NativeAPI/ReverseEvent/ReverseEventInvoker.cs +++ b/Lagrange.Core.NativeAPI/ReverseEvent/ReverseEventInvoker.cs @@ -1,4 +1,4 @@ -using Lagrange.Core.NativeAPI.ReverseEvent.Abstract; +using Lagrange.Core.NativeAPI.ReverseEvent.Abstract; namespace Lagrange.Core.NativeAPI.ReverseEvent { @@ -7,6 +7,10 @@ public class ReverseEventInvoker public ReverseEventInvoker(BotContext context) { BotCaptchaEvent.RegisterEventHandler(context); + BotGroupInviteNotificationEvent.RegisterEventHandler(context); + BotGroupJoinNotificationEvent.RegisterEventHandler(context); + BotGroupMemberDecreaseEvent.RegisterEventHandler(context); + BotGroupNudgeEvent.RegisterEventHandler(context); BotLoginEvent.RegisterEventHandler(context); BotLogEvent.RegisterEventHandler(context); BotMessageEvent.RegisterEventHandler(context); @@ -18,7 +22,15 @@ public ReverseEventInvoker(BotContext context) } public BotCaptchaReverseEvent BotCaptchaEvent { get; } = new(); - + + public BotGroupInviteNotificationReverseEvent BotGroupInviteNotificationEvent { get; } = new(); + + public BotGroupJoinNotificationReverseEvent BotGroupJoinNotificationEvent { get; } = new(); + + public BotGroupMemberDecreaseReverseEvent BotGroupMemberDecreaseEvent { get; } = new(); + + public BotGroupNudgeReverseEvent BotGroupNudgeEvent { get; } = new(); + public BotLoginReverseEvent BotLoginEvent { get; } = new(); public BotLogReverseEvent BotLogEvent { get; } = new(); diff --git a/Lagrange.Core/Events/EventArgs/BotGroupMemberDecreaseEvent.cs b/Lagrange.Core/Events/EventArgs/BotGroupMemberDecreaseEvent.cs index 35795a77..f922c73b 100644 --- a/Lagrange.Core/Events/EventArgs/BotGroupMemberDecreaseEvent.cs +++ b/Lagrange.Core/Events/EventArgs/BotGroupMemberDecreaseEvent.cs @@ -10,6 +10,6 @@ public class BotGroupMemberDecreaseEvent(long groupUin, long userUin, long? oper public override string ToEventMessage() { - return $"{nameof(BotGroupNudgeEvent)}: GroupUin={GroupUin}, OperatorUin={OperatorUin}, TargetUin={UserUin}"; + return $"{nameof(BotGroupMemberDecreaseEvent)}: GroupUin={GroupUin}, UserUin={UserUin}, OperatorUin={OperatorUin}"; } } \ No newline at end of file From 5d5e9efd2847e3acf6f5a8e3433752cde9d0df19 Mon Sep 17 00:00:00 2001 From: Huang Youzhen Date: Sun, 17 Aug 2025 03:02:58 +0800 Subject: [PATCH 7/8] =?UTF-8?q?[NativeAPI]=20=E7=BA=A0=E6=AD=A3=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E7=9A=84=E6=8E=A5=E5=8F=A3=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../NativeModel/Message/BotStrangerStruct.cs | 2 +- Lagrange.Core.NativeAPI/ReverseEvent/EventEntryPoint.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Lagrange.Core.NativeAPI/NativeModel/Message/BotStrangerStruct.cs b/Lagrange.Core.NativeAPI/NativeModel/Message/BotStrangerStruct.cs index 4b46768d..92a48965 100644 --- a/Lagrange.Core.NativeAPI/NativeModel/Message/BotStrangerStruct.cs +++ b/Lagrange.Core.NativeAPI/NativeModel/Message/BotStrangerStruct.cs @@ -15,7 +15,7 @@ public BotStrangerStruct() { } public ByteArrayNative Uid = new(); public ByteArrayNative PersonalSign = new(); public ByteArrayNative Remark = new(); - public ulong Level = new(); + public ulong Level = 0; public int Gender = 0; public long RegistrationTime = 0; public long Birthday = 0; diff --git a/Lagrange.Core.NativeAPI/ReverseEvent/EventEntryPoint.cs b/Lagrange.Core.NativeAPI/ReverseEvent/EventEntryPoint.cs index 54e83c50..13914fcb 100644 --- a/Lagrange.Core.NativeAPI/ReverseEvent/EventEntryPoint.cs +++ b/Lagrange.Core.NativeAPI/ReverseEvent/EventEntryPoint.cs @@ -49,7 +49,7 @@ public static IntPtr GetCaptchaEvent(int index) return eventPtr; } - [UnmanagedCallersOnly(EntryPoint = "GroupInviteNotificationEvent")] + [UnmanagedCallersOnly(EntryPoint = "GetGroupInviteNotificationEvent")] public static IntPtr GetGroupInviteNotificationEvent(int index) { if (index >= Program.Contexts.Count) From 2215f385b9034267aabcd29db5804130a0b0cece Mon Sep 17 00:00:00 2001 From: Huang Youzhen Date: Thu, 21 Aug 2025 20:35:23 +0800 Subject: [PATCH 8/8] =?UTF-8?q?[NativeAPI]=20=E5=90=8C=E6=AD=A5=20Core=20?= =?UTF-8?q?=E7=9A=84=E5=8A=9F=E8=83=BD=E6=B7=BB=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../NativeModel/ReverseEventCountStruct.cs | 3 + .../Event/BotFriendRequestEventStruct.cs | 40 ++++++++ .../Event/BotGroupInviteSelfEventStruct.cs | 34 +++++++ .../Event/BotGroupReactionEventStruct.cs | 38 ++++++++ .../Event/ReverseEventCountStruct.cs | 3 + .../BotFriendRequestReverseEvent.cs | 18 ++++ .../BotGroupInviteSelfReverseEvent.cs | 18 ++++ .../BotGroupReactionReverseEvent.cs | 18 ++++ .../ReverseEvent/EventEntryPoint.cs | 94 ++++++++++++++----- .../ReverseEvent/ReverseEventInvoker.cs | 27 ++++-- 10 files changed, 261 insertions(+), 32 deletions(-) create mode 100644 Lagrange.Core.NativeAPI/NativeModel/Event/BotFriendRequestEventStruct.cs create mode 100644 Lagrange.Core.NativeAPI/NativeModel/Event/BotGroupInviteSelfEventStruct.cs create mode 100644 Lagrange.Core.NativeAPI/NativeModel/Event/BotGroupReactionEventStruct.cs create mode 100644 Lagrange.Core.NativeAPI/ReverseEvent/BotFriendRequestReverseEvent.cs create mode 100644 Lagrange.Core.NativeAPI/ReverseEvent/BotGroupInviteSelfReverseEvent.cs create mode 100644 Lagrange.Core.NativeAPI/ReverseEvent/BotGroupReactionReverseEvent.cs diff --git a/Lagrange.Core.NativeAPI.Test/NativeModel/ReverseEventCountStruct.cs b/Lagrange.Core.NativeAPI.Test/NativeModel/ReverseEventCountStruct.cs index 22e9941c..2a3fff2d 100644 --- a/Lagrange.Core.NativeAPI.Test/NativeModel/ReverseEventCountStruct.cs +++ b/Lagrange.Core.NativeAPI.Test/NativeModel/ReverseEventCountStruct.cs @@ -8,10 +8,13 @@ public struct ReverseEventCountStruct public ReverseEventCountStruct() { } public int BotCaptchaEventCount = 0; + public int BotFriendRequestEventCount = 0; public int BotGroupInviteNotificationEventCount = 0; + public int BotGroupInviteSelfEventCount = 0; public int BotGroupJoinNotificationEventCount = 0; public int BotGroupMemberDecreaseEventCount = 0; public int BotGroupNudgeEventCount = 0; + public int BotGroupReactionEventCount = 0; public int BotLoginEventCount = 0; public int BotLogEventCount = 0; public int BotMessageEventCount = 0; diff --git a/Lagrange.Core.NativeAPI/NativeModel/Event/BotFriendRequestEventStruct.cs b/Lagrange.Core.NativeAPI/NativeModel/Event/BotFriendRequestEventStruct.cs new file mode 100644 index 00000000..f55d0a67 --- /dev/null +++ b/Lagrange.Core.NativeAPI/NativeModel/Event/BotFriendRequestEventStruct.cs @@ -0,0 +1,40 @@ +using System.Runtime.InteropServices; +using System.Text; +using Lagrange.Core.Common.Entity; +using Lagrange.Core.Events.EventArgs; +using Lagrange.Core.NativeAPI.NativeModel.Common; + +namespace Lagrange.Core.NativeAPI.NativeModel.Event +{ + [StructLayout(LayoutKind.Sequential)] + public struct BotFriendRequestEventStruct : IEventStruct + { + public BotFriendRequestEventStruct() { } + + public ByteArrayNative InitiatorUid = new(); + + public long InitiatorUin = 0; + + public ByteArrayNative Message = new(); + + public ByteArrayNative Source = new(); + + //public static implicit operator BotGroupMemberDecreaseEvent(BotGroupMemberDecreaseEventStruct e) + //{ + // return new BotGroupMemberDecreaseEvent( + // e.GroupUin, e.UserUin, e.OperatorUin + // ); + //} + + public static implicit operator BotFriendRequestEventStruct(BotFriendRequestEvent e) + { + return new BotFriendRequestEventStruct() + { + InitiatorUid = Encoding.UTF8.GetBytes(e.InitiatorUid), + InitiatorUin = e.InitiatorUin, + Message = Encoding.UTF8.GetBytes(e.Message), + Source = Encoding.UTF8.GetBytes(e.Source) + }; + } + } +} \ No newline at end of file diff --git a/Lagrange.Core.NativeAPI/NativeModel/Event/BotGroupInviteSelfEventStruct.cs b/Lagrange.Core.NativeAPI/NativeModel/Event/BotGroupInviteSelfEventStruct.cs new file mode 100644 index 00000000..8488584c --- /dev/null +++ b/Lagrange.Core.NativeAPI/NativeModel/Event/BotGroupInviteSelfEventStruct.cs @@ -0,0 +1,34 @@ +using System.Runtime.InteropServices; +using Lagrange.Core.Events.EventArgs; + +namespace Lagrange.Core.NativeAPI.NativeModel.Event +{ + [StructLayout(LayoutKind.Sequential)] + public struct BotGroupInviteSelfEventStruct : IEventStruct + { + public BotGroupInviteSelfEventStruct() { } + + public long InvitationSeq = 0; + + public long InitiatorUin = 0; + + public long GroupUin = 0; + + //public static implicit operator BotGroupMemberDecreaseEvent(BotGroupMemberDecreaseEventStruct e) + //{ + // return new BotGroupMemberDecreaseEvent( + // e.GroupUin, e.UserUin, e.OperatorUin + // ); + //} + + public static implicit operator BotGroupInviteSelfEventStruct(BotGroupInviteSelfEvent e) + { + return new BotGroupInviteSelfEventStruct() + { + InvitationSeq = e.InvitationSeq, + InitiatorUin = e.InitiatorUin, + GroupUin = e.GroupUin + }; + } + } +} \ No newline at end of file diff --git a/Lagrange.Core.NativeAPI/NativeModel/Event/BotGroupReactionEventStruct.cs b/Lagrange.Core.NativeAPI/NativeModel/Event/BotGroupReactionEventStruct.cs new file mode 100644 index 00000000..aef6ae42 --- /dev/null +++ b/Lagrange.Core.NativeAPI/NativeModel/Event/BotGroupReactionEventStruct.cs @@ -0,0 +1,38 @@ +using System.Runtime.InteropServices; +using System.Text; +using Lagrange.Core.Events.EventArgs; +using Lagrange.Core.NativeAPI.NativeModel.Common; + +namespace Lagrange.Core.NativeAPI.NativeModel.Event +{ + [StructLayout(LayoutKind.Sequential)] + public struct BotGroupReactionEventStruct : IEventStruct + { + public BotGroupReactionEventStruct() { } + + public long TargetGroupUin = 0; + + public ulong TargetSequence = 0; + + public long OperatorUin = 0; + + public bool IsAdd = false; + + public ByteArrayNative Code = new(); + + public ulong CurrentCount = 0; + + public static implicit operator BotGroupReactionEventStruct(BotGroupReactionEvent e) + { + return new BotGroupReactionEventStruct() + { + TargetGroupUin = e.TargetGroupUin, + TargetSequence = e.TargetSequence, + OperatorUin = e.OperatorUin, + IsAdd = e.IsAdd, + Code = Encoding.UTF8.GetBytes(e.Code), + CurrentCount = e.CurrentCount + }; + } + } +} \ No newline at end of file diff --git a/Lagrange.Core.NativeAPI/NativeModel/Event/ReverseEventCountStruct.cs b/Lagrange.Core.NativeAPI/NativeModel/Event/ReverseEventCountStruct.cs index f0e9e98a..ac0a4f4d 100644 --- a/Lagrange.Core.NativeAPI/NativeModel/Event/ReverseEventCountStruct.cs +++ b/Lagrange.Core.NativeAPI/NativeModel/Event/ReverseEventCountStruct.cs @@ -8,10 +8,13 @@ public struct ReverseEventCountStruct public ReverseEventCountStruct() { } public int BotCaptchaEventCount = 0; + public int BotFriendRequestEventCount = 0; public int BotGroupInviteNotificationEventCount = 0; + public int BotGroupInviteSelfEventCount = 0; public int BotGroupJoinNotificationEventCount = 0; public int BotGroupMemberDecreaseEventCount = 0; public int BotGroupNudgeEventCount = 0; + public int BotGroupReactionEventCount = 0; public int BotLoginEventCount = 0; public int BotLogEventCount = 0; public int BotMessageEventCount = 0; diff --git a/Lagrange.Core.NativeAPI/ReverseEvent/BotFriendRequestReverseEvent.cs b/Lagrange.Core.NativeAPI/ReverseEvent/BotFriendRequestReverseEvent.cs new file mode 100644 index 00000000..b4537e68 --- /dev/null +++ b/Lagrange.Core.NativeAPI/ReverseEvent/BotFriendRequestReverseEvent.cs @@ -0,0 +1,18 @@ +using Lagrange.Core.Events.EventArgs; +using Lagrange.Core.NativeAPI.NativeModel; +using Lagrange.Core.NativeAPI.NativeModel.Event; +using Lagrange.Core.NativeAPI.ReverseEvent.Abstract; + +namespace Lagrange.Core.NativeAPI.ReverseEvent +{ + public class BotFriendRequestReverseEvent : ReverseEventBase + { + public override void RegisterEventHandler(BotContext context) + { + context.EventInvoker.RegisterEvent((ctx, e) => + { + Events.Add((BotFriendRequestEventStruct)e); + }); + } + } +} \ No newline at end of file diff --git a/Lagrange.Core.NativeAPI/ReverseEvent/BotGroupInviteSelfReverseEvent.cs b/Lagrange.Core.NativeAPI/ReverseEvent/BotGroupInviteSelfReverseEvent.cs new file mode 100644 index 00000000..3a5a4b60 --- /dev/null +++ b/Lagrange.Core.NativeAPI/ReverseEvent/BotGroupInviteSelfReverseEvent.cs @@ -0,0 +1,18 @@ +using Lagrange.Core.Events.EventArgs; +using Lagrange.Core.NativeAPI.NativeModel; +using Lagrange.Core.NativeAPI.NativeModel.Event; +using Lagrange.Core.NativeAPI.ReverseEvent.Abstract; + +namespace Lagrange.Core.NativeAPI.ReverseEvent +{ + public class BotGroupInviteSelfReverseEvent : ReverseEventBase + { + public override void RegisterEventHandler(BotContext context) + { + context.EventInvoker.RegisterEvent((ctx, e) => + { + Events.Add((BotGroupInviteSelfEventStruct)e); + }); + } + } +} \ No newline at end of file diff --git a/Lagrange.Core.NativeAPI/ReverseEvent/BotGroupReactionReverseEvent.cs b/Lagrange.Core.NativeAPI/ReverseEvent/BotGroupReactionReverseEvent.cs new file mode 100644 index 00000000..b2d74811 --- /dev/null +++ b/Lagrange.Core.NativeAPI/ReverseEvent/BotGroupReactionReverseEvent.cs @@ -0,0 +1,18 @@ +using Lagrange.Core.Events.EventArgs; +using Lagrange.Core.NativeAPI.NativeModel; +using Lagrange.Core.NativeAPI.NativeModel.Event; +using Lagrange.Core.NativeAPI.ReverseEvent.Abstract; + +namespace Lagrange.Core.NativeAPI.ReverseEvent +{ + public class BotGroupReactionReverseEvent : ReverseEventBase + { + public override void RegisterEventHandler(BotContext context) + { + context.EventInvoker.RegisterEvent((ctx, e) => + { + Events.Add((BotGroupReactionEventStruct)e); + }); + } + } +} \ No newline at end of file diff --git a/Lagrange.Core.NativeAPI/ReverseEvent/EventEntryPoint.cs b/Lagrange.Core.NativeAPI/ReverseEvent/EventEntryPoint.cs index 13914fcb..c364f7e8 100644 --- a/Lagrange.Core.NativeAPI/ReverseEvent/EventEntryPoint.cs +++ b/Lagrange.Core.NativeAPI/ReverseEvent/EventEntryPoint.cs @@ -13,10 +13,13 @@ public static IntPtr GetEventCount(int index) var eventCount = new ReverseEventCountStruct { BotCaptchaEventCount = Program.Contexts[index].EventInvoker.BotCaptchaEvent.Events.Count, + BotFriendRequestEventCount = Program.Contexts[index].EventInvoker.BotFriendRequestEvent.Events.Count, BotGroupInviteNotificationEventCount = Program.Contexts[index].EventInvoker.BotGroupInviteNotificationEvent.Events.Count, + BotGroupInviteSelfEventCount = Program.Contexts[index].EventInvoker.BotGroupInviteSelfEvent.Events.Count, BotGroupJoinNotificationEventCount = Program.Contexts[index].EventInvoker.BotGroupJoinNotificationEvent.Events.Count, BotGroupMemberDecreaseEventCount = Program.Contexts[index].EventInvoker.BotGroupMemberDecreaseEvent.Events.Count, BotGroupNudgeEventCount = Program.Contexts[index].EventInvoker.BotGroupNudgeEvent.Events.Count, + BotGroupReactionEventCount = Program.Contexts[index].EventInvoker.BotGroupReactionEvent.Events.Count, BotLoginEventCount = Program.Contexts[index].EventInvoker.BotLoginEvent.Events.Count, BotLogEventCount = Program.Contexts[index].EventInvoker.BotLogEvent.Events.Count, BotMessageEventCount = Program.Contexts[index].EventInvoker.BotMessageEvent.Events.Count, @@ -33,7 +36,7 @@ public static IntPtr GetEventCount(int index) return eventCountPtr; } - + [UnmanagedCallersOnly(EntryPoint = "GetCaptchaEvent")] public static IntPtr GetCaptchaEvent(int index) { @@ -49,18 +52,48 @@ public static IntPtr GetCaptchaEvent(int index) return eventPtr; } - [UnmanagedCallersOnly(EntryPoint = "GetGroupInviteNotificationEvent")] + [UnmanagedCallersOnly(EntryPoint = "GetBotFriendRequestEvent")] + public static IntPtr GetBotFriendRequestEvent(int index) + { + if (index >= Program.Contexts.Count) + { + return IntPtr.Zero; + } + + var botFriendRequestEvent = Program.Contexts[index].EventInvoker.BotFriendRequestEvent; + + IntPtr eventPtr = GetEventStructPtr(botFriendRequestEvent); + + return eventPtr; + } + + [UnmanagedCallersOnly(EntryPoint = "GetGroupInviteNotificationEvent")] public static IntPtr GetGroupInviteNotificationEvent(int index) { if (index >= Program.Contexts.Count) { return IntPtr.Zero; } - + var botGroupInviteNotificationEvent = Program.Contexts[index].EventInvoker.BotGroupInviteNotificationEvent; - + IntPtr eventPtr = GetEventStructPtr(botGroupInviteNotificationEvent); - + + return eventPtr; + } + + [UnmanagedCallersOnly(EntryPoint = "GetBotGroupInviteSelfEvent")] + public static IntPtr GetBotGroupInviteSelfEvent(int index) + { + if (index >= Program.Contexts.Count) + { + return IntPtr.Zero; + } + + var botGroupInviteSelfEvent = Program.Contexts[index].EventInvoker.BotGroupInviteSelfEvent; + + IntPtr eventPtr = GetEventStructPtr(botGroupInviteSelfEvent); + return eventPtr; } @@ -109,6 +142,21 @@ public static IntPtr GetGroupNudgeEvent(int index) return eventPtr; } + [UnmanagedCallersOnly(EntryPoint = "GetBotGroupReactionEvent")] + public static IntPtr GetBotGroupReactionEvent(int index) + { + if (index >= Program.Contexts.Count) + { + return IntPtr.Zero; + } + + var botGroupReactionEvent = Program.Contexts[index].EventInvoker.BotGroupReactionEvent; + + IntPtr eventPtr = GetEventStructPtr(botGroupReactionEvent); + + return eventPtr; + } + [UnmanagedCallersOnly(EntryPoint = "GetLoginEvent")] public static IntPtr GetLoginEvent(int index) { @@ -116,14 +164,14 @@ public static IntPtr GetLoginEvent(int index) { return IntPtr.Zero; } - + var botLoginEvent = Program.Contexts[index].EventInvoker.BotLoginEvent; - + IntPtr eventPtr = GetEventStructPtr(botLoginEvent); - + return eventPtr; } - + [UnmanagedCallersOnly(EntryPoint = "GetBotLogEvent")] public static IntPtr GetBotLogEvent(int index) { @@ -131,14 +179,14 @@ public static IntPtr GetBotLogEvent(int index) { return IntPtr.Zero; } - + var botLogEvent = Program.Contexts[index].EventInvoker.BotLogEvent; - + IntPtr eventPtr = GetEventStructPtr(botLogEvent); - + return eventPtr; } - + [UnmanagedCallersOnly(EntryPoint = "GetMessageEvent")] public static IntPtr GetMessageEvent(int index) { @@ -153,7 +201,7 @@ public static IntPtr GetMessageEvent(int index) return eventPtr; } - + [UnmanagedCallersOnly(EntryPoint = "GetNewDeviceVerifyEvent")] public static IntPtr GetNewDeviceVerifyEvent(int index) { @@ -168,7 +216,7 @@ public static IntPtr GetNewDeviceVerifyEvent(int index) return eventPtr; } - + [UnmanagedCallersOnly(EntryPoint = "GetOnlineEvent")] public static IntPtr GetOnlineEvent(int index) { @@ -183,7 +231,7 @@ public static IntPtr GetOnlineEvent(int index) return eventPtr; } - + [UnmanagedCallersOnly(EntryPoint = "GetQrCodeEvent")] public static IntPtr GetQrCodeEvent(int index) { @@ -198,7 +246,7 @@ public static IntPtr GetQrCodeEvent(int index) return eventPtr; } - + [UnmanagedCallersOnly(EntryPoint = "GetQrCodeQueryEvent")] public static IntPtr GetQrCodeQueryEvent(int index) { @@ -213,7 +261,7 @@ public static IntPtr GetQrCodeQueryEvent(int index) return eventPtr; } - + [UnmanagedCallersOnly(EntryPoint = "GetRefreshKeystoreEvent")] public static IntPtr GetRefreshKeystoreEvent(int index) { @@ -228,7 +276,7 @@ public static IntPtr GetRefreshKeystoreEvent(int index) return eventPtr; } - + [UnmanagedCallersOnly(EntryPoint = "GetSMSEvent")] public static IntPtr GetSMSEvent(int index) { @@ -247,7 +295,7 @@ public static IntPtr GetSMSEvent(int index) private static IntPtr GetEventStructPtr(ReverseEventBase reverseEvent) where T : IEventStruct { EventArrayStruct result = new EventArrayStruct(); - + if (reverseEvent.Events.Count == 0) { result.Events = IntPtr.Zero; @@ -257,7 +305,7 @@ private static IntPtr GetEventStructPtr(ReverseEventBase reverseEvent) where { result.Events = Marshal.AllocHGlobal(reverseEvent.Events.Count * Marshal.SizeOf()); result.Count = reverseEvent.Events.Count; - + for (int i = 0; i < reverseEvent.Events.Count; i++) { Marshal.StructureToPtr( @@ -266,10 +314,10 @@ private static IntPtr GetEventStructPtr(ReverseEventBase reverseEvent) where false ); } - + reverseEvent.Events.Clear(); } - + IntPtr resultPtr = Marshal.AllocHGlobal(Marshal.SizeOf()); Marshal.StructureToPtr(result, resultPtr, false); return resultPtr; diff --git a/Lagrange.Core.NativeAPI/ReverseEvent/ReverseEventInvoker.cs b/Lagrange.Core.NativeAPI/ReverseEvent/ReverseEventInvoker.cs index 73bf6404..ce1188a9 100644 --- a/Lagrange.Core.NativeAPI/ReverseEvent/ReverseEventInvoker.cs +++ b/Lagrange.Core.NativeAPI/ReverseEvent/ReverseEventInvoker.cs @@ -7,10 +7,13 @@ public class ReverseEventInvoker public ReverseEventInvoker(BotContext context) { BotCaptchaEvent.RegisterEventHandler(context); + BotFriendRequestEvent.RegisterEventHandler(context); BotGroupInviteNotificationEvent.RegisterEventHandler(context); + BotGroupInviteSelfEvent.RegisterEventHandler(context); BotGroupJoinNotificationEvent.RegisterEventHandler(context); BotGroupMemberDecreaseEvent.RegisterEventHandler(context); BotGroupNudgeEvent.RegisterEventHandler(context); + BotGroupReactionEvent.RegisterEventHandler(context); BotLoginEvent.RegisterEventHandler(context); BotLogEvent.RegisterEventHandler(context); BotMessageEvent.RegisterEventHandler(context); @@ -20,33 +23,39 @@ public ReverseEventInvoker(BotContext context) BotQrCodeQueryEvent.RegisterEventHandler(context); BotRefreshKeystoreEvent.RegisterEventHandler(context); } - + public BotCaptchaReverseEvent BotCaptchaEvent { get; } = new(); + public BotFriendRequestReverseEvent BotFriendRequestEvent { get; } = new(); + public BotGroupInviteNotificationReverseEvent BotGroupInviteNotificationEvent { get; } = new(); + public BotGroupInviteSelfReverseEvent BotGroupInviteSelfEvent { get; } = new(); + public BotGroupJoinNotificationReverseEvent BotGroupJoinNotificationEvent { get; } = new(); public BotGroupMemberDecreaseReverseEvent BotGroupMemberDecreaseEvent { get; } = new(); public BotGroupNudgeReverseEvent BotGroupNudgeEvent { get; } = new(); + public BotGroupReactionReverseEvent BotGroupReactionEvent { get; } = new(); + public BotLoginReverseEvent BotLoginEvent { get; } = new(); - + public BotLogReverseEvent BotLogEvent { get; } = new(); - + public BotMessageReverseEvent BotMessageEvent { get; } = new(); - + public BotNewDeviceVerifyReverseEvent BotNewDeviceVerifyEvent { get; } = new(); - + public BotOnlineReverseEvent BotOnlineEvent { get; } = new(); - + public BotQrCodeReverseEvent BotQrCodeEvent { get; } = new(); - + public BotQrCodeQueryReverseEvent BotQrCodeQueryEvent { get; } = new(); - + public BotRefreshKeystoreReverseEvent BotRefreshKeystoreEvent { get; } = new(); - + public BotSMSReverseEvent BotSMSEvent { get; } = new(); } } \ No newline at end of file