Skip to content

Commit d0901fb

Browse files
committed
[Milky] Various changes
1. IEmptyApiHandler's ParameterType is set incorrectly 2. Implemented `get_friend_info`
1 parent 90b7bb0 commit d0901fb

File tree

13 files changed

+73
-13
lines changed

13 files changed

+73
-13
lines changed

Lagrange.Core.Runner/Program.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ private static async Task Main()
1717

1818
BotContext? bot = null;
1919

20-
var sign = new Signer(new Lazy<BotContext>(() => bot!), "http://106.54.14.24:8084/api/sign/30366");
20+
var sign = new Signer(new Lazy<BotContext>(() => bot!), "https://sign.lagrangecore.org/api/sign/30366");
2121

2222
if (File.Exists("keystore.json"))
2323
{
@@ -63,13 +63,13 @@ private static async Task Main()
6363

6464
using (var stream = File.OpenRead(@"E:\Code\CSharp\Lagrange\LagrangeV2\Lagrange.Core.Runner\Program.cs"))
6565
{
66-
if (!await bot.SendGroupFile(907925148, stream, "Program.cs", "/"))
66+
if (!await bot.SendGroupFile(0, stream, "Program.cs", "/"))
6767
{
6868
Console.WriteLine("Send group file failed");
6969
}
7070
else Console.WriteLine("Send group file succeed");
7171

72-
if (!await bot.SendFriendFile(1224702603, stream, "Program.cs"))
72+
if (!await bot.SendFriendFile(0, stream, "Program.cs"))
7373
{
7474
Console.WriteLine("Send friend file failed");
7575
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using Lagrange.Core;
2+
using Lagrange.Core.Common.Interface;
3+
using Lagrange.Milky.Implementation.Api.Parameter;
4+
using Lagrange.Milky.Implementation.Api.Result;
5+
using Lagrange.Milky.Implementation.Utility;
6+
7+
namespace Lagrange.Milky.Implementation.Api.Handler.System;
8+
9+
[Api("get_friend_info")]
10+
public class GetFriendInfoApiHandler(BotContext bot, EntityConvert convert) : IApiHandler<GetFriendInfoApiParameter>
11+
{
12+
private readonly BotContext _bot = bot;
13+
private readonly EntityConvert _convert = convert;
14+
15+
public async Task<IApiResult> HandleAsync(GetFriendInfoApiParameter parameter, CancellationToken token)
16+
{
17+
var friend = (await _bot.FetchFriends(parameter.NoCache ?? false)).FirstOrDefault();
18+
if (friend == null) return IApiResult.Failed(-1, "friend not found");
19+
20+
return IApiResult.Ok(_convert.Friend(friend));
21+
}
22+
}

Lagrange.Milky/Implementation/Api/Handler/System/GetFriendListApiHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ public class GetFriendListApiHandler(BotContext bot, EntityConvert convert) : IA
1414

1515
public async Task<IApiResult> HandleAsync(GetFriendListApiParameter parameter, CancellationToken token)
1616
{
17-
return IApiResult.Ok((await _bot.FetchFriends(parameter.NoCache)).Select(_convert.Friend));
17+
return IApiResult.Ok((await _bot.FetchFriends(parameter.NoCache ?? false)).Select(_convert.Friend));
1818
}
1919
}

Lagrange.Milky/Implementation/Api/IEmptyApiHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace Lagrange.Milky.Implementation.Api;
55

66
public interface IEmptyApiHandler : IApiHandler
77
{
8-
Type IApiHandler.ParameterType => typeof(object);
8+
Type IApiHandler.ParameterType => typeof(EmptyApiParameter);
99

1010
Task<IApiResult> IApiHandler.HandleAsync(IApiParameter parameter, CancellationToken token)
1111
{
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
namespace Lagrange.Milky.Implementation.Api.Parameter;
2+
3+
public class EmptyApiParameter : IApiParameter { }
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System.Text.Json.Serialization;
2+
3+
namespace Lagrange.Milky.Implementation.Api.Parameter;
4+
5+
public class GetFriendInfoApiParameter : IApiParameter
6+
{
7+
[JsonPropertyName("user_id")]
8+
public required long UserId { get; init; }
9+
10+
[JsonPropertyName("no_cache")]
11+
public bool? NoCache { get; init; }
12+
}

Lagrange.Milky/Implementation/Api/Parameter/GetFriendListApiParameter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ namespace Lagrange.Milky.Implementation.Api.Parameter;
55
public class GetFriendListApiParameter : IApiParameter
66
{
77
[JsonPropertyName("no_cache")]
8-
public bool NoCache { get; init; } = false;
8+
public bool? NoCache { get; init; }
99
}

Lagrange.Milky/Implementation/Api/Parameter/IApiParameter.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
namespace Lagrange.Milky.Implementation.Api.Parameter;
44

55

6+
[JsonDerivedType(typeof(EmptyApiParameter))]
67
// get_friend_list
78
[JsonDerivedType(typeof(GetFriendListApiParameter))]
9+
// get_friend_info
10+
[JsonDerivedType(typeof(GetFriendInfoApiParameter))]
811
public class IApiParameter { }

Lagrange.Milky/Implementation/Api/Result/IApiResult.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
using System.Text.Json.Serialization;
22
using Lagrange.Milky.Implementation.Api.Result.Data;
3+
using Lagrange.Milky.Implementation.Entity;
34

45
namespace Lagrange.Milky.Implementation.Api.Result;
56

67
// get_login_info
78
[JsonDerivedType(typeof(ApiOkResult<GetLoginInfoData>))]
89
// get_friend_list
9-
[JsonDerivedType(typeof(ApiOkResult<IEnumerable<Entity.Friend>>))]
10+
[JsonDerivedType(typeof(ApiOkResult<IEnumerable<Friend>>))]
11+
// get_friend_info
12+
[JsonDerivedType(typeof(ApiOkResult<Friend>))]
1013

1114
[JsonDerivedType(typeof(ApiFailedResult))]
1215
public interface IApiResult

Lagrange.Milky/Implementation/Extension/ServiceCollectionExtension.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public static class ServiceCollectionExtension
99
{
1010
[UnconditionalSuppressMessage("Trimming", "IL2026")]
1111
[UnconditionalSuppressMessage("Trimming", "IL2072")]
12+
[UnconditionalSuppressMessage("Trimming", "IL2062")]
1213
public static TServiceCollection AddApiHandlers<TServiceCollection>(this TServiceCollection services) where TServiceCollection : IServiceCollection
1314
{
1415
foreach (var type in typeof(ServiceCollectionExtension).Assembly.GetTypes())

0 commit comments

Comments
 (0)