From 14de48b959917d2cf35c7cb2324f50a55df8f72f Mon Sep 17 00:00:00 2001 From: This is XiaoDeng <1744793737@qq.com> Date: Sat, 21 Oct 2023 11:52:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=20get=5Flogin=5Finfo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- basic_api_v11.py | 19 +++++++++++++++---- translator.py | 8 ++++++-- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/basic_api_v11.py b/basic_api_v11.py index 2994352..d9983d2 100644 --- a/basic_api_v11.py +++ b/basic_api_v11.py @@ -63,11 +63,22 @@ async def get_stranger_info( user_id: int, no_cache: bool = False ) -> dict: - resp_data = translator.translate_action_response( + # resp_data = translator.translate_action_response( + # await basic_actions_v12.get_user_info( + # str(user_id) + # ) + # ) + # resp_data["data"]["nickname"] = resp_data["data"].get("user_name", "") + # resp_data["data"]["sex"] = "unknown" + return translator.translate_action_response( await basic_actions_v12.get_user_info( str(user_id) ) ) - resp_data["data"]["nickname"] = resp_data["data"].get("user_name", "") - resp_data["data"]["sex"] = "unknown" - return resp_data + + +@register_action("v11") +async def get_login_info() -> dict: + return translator.translate_action_response( + await basic_actions_v12.get_self_info() + ) diff --git a/translator.py b/translator.py index ef78049..eea8d35 100644 --- a/translator.py +++ b/translator.py @@ -57,15 +57,19 @@ def translate_action_response(_response: dict) -> dict: response = _response.copy() if isinstance(response["data"], dict): for key, value in response["data"].items(): - if key.endswith("_id"): + if isinstance(value, dict): + response["data"][key] = translate_action_response({"data": value})["data"] + elif key.endswith("_id"): try: response["data"][key] = int(value) except ValueError: pass + elif key == "user_name": + response["data"]["nickname"] = value["user_name"] elif isinstance(response["data"], list): length = 0 for item in response["data"]: - response["data"][length] = translate_action_response(item) + response["data"][length] = translate_action_response({"data": item})["data"] length += 1 return response