mirror of
https://github.com/nonebot/nonebot2.git
synced 2025-07-27 16:21:28 +00:00
✨ add apscheduler
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user