1+ using System . Text . Json ;
2+ using System . Text . Json . Serialization ;
13using System . Text . RegularExpressions ;
24
35namespace PulseTestClient . Profiles ;
46
57public class MetaForgeProfileGateway : IProfileGateway
68{
9+ private static readonly JsonSerializerOptions JsonOptions = new ( )
10+ {
11+ PropertyNamingPolicy = JsonNamingPolicy . CamelCase ,
12+ } ;
13+
714 public async Task < Profile > GetAsync ( string account , CancellationToken ct )
815 {
9- var raw = await MetaForge . RunCommandAsync ( $ "account info { account } ", ct ) ;
10- var output = Regex . Replace ( raw , @"\x1B\[[0-9;]*m" , "" ) ;
16+ var json = await MetaForge . RunCommandAsync ( $ "account info { account } --json", ct ) ;
1117
12- var address = Regex . Match ( output , @"Address:\s+(0x[0-9a-fA-F]+)" ) . Groups [ 1 ] . Value ;
13- var version = int . Parse ( Regex . Match ( output , @"Version\s+(\d+)" ) . Groups [ 1 ] . Value ) ;
18+ var response = JsonSerializer . Deserialize < ProfileResponse > ( json , JsonOptions ) ! ;
19+ var avatar = response . Metadata . Avatars [ 0 ] ;
1420
15- // Match emote rows from the right-side table (lines ending with │ <item> │ │)
16- var emotes = Regex . Matches ( output , @"│\s+(\w+)\s+│\s+│\s*$" , RegexOptions . Multiline )
17- . Select ( m => m . Groups [ 1 ] . Value )
18- . Where ( v => v != "Item" )
21+ var emotes = avatar . Avatar . Emotes
22+ . Select ( e => e . Urn )
1923 . ToArray ( ) ;
2024
21- return new Profile ( new Web3Address ( address ) , version , emotes ) ;
25+ return new Profile ( new Web3Address ( avatar . EthAddress ) , avatar . Version , emotes ) ;
2226 }
23- }
27+ }
28+
29+ file class ProfileResponse
30+ {
31+ [ JsonPropertyName ( "metadata" ) ] public ProfileMetadata Metadata { get ; set ; } = null ! ;
32+ }
33+
34+ file class ProfileMetadata
35+ {
36+ [ JsonPropertyName ( "avatars" ) ] public List < AvatarEntry > Avatars { get ; set ; } = [ ] ;
37+ }
38+
39+ file class AvatarEntry
40+ {
41+ [ JsonPropertyName ( "ethAddress" ) ] public string EthAddress { get ; set ; } = "" ;
42+ [ JsonPropertyName ( "version" ) ] public int Version { get ; set ; }
43+ [ JsonPropertyName ( "avatar" ) ] public AvatarData Avatar { get ; set ; } = null ! ;
44+ }
45+
46+ file class AvatarData
47+ {
48+ [ JsonPropertyName ( "emotes" ) ] public List < EmoteEntry > Emotes { get ; set ; } = [ ] ;
49+ }
50+
51+ file class EmoteEntry
52+ {
53+ [ JsonPropertyName ( "urn" ) ] public string Urn { get ; set ; } = "" ;
54+ }
0 commit comments