🎨代码优化 (#1586)

*  更新插件俄罗斯轮盘

* 🎨代码优化
This commit is contained in:
xuanerwa 2024-08-27 17:34:44 +08:00 committed by GitHub
parent 72641c7983
commit ab1d0d22dd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -19,22 +19,23 @@ from zhenxun.utils.platform import PlatformUtils
async def _(): async def _():
"""检测群组发言时间并禁用全部被动""" """检测群组发言时间并禁用全部被动"""
update_list = [] update_list = []
for bot in nonebot.get_bots().values(): if modules := await TaskInfo.annotate().values_list(
group_list, _ = await PlatformUtils.get_group_list(bot) "module", flat=True
group_list = [g for g in group_list if g.channel_id == None] ):
for group in group_list: for bot in nonebot.get_bots().values():
try: group_list, _ = await PlatformUtils.get_group_list(bot)
last_message = ( group_list = [g for g in group_list if g.channel_id == None]
await ChatHistory.filter(group_id=group.group_id)
.annotate() for group in group_list:
.order_by("-create_time") try:
.first() last_message = (
) await ChatHistory.filter(group_id=group.group_id)
if last_message: .annotate()
now = datetime.now(pytz.timezone("Asia/Shanghai")) .order_by("-create_time")
if modules := await TaskInfo.annotate().values_list( .first()
"module", flat=True )
): if last_message:
now = datetime.now(pytz.timezone("Asia/Shanghai"))
if now - timedelta(days=2) > last_message.create_time: if now - timedelta(days=2) > last_message.create_time:
_group, _ = await GroupConsole.get_or_create( _group, _ = await GroupConsole.get_or_create(
group_id=group.group_id, channel_id__isnull=True group_id=group.group_id, channel_id__isnull=True
@ -46,9 +47,9 @@ async def _():
"Chat检测", "Chat检测",
target=_group.group_id, target=_group.group_id,
) )
except Exception as e: except Exception as e:
logger.error( logger.error(
"检测群组发言时间失败...", "Chat检测", target=group.group_id "检测群组发言时间失败...", "Chat检测", target=group.group_id
) )
if update_list: if update_list:
await GroupConsole.bulk_update(update_list, ["block_task"], 10) await GroupConsole.bulk_update(update_list, ["block_task"], 10)