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