mirror of
https://github.com/LiteyukiStudio/LiteyukiBot.git
synced 2025-07-27 19:10:55 +00:00
📝 使用 driver_manager 自动管理启用的驱动器,无需手动配置环境变量 (当配置了环境变量时环境变量优先)
This commit is contained in:
20
liteyuki/utils/driver_manager/auto_set_env.py
Normal file
20
liteyuki/utils/driver_manager/auto_set_env.py
Normal file
@ -0,0 +1,20 @@
|
||||
import os
|
||||
|
||||
import dotenv
|
||||
import nonebot
|
||||
|
||||
from .defines import *
|
||||
|
||||
|
||||
def auto_set_env(config: dict):
|
||||
dotenv.load_dotenv()
|
||||
if os.getenv("DRIVER", None) is not None:
|
||||
nonebot.logger.info("Driver already set in environment variable, skip auto configure.")
|
||||
return
|
||||
if config.get("enable_satori", False):
|
||||
os.environ["DRIVER"] = get_driver_string(ASGI_DRIVER, HTTPX_DRIVER, WEBSOCKETS_DRIVER)
|
||||
nonebot.logger.info("Enable Satori, set driver to ASGI+HTTPX+WEBSOCKETS")
|
||||
else:
|
||||
os.environ["DRIVER"] = get_driver_string(ASGI_DRIVER)
|
||||
nonebot.logger.info("Disable Satori, set driver to ASGI")
|
||||
return
|
Reference in New Issue
Block a user