群组发言时间检测提供开关配置 (#1630)

This commit is contained in:
HibiKier 2024-09-14 19:17:40 +08:00 committed by GitHub
parent f2e354edeb
commit e41e16370e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,14 +1,24 @@
from datetime import datetime, timedelta from datetime import datetime, timedelta
import nonebot
import pytz import pytz
import nonebot
from nonebot_plugin_apscheduler import scheduler 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.chat_history import ChatHistory
from zhenxun.models.group_console import GroupConsole from zhenxun.models.group_console import GroupConsole
from zhenxun.models.task_info import TaskInfo
from zhenxun.services.log import logger Config.add_plugin_config(
from zhenxun.utils.platform import PlatformUtils "chat_check",
"STATUS",
True,
help="是否开启群组两日内未发送任何消息,关闭该群全部被动",
default_value=True,
type=bool,
)
@scheduler.scheduled_job( @scheduler.scheduled_job(
@ -17,15 +27,18 @@ from zhenxun.utils.platform import PlatformUtils
minute=40, minute=40,
) )
async def _(): 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 = [] update_list = []
if modules := await TaskInfo.annotate().values_list( if modules := await TaskInfo.annotate().values_list("module", flat=True):
"module", flat=True
):
for bot in nonebot.get_bots().values(): for bot in nonebot.get_bots().values():
group_list, _ = await PlatformUtils.get_group_list(bot) 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: for group in group_list:
try: try:
last_message = ( last_message = (
@ -47,7 +60,7 @@ async def _():
"Chat检测", "Chat检测",
target=_group.group_id, target=_group.group_id,
) )
except Exception as e: except Exception:
logger.error( logger.error(
"检测群组发言时间失败...", "Chat检测", target=group.group_id "检测群组发言时间失败...", "Chat检测", target=group.group_id
) )