add apscheduler

This commit is contained in:
yanyongyu
2020-09-12 13:34:36 +08:00
parent bd7aaa94c6
commit 4a890298db
3 changed files with 33 additions and 0 deletions

View File

@ -108,6 +108,7 @@ def get_bots() -> Union[NoReturn, Dict[str, Bot]]:
return driver.bots
from nonebot.sched import scheduler
from nonebot.config import Env, Config
from nonebot.log import logger, default_filter
from nonebot.adapters.cqhttp import Bot as CQBot
@ -169,6 +170,9 @@ def init(*, _env_file: Optional[str] = None, **kwargs):
logger.debug("Loading nonebot test frontend...")
nonebot_test.init()
if scheduler:
_driver.on_startup(_start_scheduler)
def run(host: Optional[str] = None,
port: Optional[int] = None,
@ -201,6 +205,13 @@ def run(host: Optional[str] = None,
get_driver().run(host, port, *args, **kwargs)
async def _start_scheduler():
if scheduler and not scheduler.running:
scheduler.configure(_driver.config.apscheduler_config)
scheduler.start()
logger.opt(colors=True).info("<y>Scheduler Started</y>")
from nonebot.plugin import on_message, on_notice, on_request, on_metaevent
from nonebot.plugin import on_startswith, on_endswith, on_command, on_regex
from nonebot.plugin import load_plugin, load_plugins, load_builtin_plugins, get_loaded_plugins