From c8f77612e94a5c2fa402dde3ec905260ac09eb53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B4=9B=E6=B0=B4=E5=B1=85=E5=AE=A4?= Date: Sat, 10 Sep 2022 11:47:13 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20=E4=BF=AE=E5=A4=8D=E8=B0=83?= =?UTF-8?q?=E7=94=A8=20`get=5Frecord=5Fcard`=20=E7=9A=84=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/genshin/uid.py | 18 +++++++++++++----- plugins/genshin/userstats.py | 19 +++---------------- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/plugins/genshin/uid.py b/plugins/genshin/uid.py index 2772b92..0705aed 100644 --- a/plugins/genshin/uid.py +++ b/plugins/genshin/uid.py @@ -1,7 +1,7 @@ from typing import Optional import genshin -from genshin import GenshinException, types +from genshin import GenshinException, types, DataNotPublic from telegram import Update, ReplyKeyboardRemove, ReplyKeyboardMarkup, TelegramObject from telegram.ext import CallbackContext, filters, ConversationHandler from telegram.helpers import escape_markdown @@ -50,7 +50,7 @@ class SetUserUid(Plugin.Conversation, BasePlugin.Conversation): cookies_command_data = AddUserCommandData() context.chat_data["add_uid_command_data"] = cookies_command_data text = f'你好 {user.mention_markdown_v2()} ' \ - f'{escape_markdown("!本次绑定只绑定UID,未绑定Cookies部分功能无法使用。请选择要绑定的服务器!或回复退出取消操作")}' + f'{escape_markdown("!请输入通行证UID,未绑定Cookies部分功能无法使用。请选择要绑定的服务器!或回复退出取消操作")}' reply_keyboard = [['米游社', 'HoYoLab'], ["退出"]] await message.reply_markdown_v2(text, reply_markup=ReplyKeyboardMarkup(reply_keyboard, one_time_keyboard=True)) return CHECK_SERVER @@ -100,7 +100,7 @@ class SetUserUid(Plugin.Conversation, BasePlugin.Conversation): await message.reply_text("退出任务", reply_markup=ReplyKeyboardRemove()) return ConversationHandler.END try: - uid = int(message.text) + hoyolab_uid = int(message.text) except ValueError: await message.reply_text("Cookies格式有误,请检查", reply_markup=ReplyKeyboardRemove()) return ConversationHandler.END @@ -117,13 +117,20 @@ class SetUserUid(Plugin.Conversation, BasePlugin.Conversation): else: return ConversationHandler.END try: - user_info = await client.get_record_card(uid) + user_info = await client.get_record_card(hoyolab_uid) + except DataNotPublic: + await message.reply_text("角色未公开", reply_markup=ReplyKeyboardRemove()) + logger.error(f"获取账号信息发生错误 hoyolab_uid[{hoyolab_uid}] 账户信息未公开") + return ConversationHandler.END except GenshinException as exc: await message.reply_text("获取账号信息发生错误", reply_markup=ReplyKeyboardRemove()) logger.error("获取账号信息发生错误") logger.exception(exc) return ConversationHandler.END - add_user_command_data.game_uid = uid + if user_info.game != types.Game.GENSHIN: + await message.reply_text("角色信息查询返回非原神游戏信息," + "请设置展示主界面为原神", reply_markup=ReplyKeyboardRemove()) + return ConversationHandler.END reply_keyboard = [['确认', '退出']] await message.reply_text("获取角色基础信息成功,请检查是否正确!") logger.info(f"用户 {user.full_name}[{user.id}] 获取账号 {user_info.nickname}[{user_info.uid}] 信息成功") @@ -132,6 +139,7 @@ class SetUserUid(Plugin.Conversation, BasePlugin.Conversation): f"角色等级:{user_info.level}\n" \ f"UID:`{user_info.uid}`\n" \ f"服务器名称:`{user_info.server_name}`\n" + add_user_command_data.game_uid = user_info.uid await message.reply_markdown_v2( text, reply_markup=ReplyKeyboardMarkup(reply_keyboard, one_time_keyboard=True) diff --git a/plugins/genshin/userstats.py b/plugins/genshin/userstats.py index 2c5f9df..dc1ba9f 100644 --- a/plugins/genshin/userstats.py +++ b/plugins/genshin/userstats.py @@ -2,7 +2,7 @@ import os import random from typing import Optional -from genshin import DataNotPublic, GenshinException, Client +from genshin import GenshinException, Client from telegram import Update from telegram.constants import ChatAction from telegram.ext import CallbackContext, CommandHandler, MessageHandler, ConversationHandler, filters @@ -40,21 +40,8 @@ class UserStatsPlugins(Plugin, BasePlugin): raise exc if user_info.teapot is None: raise TeapotUnlocked - try: - # 查询的UID如果是自己的,会返回DataNotPublic,自己查不了自己可还行...... - if uid > 0: - record_card_info = await client.get_record_card(uid) - else: - record_card_info = await client.get_record_card() - except DataNotPublic: - logger.warning("get_record_card请求失败 查询的用户数据未公开") - nickname = _uid - user_uid = "" - except GenshinException as exc: - raise exc - else: - nickname = record_card_info.nickname - user_uid = record_card_info.uid + nickname = user_info.info.nickname + user_uid = _uid user_avatar = user_info.characters[0].icon user_data = { "name": nickname,