From b0300134cb257cf4aab99f67b55bf7304959ef27 Mon Sep 17 00:00:00 2001 From: Nahida Date: Fri, 6 Jan 2023 00:04:59 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20`avatar=5Flist`:=20`Attrib?= =?UTF-8?q?uteError:=20'NoneType'=20object=20has=20no=20attribute=20'avata?= =?UTF-8?q?r'`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The list of `Character` may contain `None` --- plugins/genshin/avatar_list.py | 35 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/plugins/genshin/avatar_list.py b/plugins/genshin/avatar_list.py index 4c6c105c..2eb136e0 100644 --- a/plugins/genshin/avatar_list.py +++ b/plugins/genshin/avatar_list.py @@ -157,26 +157,21 @@ class AvatarListPlugin(Plugin, BasePlugin): task_results = await asyncio.gather(*[_task(character) for character in characters]) - return list( - filter( - lambda x: x, - sorted( - task_results, - key=lambda x: ( - x.avatar.level, - x.avatar.rarity, - x.sum_of_skills(), - x.avatar.constellation, - # TODO 如果加入武器排序条件,需要把武器转化为图片url的处理后置 - # x.weapon.level, - # x.weapon.rarity, - # x.weapon.refinement, - x.avatar.friendship, - ), - reverse=True, - )[:max_length], - ) - ) + return sorted( + list(filter(lambda x: x, task_results)), + key=lambda x: ( + x.avatar.level, + x.avatar.rarity, + x.sum_of_skills(), + x.avatar.constellation, + # TODO 如果加入武器排序条件,需要把武器转化为图片url的处理后置 + # x.weapon.level, + # x.weapon.rarity, + # x.weapon.refinement, + x.avatar.friendship, + ), + reverse=True, + )[:max_length] async def get_final_data(self, client: Client, characters: Sequence[Character], update: Update): try: