2024-05-17 16:26:30 +08:00
|
|
|
import os
|
|
|
|
|
|
|
|
import dotenv
|
|
|
|
import nonebot
|
|
|
|
|
|
|
|
from .defines import *
|
|
|
|
|
|
|
|
|
|
|
|
def auto_set_env(config: dict):
|
2024-05-17 18:00:07 +08:00
|
|
|
dotenv.load_dotenv(".env")
|
2024-05-17 16:26:30 +08:00
|
|
|
if os.getenv("DRIVER", None) is not None:
|
2024-05-17 18:00:07 +08:00
|
|
|
print(os.getenv("DRIVER"))
|
2024-05-17 16:26:30 +08:00
|
|
|
nonebot.logger.info("Driver already set in environment variable, skip auto configure.")
|
|
|
|
return
|
2024-05-17 17:51:42 +08:00
|
|
|
if config.get("satori", {'enable': False}).get("enable", False):
|
2024-05-17 16:26:30 +08:00
|
|
|
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
|