From e41e16370ea8469307f93f252a42574db57a42d9 Mon Sep 17 00:00:00 2001 From: HibiKier <45528451+HibiKier@users.noreply.github.com> Date: Sat, 14 Sep 2024 19:17:40 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=E7=BE=A4=E7=BB=84=E5=8F=91?= =?UTF-8?q?=E8=A8=80=E6=97=B6=E9=97=B4=E6=A3=80=E6=B5=8B=E6=8F=90=E4=BE=9B?= =?UTF-8?q?=E5=BC=80=E5=85=B3=E9=85=8D=E7=BD=AE=20(#1630)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../builtin_plugins/scheduler/chat_check.py | 33 +++++++++++++------ 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/zhenxun/builtin_plugins/scheduler/chat_check.py b/zhenxun/builtin_plugins/scheduler/chat_check.py index 5b4de3c1..2d4c9823 100644 --- a/zhenxun/builtin_plugins/scheduler/chat_check.py +++ b/zhenxun/builtin_plugins/scheduler/chat_check.py @@ -1,14 +1,24 @@ from datetime import datetime, timedelta -import nonebot import pytz +import nonebot from nonebot_plugin_apscheduler import scheduler +from zhenxun.services.log import logger +from zhenxun.configs.config import Config +from zhenxun.models.task_info import TaskInfo +from zhenxun.utils.platform import PlatformUtils from zhenxun.models.chat_history import ChatHistory from zhenxun.models.group_console import GroupConsole -from zhenxun.models.task_info import TaskInfo -from zhenxun.services.log import logger -from zhenxun.utils.platform import PlatformUtils + +Config.add_plugin_config( + "chat_check", + "STATUS", + True, + help="是否开启群组两日内未发送任何消息,关闭该群全部被动", + default_value=True, + type=bool, +) @scheduler.scheduled_job( @@ -17,15 +27,18 @@ from zhenxun.utils.platform import PlatformUtils minute=40, ) async def _(): + if not Config.get_config("chat_history", "FLAG"): + logger.debug("未开启历史发言记录,过滤群组发言检测...") + return + if not Config.get_config("chat_check", "STATUS"): + logger.debug("未开启群组聊天时间检查,过滤群组发言检测...") + return """检测群组发言时间并禁用全部被动""" update_list = [] - 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] - + group_list = [g for g in group_list if g.channel_id is None] for group in group_list: try: last_message = ( @@ -47,7 +60,7 @@ async def _(): "Chat检测", target=_group.group_id, ) - except Exception as e: + except Exception: logger.error( "检测群组发言时间失败...", "Chat检测", target=group.group_id )