Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OneBot] Making API get_group_honor_info returns Onebot11 compliant #679

Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
ishkong marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ public partial class GetGroupHonorInfoOperation(TicketService ticket) : IOperati
{
{ "talkative", 1 }, { "performer", 2 }, { "legend", 3 }, { "strong_newbie", 5 }, { "emotion", 6 },
};

private static readonly Dictionary<string, string> KeyToOnebot11 = new()
{
{"uin", "user_id"}, {"name", "nickname"}, {"nick", "nickname"}, {"desc", "description"}
};

public async Task<OneBotResult> HandleOperation(BotContext context, JsonNode? payload)
{
Expand All @@ -35,6 +40,8 @@ public async Task<OneBotResult> HandleOperation(BotContext context, JsonNode? pa
? HonorToType.Select(x => x.Key).ToArray()
: [honor.Type];

result.TryAdd("group_id", honor.GroupId);

foreach (string honorRaw in honors)
{
string url = $"https://qun.qq.com/interactive/honorlist?gc={honor.GroupId}&type={HonorToType[honorRaw]}";
Expand All @@ -46,7 +53,22 @@ public async Task<OneBotResult> HandleOperation(BotContext context, JsonNode? pa
{
foreach (var (key, value) in Keys)
{
if (json[value] is { } node) result.TryAdd(key, node.Deserialize<JsonNode>()); // 神经病
if (json[value] is JsonObject jsonObject) // 神经病 (我也觉得)
{
ProcessJsonObject(jsonObject);
if (honor.Type == "all" || honor.Type == "talkative") result.TryAdd(key, jsonObject.Deserialize<JsonNode>());
}
else if (json[value] is JsonArray jsonArray)
{
foreach (var item in jsonArray)
{
if (item is JsonObject itemObject)
{
ProcessJsonObject(itemObject);
}
}
if ((honor.Type == "all" && key.Contains(honorRaw)) || key.Contains(honor.Type)) result.TryAdd(key, jsonArray.Deserialize<JsonNode>());
}
DarkRRb marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Expand All @@ -56,4 +78,15 @@ public async Task<OneBotResult> HandleOperation(BotContext context, JsonNode? pa

throw new Exception();
}

private static void ProcessJsonObject(JsonObject jsonObject)
{
foreach (var oldKey in KeyToOnebot11.Keys)
{
if (jsonObject.Remove(oldKey, out var nodeValue))
{
jsonObject[KeyToOnebot11[oldKey]] = nodeValue;
}
}
}
}