LiteyukiBot-TriM/liteyuki/utils/adapter_manager/satori.py
Expliyh 974b97b744
📝 初次启动生成默认配置文件时添加 satori 相关配置
📝 将适配器配置初始化和注册移动到 utils.adapter_manager
2024-05-17 17:51:42 +08:00

29 lines
1009 B
Python

import json
import os
import nonebot
from nonebot.adapters import satori
def init(config: dict):
if config.get("satori", None) is None:
nonebot.logger.info("Satori config not found, skip Satori init.")
return None
satori_config = config.get("satori")
if not satori_config.get("enable", False):
nonebot.logger.info("Satori not enabled, skip Satori init.")
return None
if os.getenv("SATORI_CLIENTS", None) is not None:
nonebot.logger.info("Satori clients already set in environment variable, skip.")
os.environ["SATORI_CLIENTS"] = json.dumps(satori_config.get("hosts", []), ensure_ascii=False)
config['satori_clients'] = satori_config.get("hosts", [])
print(json.dumps(satori_config.get("hosts", []), ensure_ascii=False))
return
def register():
if os.getenv("SATORI_CLIENTS", None) is not None:
print(os.getenv("SATORI_CLIENTS", None))
driver = nonebot.get_driver()
driver.register_adapter(satori.Adapter)