mirror of
https://github.com/nonebot/nonebot2.git
synced 2025-07-27 16:21:28 +00:00
Add APScheduler as builtin scheduler
This commit is contained in:
@ -9,6 +9,12 @@ from aiocqhttp import CQHttp
|
||||
from aiocqhttp.message import Message
|
||||
|
||||
from .log import logger
|
||||
from .scheduler import Scheduler
|
||||
|
||||
if Scheduler:
|
||||
scheduler = Scheduler()
|
||||
else:
|
||||
scheduler = None
|
||||
|
||||
|
||||
class NoneBot(CQHttp):
|
||||
@ -40,6 +46,9 @@ class NoneBot(CQHttp):
|
||||
async def _(ctx):
|
||||
asyncio.ensure_future(handle_notice_or_request(self, ctx))
|
||||
|
||||
if scheduler:
|
||||
scheduler.configure(self.config.APSCHEDULER_CONFIG)
|
||||
|
||||
def run(self, host: str = None, port: int = None, *args, **kwargs):
|
||||
host = host or self.config.HOST
|
||||
port = port or self.config.PORT
|
||||
@ -88,6 +97,8 @@ def get_bot() -> NoneBot:
|
||||
|
||||
def run(host: str = None, port: int = None, *args, **kwargs) -> None:
|
||||
"""Run the NoneBot instance."""
|
||||
if scheduler and not scheduler.running:
|
||||
scheduler.start()
|
||||
get_bot().run(host=host, port=port, *args, **kwargs)
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user