Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Runtime.InteropServices;
using System.Runtime.InteropServices;

namespace Lagrange.Core.NativeAPI.Test.NativeModel;

Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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
};
}
}
}
Original file line number Diff line number Diff line change
@@ -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
};
}
}
}
Original file line number Diff line number Diff line change
@@ -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
};
}
}
}
Original file line number Diff line number Diff line change
@@ -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
};
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Runtime.InteropServices;
using System.Runtime.InteropServices;

namespace Lagrange.Core.NativeAPI.NativeModel.Event
{
Expand All @@ -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;
Expand Down
34 changes: 29 additions & 5 deletions Lagrange.Core.NativeAPI/NativeModel/Message/BotStrangerStruct.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -12,25 +13,48 @@ 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()
{
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)
};
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<BotGroupInviteNotificationEvent>((ctx, e) =>
{
Events.Add((BotGroupInviteNotificationEventStruct)e);
});
}
}
}
Original file line number Diff line number Diff line change
@@ -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<BotGroupJoinNotificationEvent>((ctx, e) =>
{
Events.Add((BotGroupJoinNotificationEventStruct)e);
});
}
}
}
Original file line number Diff line number Diff line change
@@ -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<BotGroupMemberDecreaseEvent>((ctx, e) =>
{
Events.Add((BotGroupMemberDecreaseEventStruct)e);
});
}
}
}
18 changes: 18 additions & 0 deletions Lagrange.Core.NativeAPI/ReverseEvent/BotGroupNudgeReverseEvent.cs
Original file line number Diff line number Diff line change
@@ -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<BotGroupNudgeEvent>((ctx, e) =>
{
Events.Add((BotGroupNudgeEventStruct)e);
});
}
}
}
68 changes: 66 additions & 2 deletions Lagrange.Core.NativeAPI/ReverseEvent/EventEntryPoint.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -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<BotGroupInviteNotificationEventStruct>(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<BotGroupJoinNotificationEventStruct>(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<BotGroupMemberDecreaseEventStruct>(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<BotGroupNudgeEventStruct>(botGroupNudgeEvent);

return eventPtr;
}

[UnmanagedCallersOnly(EntryPoint = "GetLoginEvent")]
public static IntPtr GetLoginEvent(int index)
{
Expand Down
Loading
Loading