Skip to content

Commit 9a7fb2f

Browse files
committed
[Core & Milky] Improve BotStranger and implement get_user_profile
1 parent 8f7692b commit 9a7fb2f

4 files changed

Lines changed: 91 additions & 3 deletions

File tree

Lagrange.Core/Common/Entity/BotStranger.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace Lagrange.Core.Common.Entity;
22

3-
public class BotStranger(long uin, string nickname, string uid, string personalSign, string remark, ulong level, BotGender gender, DateTime registrationTime, DateTime? birthday, ulong age, string qID) : BotContact
3+
public class BotStranger(long uin, string nickname, string uid, string personalSign, string remark, ulong level, BotGender gender, DateTime registrationTime, DateTime? birthday, ulong age, string qID, string country, string city, string? school) : BotContact
44
{
55
public override long Uin { get; } = uin;
66

@@ -26,6 +26,12 @@ public class BotStranger(long uin, string nickname, string uid, string personalS
2626

2727
public long Source { get; init; }
2828

29+
public string Country { get; init; } = country;
30+
31+
public string City { get; init; } = city;
32+
33+
public string? School { get; init; } = school;
34+
2935
internal BotStranger CloneWithSource(long source) => new(
3036
Uin,
3137
Nickname,
@@ -37,7 +43,10 @@ public class BotStranger(long uin, string nickname, string uid, string personalS
3743
RegistrationTime,
3844
Birthday,
3945
Age,
40-
QID
46+
QID,
47+
Country,
48+
City,
49+
School
4150
)
4251
{ Source = source };
4352
}

Lagrange.Core/Internal/Services/System/FetchStrangerService.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,10 @@ protected override ValueTask<FetchStrangerEventResp> Parse(ReadOnlyMemory<byte>
108108
DateTimeOffset.FromUnixTimeSeconds((long)numbers[20026]).DateTime,
109109
month != 0 && day != 0 ? new DateTime(year != 0 ? year : 1, month, day) : null,
110110
numbers[20037],
111-
Encoding.UTF8.GetString(bytes[27394])
111+
Encoding.UTF8.GetString(bytes[27394]),
112+
Encoding.UTF8.GetString(bytes[20003]),
113+
Encoding.UTF8.GetString(bytes[20004]),
114+
bytes.TryGetValue(200021, out byte[]? value) ? Encoding.UTF8.GetString(value) : null
112115
)));
113116
}
114117
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
using System.Text.Json.Serialization;
2+
using Lagrange.Core;
3+
using Lagrange.Core.Common.Interface;
4+
5+
namespace Lagrange.Milky.Api.Handler.System;
6+
7+
[Api("get_user_profile")]
8+
public class GetUserProfileHandler(BotContext bot) : IApiHandler<GetUserProfileParameter, GetUserProfileResult>
9+
{
10+
private readonly BotContext _bot = bot;
11+
12+
public async Task<GetUserProfileResult> HandleAsync(GetUserProfileParameter parameter, CancellationToken token)
13+
{
14+
var stranger = await _bot.FetchStranger(parameter.UserId);
15+
return new GetUserProfileResult(
16+
stranger.Nickname,
17+
stranger.QID,
18+
(int)stranger.Age,
19+
stranger.Gender switch
20+
{
21+
Lagrange.Core.Common.BotGender.Male => "male",
22+
Lagrange.Core.Common.BotGender.Female => "female",
23+
_ => "unknown",
24+
},
25+
stranger.Remark,
26+
stranger.PersonalSign,
27+
(int)stranger.Level,
28+
stranger.Country,
29+
stranger.City,
30+
stranger.School ?? string.Empty
31+
);
32+
}
33+
}
34+
35+
public class GetUserProfileParameter(long userId)
36+
{
37+
[JsonRequired]
38+
[JsonPropertyName("user_id")]
39+
public long UserId { get; init; } = userId;
40+
}
41+
42+
public class GetUserProfileResult(string nickname, string qid, int age, string sex, string remark, string bio, int level, string country, string city, string school)
43+
{
44+
[JsonPropertyName("nickname")]
45+
public string Nickname { get; } = nickname;
46+
47+
[JsonPropertyName("qid")]
48+
public string Qid { get; } = qid;
49+
50+
[JsonPropertyName("age")]
51+
public int Age { get; } = age;
52+
53+
[JsonPropertyName("sex")]
54+
public string Sex { get; } = sex;
55+
56+
[JsonPropertyName("remark")]
57+
public string Remark { get; } = remark;
58+
59+
[JsonPropertyName("bio")]
60+
public string Bio { get; } = bio;
61+
62+
[JsonPropertyName("level")]
63+
public int Level { get; } = level;
64+
65+
[JsonPropertyName("country")]
66+
public string Country { get; } = country;
67+
68+
[JsonPropertyName("city")]
69+
public string City { get; } = city;
70+
71+
[JsonPropertyName("school")]
72+
public string School { get; } = school;
73+
}

Lagrange.Milky/Utility/JsonUtility.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ public static partial class JsonUtility
3838
[JsonSerializable(typeof(GetLoginInfoResult))]
3939
// get_impl_info
4040
[JsonSerializable(typeof(GetImplInfoResult))]
41+
// get_user_profile
42+
[JsonSerializable(typeof(GetUserProfileParameter))]
43+
[JsonSerializable(typeof(GetUserProfileResult))]
4144
// get_friend_list
4245
[JsonSerializable(typeof(GetFriendListParameter))]
4346
[JsonSerializable(typeof(GetFriendListResult))]

0 commit comments

Comments
 (0)