Files
zhenxun_bot/zhenxun/configs/config.py
T

44 lines
1.0 KiB
Python
Raw Normal View History

2021-11-04 16:11:50 +08:00
from pathlib import Path
2024-08-24 19:32:52 +08:00
import nonebot
from pydantic import BaseModel
2021-08-06 19:42:02 +08:00
2024-08-24 19:32:52 +08:00
from .utils import ConfigsManager
2024-08-24 17:06:23 +08:00
2024-08-24 19:32:52 +08:00
class BotSetting(BaseModel):
self_nickname: str = ""
"""回复时NICKNAME"""
system_proxy: str | None = None
"""系统代理"""
db_url: str = ""
"""数据库链接"""
platform_superusers: dict[str, list[str]] = {}
"""平台超级用户"""
2024-08-24 17:06:23 +08:00
2024-09-09 23:01:15 +08:00
def get_superuser(self, platform: str) -> list[str]:
2024-08-24 19:32:52 +08:00
"""获取超级用户
2024-08-24 17:06:23 +08:00
2024-08-24 19:32:52 +08:00
参数:
platform: 对应平台
2024-08-24 17:06:23 +08:00
2024-08-24 19:32:52 +08:00
返回:
2024-09-09 23:01:15 +08:00
list[str]: 超级用户id
2024-08-24 19:32:52 +08:00
"""
if self.platform_superusers:
2024-09-09 23:01:15 +08:00
return self.platform_superusers.get(platform, [])
return []
2021-05-20 18:37:51 +08:00
2024-09-07 16:46:56 +08:00
def get_sql_type(self) -> str:
"""获取数据库类型
返回:
str: 数据库类型, postgres, aiomysql, sqlite
"""
return self.db_url.split(":", 1)[0] if self.db_url else ""
2021-05-20 18:37:51 +08:00
2021-11-04 16:11:50 +08:00
Config = ConfigsManager(Path() / "data" / "configs" / "plugins2config.yaml")
2024-08-24 17:06:23 +08:00
2024-08-24 19:32:52 +08:00
BotConfig = nonebot.get_plugin_config(BotSetting)