🎨 解决部分查询时UID错误的问题

This commit is contained in:
洛水居室 2022-10-08 21:35:46 +08:00
parent dc30f33dd1
commit 52de48fedf
No known key found for this signature in database
GPG Key ID: C9DE87DA724B88FC

View File

@ -1,7 +1,7 @@
import secrets
from typing import Optional
from genshin import GenshinException, Client
from genshin import Client
from genshin.models import GenshinUserStats
from telegram import Update
from telegram.constants import ChatAction
@ -42,23 +42,20 @@ class UserStatsPlugins(Plugin, BasePlugin):
user = update.effective_user
message = update.effective_message
logger.info(f"用户 {user.full_name}[{user.id}] 查询游戏用户命令请求")
uid: int = -1
uid: Optional[int] = None
try:
args = context.args
if args is not None and len(args) >= 1:
uid = int(args[0])
except ValueError as exc:
logger.error("获取 uid 发生错误! 错误信息为")
logger.exception(exc)
logger.warning(f"获取 uid 发生错误! 错误信息为 {repr(exc)}")
await message.reply_text("输入错误")
return ConversationHandler.END
try:
try:
client = await get_genshin_client(user.id)
except CookiesNotFoundError:
client, _uid = await get_public_genshin_client(user.id)
if uid == -1:
uid = _uid
client, uid = await get_public_genshin_client(user.id)
png_data = await self.render(client, uid)
except UserNotFoundError:
reply_message = await message.reply_text("未查询到账号信息,请先私聊派蒙绑定账号")
@ -84,15 +81,12 @@ class UserStatsPlugins(Plugin, BasePlugin):
png_data, filename=f"{client.uid}.png", allow_sending_without_reply=True
)
async def render(self, client: Client, uid: int = -1) -> bytes:
if uid == -1 and client.uid:
async def render(self, client: Client, uid: Optional[int] = None) -> bytes:
if uid is None:
uid = client.uid
try:
user_info = await client.get_genshin_user(uid)
logger.debug(user_info)
except GenshinException as exc:
raise exc
# 因为需要替换线上图片地址为本地地址,先克隆数据,避免修改原数据
user_info = user_info.copy(deep=True)