2020-11-22 01:20:14 +08:00
|
|
|
import importlib
|
|
|
|
|
|
|
|
import nonebot
|
|
|
|
from nonebot.log import logger
|
|
|
|
|
|
|
|
|
|
|
|
def init():
|
|
|
|
driver = nonebot.get_driver()
|
|
|
|
try:
|
2021-11-22 23:21:26 +08:00
|
|
|
_module = importlib.import_module(f"nonebot_plugin_docs.drivers.{driver.type}")
|
2020-11-22 01:20:14 +08:00
|
|
|
except ImportError:
|
|
|
|
logger.warning(f"Driver {driver.type} not supported")
|
|
|
|
return
|
|
|
|
register_route = getattr(_module, "register_route")
|
|
|
|
register_route(driver)
|
|
|
|
host = str(driver.config.host)
|
|
|
|
port = driver.config.port
|
|
|
|
if host in ["0.0.0.0", "127.0.0.1"]:
|
|
|
|
host = "localhost"
|
2021-11-22 23:21:26 +08:00
|
|
|
logger.opt(colors=True).info(
|
|
|
|
f"Nonebot docs will be running at: " f"<b><u>http://{host}:{port}/docs/</u></b>"
|
|
|
|
)
|
2020-11-22 01:20:14 +08:00
|
|
|
|
|
|
|
|
|
|
|
init()
|