def app( nonebug_init: None, tmp_path: Path, monkeypatch: pytest.MonkeyPatch, request, ) -> App: param = getattr(request, "param", ()) import nonebot config = nonebot.get_driver().config # 插件数据目录 config.datastore_cache_dir = tmp_path / "cache" config.datastore_config_dir = tmp_path / "config" config.datastore_data_dir = tmp_path / "data" # 加载插件 # 默认加载所有插件 if param: for plugin in param: nonebot.load_plugin(plugin) else: nonebot.load_from_toml("pyproject.toml") return App(monkeypatch)
# from nonebot.log import logger, default_format # logger.add("error.log", # rotation="00:00", # diagnose=False, # level="ERROR", # format=default_format) # 初始化 # You can pass some keyword args config to init function nonebot.init() app = nonebot.get_asgi() driver = nonebot.get_driver() # 使用协议 driver.register_adapter("cqhttp", CQHTTPBot) # 加载插件 nonebot.load_plugin("nonebot_plugin_biliav") nonebot.load_builtin_plugins() nonebot.load_from_toml("pyproject.toml") # Modify some config / config depends on loaded configs # # config = driver.config # do something... if __name__ == "__main__": nonebot.logger.warning("Always use `nb run` to start the bot instead of manually running!") nonebot.run(app="__mp_main__:app")
# test custom log logger.add("error.log", rotation="00:00", diagnose=False, level="ERROR", format=default_format) nonebot.init(custom_config2="config on init") app = nonebot.get_asgi() driver = nonebot.get_driver() driver.register_adapter("cqhttp", Bot) driver.register_adapter("ding", DingBot) driver.register_adapter("mirai", MiraiBot) driver.register_adapter("feishu", FeishuBot) # load builtin plugin nonebot.load_builtin_plugins() # load all plugins nonebot.load_from_toml("plugins.toml") # modify some config / config depends on loaded configs config = driver.config config.custom_config3 = config.custom_config1 config.custom_config4 = "New custom config" if __name__ == "__main__": nonebot.run(app="__mp_main__:app") # nonebot.run()
import nonebot from nonebot.adapters.cqhttp import Bot as CQHTTPBot # Custom your logger # # from nonebot.log import logger, default_format # logger.add('error.log', # rotation='00:00', # diagnose=False, # level='ERROR', # format=default_format) # You can pass some keyword args config to init function nonebot.init() app = nonebot.get_asgi() driver = nonebot.get_driver() driver.register_adapter('cqhttp', CQHTTPBot) nonebot.load_from_toml('pyproject.toml') # Modify some config / config depends on loaded configs # # config = driver.config # do something... if __name__ == '__main__': nonebot.logger.warning( 'Always use `nb run` to start the bot instead of manually running!') nonebot.run(app='__mp_main__:app')