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+ }
0 commit comments