Skip to content
Merged
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
4 changes: 2 additions & 2 deletions Lagrange.Core.NativeAPI.Test/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ static async Task Main(string[] args)
IntPtr keystorePtr = IntPtr.Zero;
IntPtr botConfigPtr = Marshal.AllocHGlobal(Marshal.SizeOf(botConfig));
Marshal.StructureToPtr(botConfig, botConfigPtr, false);
_index = Wrapper.Initialize(botConfigPtr, keystorePtr);
_index = Wrapper.Initialize(botConfigPtr, keystorePtr, IntPtr.Zero);
Console.WriteLine($"Bot initialized with index: {_index}");
int status = Wrapper.Start(_index);
Console.WriteLine($"Bot started with status: {status}");
Expand All @@ -34,7 +34,7 @@ static async void PollingProcesser(Object? source, System.Timers.ElapsedEventArg
{
try
{
//await GetEventCount();
// await GetEventCount();
await GetQrCodeEvent();
await GetLogEvent();
}
Expand Down
4 changes: 2 additions & 2 deletions Lagrange.Core.NativeAPI.Test/Wrapper.cs
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;

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

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

[DllImport(DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern int Start(int index);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Runtime.InteropServices;
using System.Text;
using Lagrange.Core.Common.Entity;

namespace Lagrange.Core.NativeAPI.NativeModel.Common;
[StructLayout(LayoutKind.Sequential)]
public class BotGroupExitNotificationStruct(BotGroupExitNotification e) : BotGroupNotificationBaseStruct(e)
{
public static implicit operator BotGroupExitNotificationStruct(BotGroupExitNotification e)
{
return new BotGroupExitNotificationStruct(e);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.Runtime.InteropServices;
using System.Text;
using Lagrange.Core.Common.Entity;

namespace Lagrange.Core.NativeAPI.NativeModel.Common;
[StructLayout(LayoutKind.Sequential)]
public class BotGroupKickNotificationStruct(BotGroupKickNotification notification) : BotGroupNotificationBaseStruct(notification)
{
public long OperatorUin = notification.OperatorUin;

public ByteArrayNative OperatorUid { get; } = Encoding.UTF8.GetBytes(notification.OperatorUid);

public static implicit operator BotGroupKickNotificationStruct(BotGroupKickNotification e)
{
return new BotGroupKickNotificationStruct(e);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.Runtime.InteropServices;
using System.Text;
using Lagrange.Core.Common.Entity;

namespace Lagrange.Core.NativeAPI.NativeModel.Common;
[StructLayout(LayoutKind.Sequential)]
public class BotGroupSetAdminNotificationStruct(BotGroupSetAdminNotification notification) : BotGroupNotificationBaseStruct(notification)
{
public long OperatorUin = notification.OperatorUin;

public ByteArrayNative OperatorUid { get; } = Encoding.UTF8.GetBytes(notification.OperatorUid);

public static implicit operator BotGroupSetAdminNotificationStruct(BotGroupSetAdminNotification e)
{
return new BotGroupSetAdminNotificationStruct(e);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.Runtime.InteropServices;
using System.Text;
using Lagrange.Core.Common.Entity;

namespace Lagrange.Core.NativeAPI.NativeModel.Common;
[StructLayout(LayoutKind.Sequential)]
public class BotGroupUnsetAdminNotificationStruct(BotGroupUnsetAdminNotification notification) : BotGroupNotificationBaseStruct(notification)
{
public long OperatorUin = notification.OperatorUin;

public ByteArrayNative OperatorUid { get; } = Encoding.UTF8.GetBytes(notification.OperatorUid);

public static implicit operator BotGroupUnsetAdminNotificationStruct(BotGroupUnsetAdminNotification e)
{
return new BotGroupUnsetAdminNotificationStruct(e);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
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 BotFriendRecallEventStruct : IEventStruct
{
public BotFriendRecallEventStruct() { }

public long PeerUin = 0;

public long AuthorUin = 0;

public ulong Sequence = 0;

public ByteArrayNative Tip = new();

public static implicit operator BotFriendRecallEventStruct(BotFriendRecallEvent e)
{
return new BotFriendRecallEventStruct()
{
PeerUin = e.PeerUin,
AuthorUin = e.AuthorUin,
Sequence = e.Sequence,
Tip = Encoding.UTF8.GetBytes(e.Tip)
};
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
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 BotGroupRecallEventStruct : IEventStruct
{
public BotGroupRecallEventStruct() { }

public long GroupUin = 0;

public ulong Sequence = 0;

public long AuthorUin = 0;

public long OperatorUin = 0;

public ByteArrayNative Tip = new();

public static implicit operator BotGroupRecallEventStruct(BotGroupRecallEvent e)
{
return new BotGroupRecallEventStruct()
{
GroupUin = e.GroupUin,
Sequence = e.Sequence,
AuthorUin = e.AuthorUin,
OperatorUin = e.OperatorUin,
Tip = Encoding.UTF8.GetBytes(e.Tip)
};
}
}
}
36 changes: 36 additions & 0 deletions Lagrange.Core.NativeAPI/NativeModel/Event/BotOfflineEventStruct.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
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 BotOfflineEventStruct : IEventStruct
{
public BotOfflineEventStruct() { }

public int Reason = 0;

ByteArrayNative Tag = new();

ByteArrayNative Message = new();

public static implicit operator BotOfflineEvent(BotOfflineEventStruct e)
{
return new BotOfflineEvent((BotOfflineEvent.Reasons)e.Reason, (
Encoding.UTF8.GetString(e.Tag), Encoding.UTF8.GetString(e.Message)
));
}

public static implicit operator BotOfflineEventStruct(BotOfflineEvent e)
{
return new BotOfflineEventStruct()
{
Reason = (int)e.Reason,
Tag = Encoding.UTF8.GetBytes(e.Tips?.Tag ?? ""),
Message = Encoding.UTF8.GetBytes(e.Tips?.Message ?? ""),
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ public ReverseEventCountStruct() { }

public int BotCaptchaEventCount = 0;
public int BotFriendRequestEventCount = 0;
public int BotFriendRecallEventCount = 0;
public int BotGroupInviteNotificationEventCount = 0;
public int BotGroupInviteSelfEventCount = 0;
public int BotGroupJoinNotificationEventCount = 0;
public int BotGroupMemberDecreaseEventCount = 0;
public int BotGroupMemberIncreaseEventCount = 0;
public int BotGroupNudgeEventCount = 0;
public int BotGroupReactionEventCount = 0;
public int BotGroupRecallEventCount = 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
Expand Up @@ -4,7 +4,6 @@
using Lagrange.Core.Message;
using Lagrange.Core.Message.Entities;
using Lagrange.Core.NativeAPI.NativeModel.Common;
using Lagrange.Core.NativeAPI.NativeModel.Event;
using Lagrange.Core.NativeAPI.NativeModel.Message.Entity;

namespace Lagrange.Core.NativeAPI.NativeModel.Message
Expand All @@ -28,6 +27,10 @@ public BotMessageStruct() { }

public int EntityLength = 0;

public ulong Sequence = 0;

public ulong ClientSequence = 0;

public static implicit operator BotMessageStruct(BotMessage message)
{
int type = 0;
Expand Down Expand Up @@ -162,7 +165,9 @@ public static implicit operator BotMessageStruct(BotMessage message)
Type = type,
Time = Encoding.UTF8.GetBytes(message.Time.ToString("O")),
Entities = entitiesPtr,
EntityLength = entitiesLength
EntityLength = entitiesLength,
Sequence = message.Sequence,
ClientSequence = message.ClientSequence
};
}
}
Expand Down
Loading