mirror of
https://github.com/ClovertaTheTrilobita/SanYeCao-Nonebot.git
synced 2026-04-01 22:04:51 +00:00
- 将 `BlockingScheduler` 替换为 `BackgroundScheduler` - 将 `clean_temp_cache` 函数移至 `bot.py` 并优化文件清理逻辑 - 调整日志文件路径为 `log_path + "error.log"` - 移除 `platform.py` 中冗余的缓存清理函数
39 lines
1.2 KiB
Python
39 lines
1.2 KiB
Python
import os
|
|
import glob
|
|
import logging
|
|
import nonebot
|
|
from pathlib import Path
|
|
from nonebot import logger
|
|
from nonebot.log import default_format
|
|
from nonebot.adapters.qq import Adapter as QQAdapter
|
|
from apscheduler.schedulers.background import BackgroundScheduler
|
|
from src.configs.path_config import log_path,temp_path,video_path
|
|
|
|
nonebot.init()
|
|
driver = nonebot.get_driver()
|
|
driver.register_adapter(QQAdapter) # 注册QQ适配器
|
|
nonebot.load_from_toml("pyproject.toml")
|
|
logger.add(log_path+"error.log", level="ERROR", format=default_format, rotation="1 week")
|
|
|
|
from src.clover_sqlite.data_init.db_connect import disconnect, init
|
|
driver.on_startup(init)
|
|
driver.on_shutdown(disconnect)
|
|
|
|
def clean_temp_cache():
|
|
"""定时清理缓存文件"""
|
|
path_list = [Path(temp_path), Path(video_path)]
|
|
print("开始清理文件")
|
|
for folder_path in path_list:
|
|
files = get_files_in_folder(folder_path)
|
|
for file in files:
|
|
os.remove(file)
|
|
|
|
def get_files_in_folder(folder_path: Path):
|
|
return [Path(f) for f in glob.glob(str(folder_path / "*")) if Path(f).is_file()]
|
|
|
|
scheduler = BackgroundScheduler()
|
|
scheduler.add_job(clean_temp_cache, 'cron', hour=0, minute=0)
|
|
|
|
if __name__ == "__main__":
|
|
scheduler.start()
|
|
nonebot.run()
|