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 )