-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
46 lines (33 loc) · 1.16 KB
/
Copy pathmain.py
File metadata and controls
46 lines (33 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
"""QJinEra — 拟人化赛博群友 QQBot 入口。"""
from __future__ import annotations
import asyncio
from alicebot import Bot
from config import config
from logger import get_logger, setup_logging, shutdown_logging
from services.scheduler import start_scheduler_loop
from services.storage.database import init_db
from utils import wait_all_tasks
logger = get_logger("Main")
async def main() -> None:
# 1. 初始化日志
setup_logging(level=config.log.level, log_dir=config.log.log_dir)
logger.info("启动 %s (%s) ...", config.bot.name, config.bot.english_name)
# 2. 初始化数据库
init_db()
logger.info("数据库就绪: %s", config.storage.database_file)
# 3. 启动 AliceBot
bot = Bot()
@bot.bot_run_hook
async def start_background_tasks(b: Bot) -> None:
"""注册并启动后台定时任务。"""
asyncio.create_task(start_scheduler_loop(b))
try:
await bot.run_async()
finally:
await wait_all_tasks()
shutdown_logging()
if __name__ == "__main__":
try:
asyncio.run(main())
except KeyboardInterrupt:
print("\n[System] Bot 已被手动停止。")