🐛 修复多bot连接时深渊统计猜语音可能报错的问题

This commit is contained in:
CMHopeSunshine 2023-02-17 22:57:12 +08:00
parent 4c3b1e5631
commit 33c5fbd2da

View File

@ -37,25 +37,26 @@ async def get_group_avatar(group_id: str):
async def get_statistics(group_id: int, bot: Bot): async def get_statistics(group_id: int, bot: Bot):
now = datetime.datetime.now() if not (info_list := await AbyssInfo.all()):
abyss_info_list = await AbyssInfo.filter(
total_battle__not=None,
total_star__not=None,
max_damage__not=None,
max_take_damage__not=None,
start_time__lte=now,
end_time__gte=now,
)
if not abyss_info_list:
return '本群还没有深渊战斗数据哦!' return '本群还没有深渊战斗数据哦!'
member_list = await bot.get_group_member_list(group_id=group_id) member_list = await bot.get_group_member_list(group_id=group_id)
member_id_list = [str(member['user_id']) for member in member_list] member_id_list = [str(member['user_id']) for member in member_list]
info_list = [info for info in abyss_info_list if info.user_id in member_id_list] info_list = [
if not abyss_info_list: info
for info in info_list
if info.user_id in member_id_list
and info.total_battle
and info.total_star
and info.max_damage
and info.max_take_damage
]
now = datetime.datetime.now().replace(tzinfo=pytz.timezone('Asia/Shanghai'))
info_list = [info for info in info_list if info.start_time <= now <= info.end_time]
if not info_list:
return '本群还没有深渊战斗数据哦!' return '本群还没有深渊战斗数据哦!'
elif len(abyss_info_list) < 3: elif len(info_list) < 3:
return '本群深渊有效战斗数据不足3人无法生成统计图' return '本群深渊有效战斗数据不足3人无法生成统计图'
for info in abyss_info_list: for info in info_list:
if info.nickname is None: if info.nickname is None:
for member in member_list: for member in member_list:
if info.user_id == str(member['user_id']): if info.user_id == str(member['user_id']):