@@ -25,6 +25,11 @@ public partial class GetGroupHonorInfoOperation(TicketService ticket) : IOperati
25
25
{
26
26
{ "talkative" , 1 } , { "performer" , 2 } , { "legend" , 3 } , { "strong_newbie" , 5 } , { "emotion" , 6 } ,
27
27
} ;
28
+
29
+ private static readonly Dictionary < string , string > KeyToOnebot11 = new ( )
30
+ {
31
+ { "uin" , "user_id" } , { "name" , "nickname" } , { "nick" , "nickname" } , { "desc" , "description" }
32
+ } ;
28
33
29
34
public async Task < OneBotResult > HandleOperation ( BotContext context , JsonNode ? payload )
30
35
{
@@ -35,18 +40,37 @@ public async Task<OneBotResult> HandleOperation(BotContext context, JsonNode? pa
35
40
? HonorToType . Select ( x => x . Key ) . ToArray ( )
36
41
: [ honor . Type ] ;
37
42
43
+ result . TryAdd ( "group_id" , honor . GroupId ) ;
44
+
38
45
foreach ( string honorRaw in honors )
39
46
{
40
47
string url = $ "https://qun.qq.com/interactive/honorlist?gc={ honor . GroupId } &type={ HonorToType [ honorRaw ] } ";
41
48
var response = await ticket . SendAsync ( new HttpRequestMessage ( HttpMethod . Get , url ) ) ;
42
49
string raw = await response . Content . ReadAsStringAsync ( ) ;
43
50
var match = HonorRegex ( ) . Match ( raw ) ;
44
51
45
- if ( JsonSerializer . Deserialize < JsonObject > ( match . Groups [ 1 ] . Value ) is { } json )
52
+ if ( JsonSerializer . Deserialize < JsonObject > ( match . Groups [ 1 ] . Value ) is { } json ) // 神经病
46
53
{
47
54
foreach ( var ( key , value ) in Keys )
48
55
{
49
- if ( json [ value ] is { } node ) result . TryAdd ( key , node . Deserialize < JsonNode > ( ) ) ; // 神经病
56
+ if ( json . Remove ( value , out var node ) )
57
+ {
58
+ if ( node is JsonObject jsonObject )
59
+ {
60
+ ProcessJsonObject ( jsonObject ) ;
61
+ }
62
+ else if ( node is JsonArray jsonArray )
63
+ {
64
+ foreach ( var subNode in jsonArray )
65
+ {
66
+ if ( subNode is JsonObject subObject )
67
+ {
68
+ ProcessJsonObject ( subObject ) ;
69
+ }
70
+ }
71
+ }
72
+ if ( key . Contains ( honorRaw ) ) result . TryAdd ( key , node ) ;
73
+ }
50
74
}
51
75
}
52
76
}
@@ -56,4 +80,15 @@ public async Task<OneBotResult> HandleOperation(BotContext context, JsonNode? pa
56
80
57
81
throw new Exception ( ) ;
58
82
}
83
+
84
+ private static void ProcessJsonObject ( JsonObject jsonObject )
85
+ {
86
+ foreach ( var oldKey in KeyToOnebot11 . Keys )
87
+ {
88
+ if ( jsonObject . Remove ( oldKey , out var nodeValue ) )
89
+ {
90
+ jsonObject [ KeyToOnebot11 [ oldKey ] ] = nodeValue ;
91
+ }
92
+ }
93
+ }
59
94
}
0 commit comments