1+ using System . Text . Json ;
2+ using UnofficialArcaeaAPI . Lib . Models ;
3+ using UnofficialArcaeaAPI . Lib . Responses ;
4+ using UnofficialArcaeaAPI . Lib . Utils ;
5+
6+ namespace UnofficialArcaeaAPI . Lib . Core ;
7+
8+ public sealed class UaaImageUserApi
9+ {
10+ private readonly HttpClient _client ;
11+
12+ internal UaaImageUserApi ( HttpClient client )
13+ {
14+ _client = client ;
15+ }
16+
17+ #region /user/info
18+
19+ private async Task < byte [ ] > GetInfoAsyncCore ( string ? user , int ? userCode , int recent ,
20+ AuaReplyWith replyWith )
21+ {
22+ var qb = new QueryBuilder ( )
23+ . Add ( "recent" , recent . ToString ( ) ) ;
24+
25+ if ( user is not null )
26+ qb . Add ( "user_name" , user ) ;
27+ else
28+ qb . Add ( "user_code" , userCode . ToString ( ) ! ) ;
29+
30+ if ( replyWith . HasFlag ( AuaReplyWith . SongInfo ) )
31+ qb . Add ( "with_song_info" , "true" ) ;
32+ var resp = await _client . GetAsync ( "image/user/info" + qb . Build ( ) ) ;
33+ return await resp . EnsureDataSuccess ( ) ;
34+ }
35+
36+ /// <summary>
37+ /// Get user info image.
38+ /// </summary>
39+ /// <param name="user">User name or 9-digit user code</param>
40+ /// <param name="recent">The number of recently played songs expected, range 0-7</param>
41+ /// <param name="replyWith">Additional information to reply with. Supports songinfo only.</param>
42+ /// <returns>User info image</returns>
43+ public Task < byte [ ] > GetInfoAsync ( string user , int recent = 0 ,
44+ AuaReplyWith replyWith = AuaReplyWith . None )
45+ => GetInfoAsyncCore ( user , null , recent , replyWith ) ;
46+
47+ /// <summary>
48+ /// Get user info image.
49+ /// </summary>
50+ /// <param name="userCode">9-digit user code</param>
51+ /// <param name="recent">The number of recently played songs expected, range 0-7</param>
52+ /// <param name="replyWith">Additional information to reply with. Supports songinfo only.</param>
53+ /// <returns>User info image</returns>
54+ public Task < byte [ ] > GetInfoAsync ( int userCode , int recent = 0 ,
55+ AuaReplyWith replyWith = AuaReplyWith . None )
56+ => GetInfoAsyncCore ( null , userCode , recent , replyWith ) ;
57+
58+ /// <summary>
59+ /// Get user info image.
60+ /// </summary>
61+ /// <param name="user">User name or 9-digit user code</param>
62+ /// <param name="replyWith">Additional information to reply with. Supports songinfo only.</param>
63+ /// <returns>User info image</returns>
64+ public Task < byte [ ] > GetInfoAsync ( string user , AuaReplyWith replyWith )
65+ => GetInfoAsyncCore ( user , null , 0 , replyWith ) ;
66+
67+ /// <summary>
68+ /// Get user info image.
69+ /// </summary>
70+ /// <param name="userCode">9-digit user code</param>
71+ /// <param name="replyWith">Additional information to reply with. Supports songinfo only.</param>
72+ /// <returns>User info image</returns>
73+ public Task < byte [ ] > GetInfoAsync ( int userCode , AuaReplyWith replyWith )
74+ => GetInfoAsyncCore ( null , userCode , 0 , replyWith ) ;
75+
76+ #endregion /user/info
77+
78+ #region /user/best
79+
80+ private async Task < byte [ ] > GetBestAsyncCore ( string ? user , int ? userCode , string songname ,
81+ AuaSongQueryType queryType , ArcaeaDifficulty difficulty , AuaReplyWith replyWith )
82+ {
83+ var qb = new QueryBuilder ( )
84+ . Add ( queryType == AuaSongQueryType . SongId ? "song_id" : "song_name" , songname )
85+ . Add ( "difficulty" , ( ( int ) difficulty ) . ToString ( ) ) ;
86+
87+ if ( user is not null )
88+ qb . Add ( "user_name" , user ) ;
89+ else
90+ qb . Add ( "user_code" , userCode . ToString ( ) ! ) ;
91+
92+ if ( replyWith . HasFlag ( AuaReplyWith . Recent ) )
93+ qb . Add ( "with_recent" , "true" ) ;
94+ if ( replyWith . HasFlag ( AuaReplyWith . SongInfo ) )
95+ qb . Add ( "with_song_info" , "true" ) ;
96+
97+ var resp = await _client . GetAsync ( "user/best" + qb . Build ( ) ) ;
98+ return await resp . EnsureDataSuccess ( ) ;
99+ }
100+
101+ /// <summary>
102+ /// Get user best score image.
103+ /// </summary>
104+ /// <param name="user">User name or 9-digit user code</param>
105+ /// <param name="songName">Any song name for fuzzy querying or sid in Arcaea songlist</param>
106+ /// <param name="queryType">Specify the query type between songname and songid</param>
107+ /// <param name="difficulty">Song difficulty</param>
108+ /// <param name="replyWith">Additional information to reply with. Supports songinfo and recent.</param>
109+ /// <returns>User best image</returns>
110+ public Task < byte [ ] > GetBestAsync ( string user , string songName ,
111+ AuaSongQueryType queryType = AuaSongQueryType . SongName , ArcaeaDifficulty difficulty = ArcaeaDifficulty . Future ,
112+ AuaReplyWith replyWith = AuaReplyWith . None )
113+ => GetBestAsyncCore ( user , null , songName , queryType , difficulty , replyWith ) ;
114+
115+ /// <summary>
116+ /// Get user best score image.
117+ /// </summary>
118+ /// <param name="userCode">9-digit user code</param>
119+ /// <param name="songName">Any song name for fuzzy querying or sid in Arcaea songlist</param>
120+ /// <param name="queryType">Specify the query type between songname and songid</param>
121+ /// <param name="difficulty">Song difficulty</param>
122+ /// <param name="replyWith">Additional information to reply with. Supports songinfo and recent.</param>
123+ /// <returns>User best image</returns>
124+ public Task < byte [ ] > GetBestAsync ( int userCode , string songName ,
125+ AuaSongQueryType queryType = AuaSongQueryType . SongName , ArcaeaDifficulty difficulty = ArcaeaDifficulty . Future ,
126+ AuaReplyWith replyWith = AuaReplyWith . None )
127+ => GetBestAsyncCore ( null , userCode , songName , queryType , difficulty , replyWith ) ;
128+
129+ /// <summary>
130+ /// Get user best score image.
131+ /// </summary>
132+ /// <param name="user">User name or 9-digit user code</param>
133+ /// <param name="songName">Any song name for fuzzy querying</param>
134+ /// <param name="difficulty">Song difficulty</param>
135+ /// <param name="replyWith">Additional information to reply with. Supports songinfo and recent.</param>
136+ /// <returns>User best image</returns>
137+ public Task < byte [ ] > GetBestAsync ( string user , string songName ,
138+ ArcaeaDifficulty difficulty ,
139+ AuaReplyWith replyWith = AuaReplyWith . None )
140+ => GetBestAsyncCore ( user , null , songName , AuaSongQueryType . SongName , difficulty , replyWith ) ;
141+
142+ /// <summary>
143+ /// Get user best score image.
144+ /// </summary>
145+ /// <param name="userCode">9-digit user code</param>
146+ /// <param name="songName">Any song name for fuzzy querying</param>
147+ /// <param name="difficulty">Song difficulty</param>
148+ /// <param name="replyWith">Additional information to reply with. Supports songinfo and recent.</param>
149+ /// <returns>User best image</returns>
150+ public Task < byte [ ] > GetBestAsync ( int userCode , string songName ,
151+ ArcaeaDifficulty difficulty ,
152+ AuaReplyWith replyWith = AuaReplyWith . None )
153+ => GetBestAsyncCore ( null , userCode , songName , AuaSongQueryType . SongName , difficulty , replyWith ) ;
154+
155+ /// <summary>
156+ /// Get user best score image.
157+ /// </summary>
158+ /// <param name="user">User name or 9-digit user code</param>
159+ /// <param name="songName">Any song name for fuzzy querying</param>
160+ /// <param name="replyWith">Additional information to reply with. Supports songinfo and recent.</param>
161+ /// <returns>User best image</returns>
162+ public Task < byte [ ] > GetBestAsync ( string user , string songName , AuaReplyWith replyWith )
163+ => GetBestAsyncCore ( user , null , songName , AuaSongQueryType . SongName , ArcaeaDifficulty . Future , replyWith ) ;
164+
165+ /// <summary>
166+ /// Get user best score image.
167+ /// </summary>
168+ /// <param name="userCode">9-digit user code</param>
169+ /// <param name="songName">Any song name for fuzzy querying</param>
170+ /// <param name="replyWith">Additional information to reply with. Supports songinfo and recent.</param>
171+ /// <returns>User best image</returns>
172+ public Task < byte [ ] > GetBestAsync ( int userCode , string songName ,
173+ AuaReplyWith replyWith )
174+ => GetBestAsyncCore ( null , userCode , songName , AuaSongQueryType . SongName , ArcaeaDifficulty . Future , replyWith ) ;
175+
176+ #endregion /user/best
177+ }
0 commit comments