zhenxun_bot/basic_plugins/admin_bot_manage/timing_task.py

52 lines
1.5 KiB
Python
Raw Normal View History

2021-07-30 21:21:51 +08:00
from utils.utils import scheduler, get_bot
from .data_source import update_member_info
from services.log import logger
from models.group_info import GroupInfo
2021-11-04 16:11:50 +08:00
from asyncpg.exceptions import ConnectionDoesNotExistError, UndefinedColumnError
2021-07-30 21:21:51 +08:00
2021-10-03 14:24:07 +08:00
__zx_plugin_name__ = '管理方面定时任务 [Hidden]'
__plugin_usage__ = ''
__plugin_des__ = '成员信息和管理权限的定时更新'
__plugin_version__ = 0.1
__plugin_author__ = 'HibiKier'
2021-07-30 21:21:51 +08:00
# 自动更新群员信息
@scheduler.scheduled_job(
"cron",
hour=2,
minute=1,
)
async def _():
bot = get_bot()
2021-10-03 14:24:07 +08:00
if bot:
gl = await bot.get_group_list()
gl = [g["group_id"] for g in gl]
for g in gl:
try:
await update_member_info(g)
logger.info(f"更新群组 g:{g} 成功")
except Exception as e:
logger.error(f"更新群组错误 g:{g} e:{e}")
2021-07-30 21:21:51 +08:00
# 快速更新群员信息以及管理员权限
@scheduler.scheduled_job(
"interval",
minutes=5,
)
async def _():
2021-07-30 22:28:13 +08:00
try:
bot = get_bot()
2021-10-03 14:24:07 +08:00
if bot:
gl = await bot.get_group_list()
gl = [g["group_id"] for g in gl]
all_group = [x.group_id for x in await GroupInfo.get_all_group()]
for g in gl:
if g not in all_group:
2021-10-04 20:22:09 +08:00
await update_member_info(g, False)
2021-10-03 14:24:07 +08:00
logger.info(f"快速更新群信息以及权限:{g}")
2021-11-04 16:11:50 +08:00
except (IndexError, ConnectionDoesNotExistError, UndefinedColumnError):
2021-07-30 22:28:13 +08:00
pass