nonebot2/packages/nonebot-plugin-docs/nonebot_plugin_docs/__init__.py

40 lines
1.1 KiB
Python
Raw Permalink Normal View History

2020-11-22 01:20:14 +08:00
import importlib
import nonebot
from nonebot.log import logger
from nonebot.plugin import PluginMetadata
__plugin_meta__ = PluginMetadata(
name="NoneBot 离线文档",
description="在本地查看 NoneBot 文档",
usage="启动机器人后访问 http://localhost:port/website/ 查看文档",
type="application",
homepage="https://github.com/nonebot/nonebot2/blob/master/packages/nonebot-plugin-docs",
config=None,
supported_adapters=None,
)
2020-11-22 01:20:14 +08:00
def init():
driver = nonebot.get_driver()
try:
2021-12-29 21:09:31 +08:00
_module = importlib.import_module(
f"nonebot_plugin_docs.drivers.{driver.type.split('+')[0]}"
)
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"}:
2020-11-22 01:20:14 +08:00
host = "localhost"
logger.opt(colors=True).info(
2022-01-08 19:36:19 +08:00
f"Nonebot docs will be running at: "
f"<b><u>http://{host}:{port}/website/</u></b>"
)
2020-11-22 01:20:14 +08:00
init()