Files
zhenxun_bot-sdgb_api/user.py
2025-10-15 19:42:27 +08:00

52 lines
1.8 KiB
Python

__all__ = ["handle_user"]
bind_lock = asyncio.Lock()
async def _ensure_login(userId: int):
ts = generateTimestamp()
loginResult = apiLogin(ts, userId)
return ts, loginResult
async def handle_user(bot: Bot, event: Event):
user_qq = str(event.user_id)
async with bind_lock:
if user_qq not in bind_data:
await MessageUtils.build_message("请先绑定 /bind").send(reply_to=True)
return
userId = bind_data[user_qq]
ts, loginResult = await _ensure_login(userId)
return_code = loginResult.get("returnCode")
if return_code == 1:
pass
elif return_code == 100:
await MessageUtils.build_message("用户正在上机游玩,请下机后再试,或等待 15 分钟。").send(reply_to=True)
return
elif return_code == 102:
await MessageUtils.build_message("zako~zako~又不获取二维码吗").send(reply_to=True)
return
elif return_code == 103:
await MessageUtils.build_message("登录的账号 UID 无效,请检查账号是否正确。").send(reply_to=True)
return
else:
error_details = loginResult.get("message", str(loginResult))
await MessageUtils.build_message(f"登录失败!这不应该发生,请反馈此问题。\n错误详情:{error_details}").send(reply_to=True)
return
try:
friendly_info = getFriendlyUserData(userId)
await MessageUtils.build_message(f"📄 用户信息:\n{friendly_info}").send(reply_to=True)
except Exception as e:
await MessageUtils.build_message(f"❌ 获取用户信息失败: {e}").send(reply_to=True)
logger.error(f"获取用户信息异常: {e}")
finally:
try:
apiLogout(ts, userId)
except Exception as e:
logger.warning(f"登出失败: {e}")