Skip to content

Commit 06234c8

Browse files
authored
[Core & NativeAPI] 同步 Core 更改到 NativeAPI,并纠正了 Core 的笔误。 (#38)
1 parent ab6d4e5 commit 06234c8

14 files changed

Lines changed: 308 additions & 12 deletions

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

Lines changed: 5 additions & 1 deletion
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.NativeModel;
44

@@ -8,6 +8,10 @@ public struct ReverseEventCountStruct
88
public ReverseEventCountStruct() { }
99

1010
public int BotCaptchaEventCount = 0;
11+
public int BotGroupInviteNotificationEventCount = 0;
12+
public int BotGroupJoinNotificationEventCount = 0;
13+
public int BotGroupMemberDecreaseEventCount = 0;
14+
public int BotGroupNudgeEventCount = 0;
1115
public int BotLoginEventCount = 0;
1216
public int BotLogEventCount = 0;
1317
public int BotMessageEventCount = 0;
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System.Runtime.InteropServices;
2+
using Lagrange.Core.Common.Entity;
3+
using Lagrange.Core.Events.EventArgs;
4+
5+
namespace Lagrange.Core.NativeAPI.NativeModel.Event
6+
{
7+
[StructLayout(LayoutKind.Sequential)]
8+
public struct BotGroupInviteNotificationEventStruct(BotGroupInviteNotification notification) : IEventStruct
9+
{
10+
public BotGroupInviteNotification Notification = notification;
11+
12+
//public static implicit operator BotGroupMemberDecreaseEvent(BotGroupMemberDecreaseEventStruct e)
13+
//{
14+
// return new BotGroupMemberDecreaseEvent(
15+
// e.GroupUin, e.UserUin, e.OperatorUin
16+
// );
17+
//}
18+
19+
public static implicit operator BotGroupInviteNotificationEventStruct(BotGroupInviteNotificationEvent e)
20+
{
21+
return new BotGroupInviteNotificationEventStruct()
22+
{
23+
Notification = e.Notification
24+
};
25+
}
26+
}
27+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System.Runtime.InteropServices;
2+
using Lagrange.Core.Common.Entity;
3+
using Lagrange.Core.Events.EventArgs;
4+
5+
namespace Lagrange.Core.NativeAPI.NativeModel.Event
6+
{
7+
[StructLayout(LayoutKind.Sequential)]
8+
public struct BotGroupJoinNotificationEventStruct(BotGroupJoinNotification notification) : IEventStruct
9+
{
10+
public BotGroupJoinNotification Notification = notification;
11+
12+
//public static implicit operator BotGroupJoinNotificationEvent(BotGroupJoinNotificationEventStruct e)
13+
//{
14+
// return new BotGroupJoinNotificationEvent(
15+
// e.Notification
16+
// );
17+
//}
18+
19+
public static implicit operator BotGroupJoinNotificationEventStruct(BotGroupJoinNotificationEvent e)
20+
{
21+
return new BotGroupJoinNotificationEventStruct()
22+
{
23+
Notification = e.Notification
24+
};
25+
}
26+
}
27+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System.Runtime.InteropServices;
2+
using Lagrange.Core.Events.EventArgs;
3+
4+
namespace Lagrange.Core.NativeAPI.NativeModel.Event
5+
{
6+
[StructLayout(LayoutKind.Sequential)]
7+
public struct BotGroupMemberDecreaseEventStruct : IEventStruct
8+
{
9+
public BotGroupMemberDecreaseEventStruct() { }
10+
public Int64 GroupUin = 0;
11+
public Int64 UserUin = 0;
12+
public Int64 OperatorUin = 0;
13+
14+
//public static implicit operator BotGroupMemberDecreaseEvent(BotGroupMemberDecreaseEventStruct e)
15+
//{
16+
// return new BotGroupMemberDecreaseEvent(
17+
// e.GroupUin, e.UserUin, e.OperatorUin
18+
// );
19+
//}
20+
21+
public static implicit operator BotGroupMemberDecreaseEventStruct(BotGroupMemberDecreaseEvent e)
22+
{
23+
return new BotGroupMemberDecreaseEventStruct()
24+
{
25+
GroupUin = e.GroupUin,
26+
UserUin = e.UserUin,
27+
OperatorUin = e.OperatorUin ?? 0
28+
};
29+
}
30+
}
31+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System.Runtime.InteropServices;
2+
using Lagrange.Core.Events.EventArgs;
3+
4+
namespace Lagrange.Core.NativeAPI.NativeModel.Event
5+
{
6+
[StructLayout(LayoutKind.Sequential)]
7+
public struct BotGroupNudgeEventStruct : IEventStruct
8+
{
9+
public BotGroupNudgeEventStruct() { }
10+
public Int64 GroupUin = 0;
11+
public Int64 OperatorUin = 0;
12+
public Int64 TargetUin = 0;
13+
14+
public static implicit operator BotGroupNudgeEvent(BotGroupNudgeEventStruct e)
15+
{
16+
return new BotGroupNudgeEvent(
17+
e.GroupUin, e.OperatorUin, e.TargetUin
18+
);
19+
}
20+
21+
public static implicit operator BotGroupNudgeEventStruct(BotGroupNudgeEvent e)
22+
{
23+
return new BotGroupNudgeEventStruct()
24+
{
25+
GroupUin = e.GroupUin,
26+
OperatorUin = e.OperatorUin,
27+
TargetUin = e.TargetUin
28+
};
29+
}
30+
}
31+
}

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

Lines changed: 5 additions & 1 deletion
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.NativeModel.Event
44
{
@@ -8,6 +8,10 @@ public struct ReverseEventCountStruct
88
public ReverseEventCountStruct() { }
99

1010
public int BotCaptchaEventCount = 0;
11+
public int BotGroupInviteNotificationEventCount = 0;
12+
public int BotGroupJoinNotificationEventCount = 0;
13+
public int BotGroupMemberDecreaseEventCount = 0;
14+
public int BotGroupNudgeEventCount = 0;
1115
public int BotLoginEventCount = 0;
1216
public int BotLogEventCount = 0;
1317
public int BotMessageEventCount = 0;

Lagrange.Core.NativeAPI/NativeModel/Message/BotStrangerStruct.cs

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
using System.Runtime.InteropServices;
1+
using System.Runtime.InteropServices;
22
using System.Text;
3+
using Lagrange.Core.Common;
34
using Lagrange.Core.Common.Entity;
45
using Lagrange.Core.NativeAPI.NativeModel.Common;
56

@@ -12,25 +13,48 @@ public BotStrangerStruct() { }
1213
public long Uin = 0;
1314
public ByteArrayNative Nickname = new();
1415
public ByteArrayNative Uid = new();
16+
public ByteArrayNative PersonalSign = new();
17+
public ByteArrayNative Remark = new();
18+
public ulong Level = 0;
19+
public int Gender = 0;
20+
public long RegistrationTime = 0;
21+
public long Birthday = 0;
22+
public ulong Age = 0;
23+
public ByteArrayNative QID = new();
1524
public long Source = 0;
16-
25+
1726
public static implicit operator BotStranger(BotStrangerStruct stranger)
1827
{
1928
return new BotStranger(
2029
stranger.Uin,
2130
Encoding.UTF8.GetString(stranger.Nickname),
22-
Encoding.UTF8.GetString(stranger.Uid)
31+
Encoding.UTF8.GetString(stranger.Uid),
32+
Encoding.UTF8.GetString(stranger.PersonalSign),
33+
Encoding.UTF8.GetString(stranger.Remark),
34+
stranger.Level,
35+
(BotGender)stranger.Gender,
36+
DateTimeOffset.FromUnixTimeSeconds(stranger.RegistrationTime).LocalDateTime,
37+
DateTimeOffset.FromUnixTimeSeconds(stranger.Birthday).LocalDateTime,
38+
stranger.Age,
39+
Encoding.UTF8.GetString(stranger.QID)
2340
);
2441
}
25-
42+
2643
public static implicit operator BotStrangerStruct(BotStranger stranger)
2744
{
2845
return new BotStrangerStruct()
2946
{
3047
Uin = stranger.Uin,
3148
Nickname = Encoding.UTF8.GetBytes(stranger.Nickname),
3249
Uid = Encoding.UTF8.GetBytes(stranger.Uid),
33-
Source = stranger.Source
50+
PersonalSign = Encoding.UTF8.GetBytes(stranger.PersonalSign),
51+
Remark = Encoding.UTF8.GetBytes(stranger.Remark),
52+
Level = stranger.Level,
53+
Gender = (int)stranger.Gender,
54+
RegistrationTime = new DateTimeOffset(stranger.RegistrationTime).ToUnixTimeSeconds(),
55+
Birthday = new DateTimeOffset(stranger.Birthday ?? new()).ToUnixTimeSeconds(),
56+
Age = stranger.Age,
57+
QID = Encoding.UTF8.GetBytes(stranger.QID)
3458
};
3559
}
3660
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using Lagrange.Core.Events.EventArgs;
2+
using Lagrange.Core.NativeAPI.NativeModel;
3+
using Lagrange.Core.NativeAPI.NativeModel.Event;
4+
using Lagrange.Core.NativeAPI.ReverseEvent.Abstract;
5+
6+
namespace Lagrange.Core.NativeAPI.ReverseEvent
7+
{
8+
public class BotGroupInviteNotificationReverseEvent : ReverseEventBase
9+
{
10+
public override void RegisterEventHandler(BotContext context)
11+
{
12+
context.EventInvoker.RegisterEvent<BotGroupInviteNotificationEvent>((ctx, e) =>
13+
{
14+
Events.Add((BotGroupInviteNotificationEventStruct)e);
15+
});
16+
}
17+
}
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using Lagrange.Core.Events.EventArgs;
2+
using Lagrange.Core.NativeAPI.NativeModel;
3+
using Lagrange.Core.NativeAPI.NativeModel.Event;
4+
using Lagrange.Core.NativeAPI.ReverseEvent.Abstract;
5+
6+
namespace Lagrange.Core.NativeAPI.ReverseEvent
7+
{
8+
public class BotGroupJoinNotificationReverseEvent : ReverseEventBase
9+
{
10+
public override void RegisterEventHandler(BotContext context)
11+
{
12+
context.EventInvoker.RegisterEvent<BotGroupJoinNotificationEvent>((ctx, e) =>
13+
{
14+
Events.Add((BotGroupJoinNotificationEventStruct)e);
15+
});
16+
}
17+
}
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using Lagrange.Core.Events.EventArgs;
2+
using Lagrange.Core.NativeAPI.NativeModel;
3+
using Lagrange.Core.NativeAPI.NativeModel.Event;
4+
using Lagrange.Core.NativeAPI.ReverseEvent.Abstract;
5+
6+
namespace Lagrange.Core.NativeAPI.ReverseEvent
7+
{
8+
public class BotGroupMemberDecreaseReverseEvent : ReverseEventBase
9+
{
10+
public override void RegisterEventHandler(BotContext context)
11+
{
12+
context.EventInvoker.RegisterEvent<BotGroupMemberDecreaseEvent>((ctx, e) =>
13+
{
14+
Events.Add((BotGroupMemberDecreaseEventStruct)e);
15+
});
16+
}
17+
}
18+
}

0 commit comments

Comments
 (0)