优化错误提示

This commit is contained in:
CMHopeSunshine 2022-12-13 21:55:32 +08:00
parent 59bb191941
commit 4e80c1bc09
2 changed files with 41 additions and 29 deletions

View File

@ -198,33 +198,38 @@ async def _(event: MessageEvent):
async def _(event: MessageEvent, players=CommandPlayer(only_cn=False), characters=CommandCharacter()): async def _(event: MessageEvent, players=CommandPlayer(only_cn=False), characters=CommandCharacter()):
logger.info('原神角色面板', '开始执行') logger.info('原神角色面板', '开始执行')
msg = Message() msg = Message()
if len(players) == 1: try:
# 当查询对象只有一个时,查询所有角色 if len(players) == 1:
gim = GenshinInfoManager(players[0].user_id, players[0].uid) # 当查询对象只有一个时,查询所有角色
await LastQuery.update_last_query(players[0].user_id, players[0].uid) gim = GenshinInfoManager(players[0].user_id, players[0].uid)
logger.info('原神角色面板', '', {'用户': players[0].user_id, 'UID': players[0].uid}) await LastQuery.update_last_query(players[0].user_id, players[0].uid)
for character in characters: logger.info('原神角色面板', '', {'用户': players[0].user_id, 'UID': players[0].uid})
character_info = await gim.get_character(name=character, data_source='enka') for character in characters:
if not character_info: character_info = await gim.get_character(name=character, data_source='enka')
logger.info('原神角色面板', '➤➤', {'角色': character}, '没有该角色信息', False) if not character_info:
msg += f'\n暂无你{character}信息,请在游戏内展柜放置该角色' logger.info('原神角色面板', '➤➤', {'角色': character}, '没有该角色信息', False)
else: msg += f'\n暂无你{character}信息,请在游戏内展柜放置该角色'
img = await draw_chara_detail(players[0].uid, character_info) else:
logger.info('原神角色面板', '➤➤➤', {}, '制图完成', True) img = await draw_chara_detail(players[0].uid, character_info)
msg += img logger.info('原神角色面板', '➤➤➤', {}, '制图完成', True)
else: msg += img
# 当查询对象有多个时,只查询第一个角色 else:
for player in players: # 当查询对象有多个时,只查询第一个角色
gim = GenshinInfoManager(player.user_id, player.uid) for player in players:
await LastQuery.update_last_query(player.user_id, player.uid) gim = GenshinInfoManager(player.user_id, player.uid)
logger.info('原神角色面板', '', {'用户': player.user_id, 'UID': player.uid}) await LastQuery.update_last_query(player.user_id, player.uid)
character_info = await gim.get_character(name=characters[0], data_source='enka') logger.info('原神角色面板', '', {'用户': player.user_id, 'UID': player.uid})
if not character_info: character_info = await gim.get_character(name=characters[0], data_source='enka')
msg += f'\n暂无{player.uid}{characters[0]}信息,请在游戏内展柜放置该角色' if not character_info:
else: msg += f'\n暂无{player.uid}{characters[0]}信息,请在游戏内展柜放置该角色'
img = await draw_chara_detail(player.uid, character_info) else:
logger.info('原神角色面板', '➤➤➤', {}, '制图完成', True) img = await draw_chara_detail(player.uid, character_info)
msg += img logger.info('原神角色面板', '➤➤➤', {}, '制图完成', True)
msg += img
except KeyError as e:
msg = f'获取角色信息失败,缺少{e}的数据可能是Enka.Network接口出现问题'
except Exception as e:
msg = f'获取角色信息失败,错误信息:{e}'
await ysd.finish(msg, at_sender=True) await ysd.finish(msg, at_sender=True)
@ -248,7 +253,7 @@ async def _(event: MessageEvent, state: T_State, uid=CommandUID()):
gim = GenshinInfoManager(str(event.user_id), uid) gim = GenshinInfoManager(str(event.user_id), uid)
result = await gim.update_all(include_talent) result = await gim.update_all(include_talent)
except KeyError as e: except KeyError as e:
result = f'更新失败,缺少{e}的数据,请尝试更新bot版本' result = f'更新失败,缺少{e}的数据,可能是Enka.Network接口出现问题'
except Exception as e: except Exception as e:
result = f'更新失败,错误信息:{e}' result = f'更新失败,错误信息:{e}'
running_udi.remove(f'{event.user_id}-{uid}') running_udi.remove(f'{event.user_id}-{uid}')

View File

@ -173,7 +173,14 @@ class GenshinInfoManager:
if not character or character.update_time < ( if not character or character.update_time < (
datetime.datetime.now() - datetime.timedelta(hours=config.ysd_auto_update)).replace( datetime.datetime.now() - datetime.timedelta(hours=config.ysd_auto_update)).replace(
tzinfo=pytz.timezone('UTC')): tzinfo=pytz.timezone('UTC')):
await self.update_from_enka() try:
await self.update_from_enka()
except Exception as e:
logger.info('原神角色面板', '➤➤', {'角色': name or character_id}, f'数据更新失败可能是Enka.Network接口出现问题:{e}', False)
if character:
return character
else:
raise e
if character := await Character.get_or_none(**query, data_source='enka'): if character := await Character.get_or_none(**query, data_source='enka'):
logger.info('原神角色面板', '➤➤', {'角色': name or character_id}, '数据更新成功', True) logger.info('原神角色面板', '➤➤', {'角色': name or character_id}, '数据更新成功', True)
else: else: