From ab1d0d22dda035debb91bae6084291a04317a872 Mon Sep 17 00:00:00 2001 From: xuanerwa <58063798+xuanerwa@users.noreply.github.com> Date: Tue, 27 Aug 2024 17:34:44 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=E4=BB=A3=E7=A0=81=E4=BC=98?= =?UTF-8?q?=E5=8C=96=20(#1586)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * ✨ 更新插件俄罗斯轮盘 * 🎨代码优化 --- .../builtin_plugins/scheduler/chat_check.py | 41 ++++++++++--------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/zhenxun/builtin_plugins/scheduler/chat_check.py b/zhenxun/builtin_plugins/scheduler/chat_check.py index 599dff35..5b4de3c1 100644 --- a/zhenxun/builtin_plugins/scheduler/chat_check.py +++ b/zhenxun/builtin_plugins/scheduler/chat_check.py @@ -19,22 +19,23 @@ from zhenxun.utils.platform import PlatformUtils async def _(): """检测群组发言时间并禁用全部被动""" update_list = [] - for bot in nonebot.get_bots().values(): - group_list, _ = await PlatformUtils.get_group_list(bot) - group_list = [g for g in group_list if g.channel_id == None] - for group in group_list: - try: - last_message = ( - await ChatHistory.filter(group_id=group.group_id) - .annotate() - .order_by("-create_time") - .first() - ) - if last_message: - now = datetime.now(pytz.timezone("Asia/Shanghai")) - if modules := await TaskInfo.annotate().values_list( - "module", flat=True - ): + if modules := await TaskInfo.annotate().values_list( + "module", flat=True + ): + for bot in nonebot.get_bots().values(): + group_list, _ = await PlatformUtils.get_group_list(bot) + group_list = [g for g in group_list if g.channel_id == None] + + for group in group_list: + try: + last_message = ( + await ChatHistory.filter(group_id=group.group_id) + .annotate() + .order_by("-create_time") + .first() + ) + if last_message: + now = datetime.now(pytz.timezone("Asia/Shanghai")) if now - timedelta(days=2) > last_message.create_time: _group, _ = await GroupConsole.get_or_create( group_id=group.group_id, channel_id__isnull=True @@ -46,9 +47,9 @@ async def _(): "Chat检测", target=_group.group_id, ) - except Exception as e: - logger.error( - "检测群组发言时间失败...", "Chat检测", target=group.group_id - ) + except Exception as e: + logger.error( + "检测群组发言时间失败...", "Chat检测", target=group.group_id + ) if update_list: await GroupConsole.bulk_update(update_list, ["block_task"], 10)