2021-11-04 16:11:50 +08:00
|
|
|
from pathlib import Path
|
2023-02-18 18:46:54 +08:00
|
|
|
|
2024-08-24 19:32:52 +08:00
|
|
|
import nonebot
|
2025-02-04 02:15:21 +08:00
|
|
|
from pydantic import BaseModel, Field
|
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
|
|
|
|
2025-02-03 21:23:14 +08:00
|
|
|
__all__ = ["BotConfig", "Config"]
|
|
|
|
|
|
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
|
|
|
|
|
"""系统代理"""
|
2025-08-06 16:31:09 +08:00
|
|
|
db_url: str = ""
|
2025-07-14 22:35:29 +08:00
|
|
|
"""数据库链接, 默认值为sqlite:data/zhenxun.db"""
|
2025-02-04 02:15:21 +08:00
|
|
|
platform_superusers: dict[str, list[str]] = Field(default_factory=dict)
|
2024-08-24 19:32:52 +08:00
|
|
|
"""平台超级用户"""
|
2025-02-04 02:15:21 +08:00
|
|
|
qbot_id_data: dict[str, str] = Field(default_factory=dict)
|
2024-10-18 18:57:55 +08:00
|
|
|
"""官bot id:账号id"""
|
|
|
|
|
|
|
|
|
|
def get_qbot_uid(self, qbot_id: str) -> str | None:
|
|
|
|
|
"""获取官bot账号id
|
|
|
|
|
|
|
|
|
|
参数:
|
|
|
|
|
qbot_id: 官bot id
|
|
|
|
|
|
|
|
|
|
返回:
|
|
|
|
|
str: 账号id
|
|
|
|
|
"""
|
|
|
|
|
return self.qbot_id_data.get(qbot_id)
|
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:
|
|
|
|
|
"""获取数据库类型
|
|
|
|
|
|
|
|
|
|
返回:
|
2024-11-18 11:06:13 +08:00
|
|
|
str: 数据库类型, postgres, mysql, sqlite
|
2024-09-07 16:46:56 +08:00
|
|
|
"""
|
|
|
|
|
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)
|