Skip to content

Commit

Permalink
实现 get_login_info
Browse files Browse the repository at this point in the history
  • Loading branch information
This-is-XiaoDeng committed Oct 21, 2023
1 parent 0a205d3 commit 14de48b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
19 changes: 15 additions & 4 deletions basic_api_v11.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
)
8 changes: 6 additions & 2 deletions translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 14de48b

Please sign in to comment.