Skip to content

Commit 90eeec9

Browse files
authored
[NativeAPI] Synchronize Core's new features. (#78)
1 parent ddfa660 commit 90eeec9

22 files changed

Lines changed: 730 additions & 91 deletions

Lagrange.Core.NativeAPI.Test/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ static async Task Main(string[] args)
1818
IntPtr keystorePtr = IntPtr.Zero;
1919
IntPtr botConfigPtr = Marshal.AllocHGlobal(Marshal.SizeOf(botConfig));
2020
Marshal.StructureToPtr(botConfig, botConfigPtr, false);
21-
_index = Wrapper.Initialize(botConfigPtr, keystorePtr);
21+
_index = Wrapper.Initialize(botConfigPtr, keystorePtr, IntPtr.Zero);
2222
Console.WriteLine($"Bot initialized with index: {_index}");
2323
int status = Wrapper.Start(_index);
2424
Console.WriteLine($"Bot started with status: {status}");
@@ -34,7 +34,7 @@ static async void PollingProcesser(Object? source, System.Timers.ElapsedEventArg
3434
{
3535
try
3636
{
37-
//await GetEventCount();
37+
// await GetEventCount();
3838
await GetQrCodeEvent();
3939
await GetLogEvent();
4040
}

Lagrange.Core.NativeAPI.Test/Wrapper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Runtime.InteropServices;
1+
using System.Runtime.InteropServices;
22

33
namespace Lagrange.Core.NativeAPI.Test;
44

@@ -7,7 +7,7 @@ public static class Wrapper
77
public const string DLL_NAME = "Lagrange.Core.NativeAPI.dll";
88

99
[DllImport(DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
10-
public static extern int Initialize(IntPtr botConfigPtr, IntPtr keystorePtr);
10+
public static extern int Initialize(IntPtr botConfigPtr, IntPtr keystorePtr, IntPtr appConfigPtr);
1111

1212
[DllImport(DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
1313
public static extern int Start(int index);
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System.Runtime.InteropServices;
2+
using System.Text;
3+
using Lagrange.Core.Common.Entity;
4+
5+
namespace Lagrange.Core.NativeAPI.NativeModel.Common;
6+
[StructLayout(LayoutKind.Sequential)]
7+
public class BotGroupExitNotificationStruct(BotGroupExitNotification e) : BotGroupNotificationBaseStruct(e)
8+
{
9+
public static implicit operator BotGroupExitNotificationStruct(BotGroupExitNotification e)
10+
{
11+
return new BotGroupExitNotificationStruct(e);
12+
}
13+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System.Runtime.InteropServices;
2+
using System.Text;
3+
using Lagrange.Core.Common.Entity;
4+
5+
namespace Lagrange.Core.NativeAPI.NativeModel.Common;
6+
[StructLayout(LayoutKind.Sequential)]
7+
public class BotGroupKickNotificationStruct(BotGroupKickNotification notification) : BotGroupNotificationBaseStruct(notification)
8+
{
9+
public long OperatorUin = notification.OperatorUin;
10+
11+
public ByteArrayNative OperatorUid { get; } = Encoding.UTF8.GetBytes(notification.OperatorUid);
12+
13+
public static implicit operator BotGroupKickNotificationStruct(BotGroupKickNotification e)
14+
{
15+
return new BotGroupKickNotificationStruct(e);
16+
}
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System.Runtime.InteropServices;
2+
using System.Text;
3+
using Lagrange.Core.Common.Entity;
4+
5+
namespace Lagrange.Core.NativeAPI.NativeModel.Common;
6+
[StructLayout(LayoutKind.Sequential)]
7+
public class BotGroupSetAdminNotificationStruct(BotGroupSetAdminNotification notification) : BotGroupNotificationBaseStruct(notification)
8+
{
9+
public long OperatorUin = notification.OperatorUin;
10+
11+
public ByteArrayNative OperatorUid { get; } = Encoding.UTF8.GetBytes(notification.OperatorUid);
12+
13+
public static implicit operator BotGroupSetAdminNotificationStruct(BotGroupSetAdminNotification e)
14+
{
15+
return new BotGroupSetAdminNotificationStruct(e);
16+
}
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System.Runtime.InteropServices;
2+
using System.Text;
3+
using Lagrange.Core.Common.Entity;
4+
5+
namespace Lagrange.Core.NativeAPI.NativeModel.Common;
6+
[StructLayout(LayoutKind.Sequential)]
7+
public class BotGroupUnsetAdminNotificationStruct(BotGroupUnsetAdminNotification notification) : BotGroupNotificationBaseStruct(notification)
8+
{
9+
public long OperatorUin = notification.OperatorUin;
10+
11+
public ByteArrayNative OperatorUid { get; } = Encoding.UTF8.GetBytes(notification.OperatorUid);
12+
13+
public static implicit operator BotGroupUnsetAdminNotificationStruct(BotGroupUnsetAdminNotification e)
14+
{
15+
return new BotGroupUnsetAdminNotificationStruct(e);
16+
}
17+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System.Runtime.InteropServices;
2+
using System.Text;
3+
using Lagrange.Core.Events.EventArgs;
4+
using Lagrange.Core.NativeAPI.NativeModel.Common;
5+
6+
namespace Lagrange.Core.NativeAPI.NativeModel.Event
7+
{
8+
[StructLayout(LayoutKind.Sequential)]
9+
public struct BotFriendRecallEventStruct : IEventStruct
10+
{
11+
public BotFriendRecallEventStruct() { }
12+
13+
public long PeerUin = 0;
14+
15+
public long AuthorUin = 0;
16+
17+
public ulong Sequence = 0;
18+
19+
public ByteArrayNative Tip = new();
20+
21+
public static implicit operator BotFriendRecallEventStruct(BotFriendRecallEvent e)
22+
{
23+
return new BotFriendRecallEventStruct()
24+
{
25+
PeerUin = e.PeerUin,
26+
AuthorUin = e.AuthorUin,
27+
Sequence = e.Sequence,
28+
Tip = Encoding.UTF8.GetBytes(e.Tip)
29+
};
30+
}
31+
}
32+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System.Runtime.InteropServices;
2+
using System.Text;
3+
using Lagrange.Core.Events.EventArgs;
4+
using Lagrange.Core.NativeAPI.NativeModel.Common;
5+
6+
namespace Lagrange.Core.NativeAPI.NativeModel.Event
7+
{
8+
[StructLayout(LayoutKind.Sequential)]
9+
public struct BotGroupRecallEventStruct : IEventStruct
10+
{
11+
public BotGroupRecallEventStruct() { }
12+
13+
public long GroupUin = 0;
14+
15+
public ulong Sequence = 0;
16+
17+
public long AuthorUin = 0;
18+
19+
public long OperatorUin = 0;
20+
21+
public ByteArrayNative Tip = new();
22+
23+
public static implicit operator BotGroupRecallEventStruct(BotGroupRecallEvent e)
24+
{
25+
return new BotGroupRecallEventStruct()
26+
{
27+
GroupUin = e.GroupUin,
28+
Sequence = e.Sequence,
29+
AuthorUin = e.AuthorUin,
30+
OperatorUin = e.OperatorUin,
31+
Tip = Encoding.UTF8.GetBytes(e.Tip)
32+
};
33+
}
34+
}
35+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Runtime.InteropServices;
2+
using System.Text;
3+
using Lagrange.Core.Events.EventArgs;
4+
using Lagrange.Core.NativeAPI.NativeModel.Common;
5+
6+
namespace Lagrange.Core.NativeAPI.NativeModel.Event
7+
{
8+
[StructLayout(LayoutKind.Sequential)]
9+
public struct BotOfflineEventStruct : IEventStruct
10+
{
11+
public BotOfflineEventStruct() { }
12+
13+
public int Reason = 0;
14+
15+
ByteArrayNative Tag = new();
16+
17+
ByteArrayNative Message = new();
18+
19+
public static implicit operator BotOfflineEvent(BotOfflineEventStruct e)
20+
{
21+
return new BotOfflineEvent((BotOfflineEvent.Reasons)e.Reason, (
22+
Encoding.UTF8.GetString(e.Tag), Encoding.UTF8.GetString(e.Message)
23+
));
24+
}
25+
26+
public static implicit operator BotOfflineEventStruct(BotOfflineEvent e)
27+
{
28+
return new BotOfflineEventStruct()
29+
{
30+
Reason = (int)e.Reason,
31+
Tag = Encoding.UTF8.GetBytes(e.Tips?.Tag ?? ""),
32+
Message = Encoding.UTF8.GetBytes(e.Tips?.Message ?? ""),
33+
};
34+
}
35+
}
36+
}

Lagrange.Core.NativeAPI/NativeModel/Event/ReverseEventCountStruct.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ public ReverseEventCountStruct() { }
99

1010
public int BotCaptchaEventCount = 0;
1111
public int BotFriendRequestEventCount = 0;
12+
public int BotFriendRecallEventCount = 0;
1213
public int BotGroupInviteNotificationEventCount = 0;
1314
public int BotGroupInviteSelfEventCount = 0;
1415
public int BotGroupJoinNotificationEventCount = 0;
1516
public int BotGroupMemberDecreaseEventCount = 0;
1617
public int BotGroupMemberIncreaseEventCount = 0;
1718
public int BotGroupNudgeEventCount = 0;
1819
public int BotGroupReactionEventCount = 0;
20+
public int BotGroupRecallEventCount = 0;
1921
public int BotLoginEventCount = 0;
2022
public int BotLogEventCount = 0;
2123
public int BotMessageEventCount = 0;

0 commit comments

Comments
 (0)