From c67b9a888ab8585f323807c1cdf6c53dcdfc8f59 Mon Sep 17 00:00:00 2001 From: SlyAimer <2289782085@qq.com> Date: Sat, 25 Jan 2025 21:24:59 +0800 Subject: [PATCH] =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=E6=8F=90?= =?UTF-8?q?=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/configs/config.py | 49 +++++++++++++++++++++++++++++++++++ src/configs/path_config.py | 27 +++++++++++++++++++ src/configs/utils/__init__.py | 0 3 files changed, 76 insertions(+) create mode 100644 src/configs/config.py create mode 100644 src/configs/path_config.py create mode 100644 src/configs/utils/__init__.py diff --git a/src/configs/config.py b/src/configs/config.py new file mode 100644 index 0000000..1da6b9a --- /dev/null +++ b/src/configs/config.py @@ -0,0 +1,49 @@ +from pathlib import Path +import nonebot +from collections import defaultdict +from pydantic import BaseModel + + +class BotSetting(BaseModel): + """" + Bot 配置 + """ + #数据库链接 + db_url: str = "sqlite://./chat_bot.db" + # 超级用户 + platform_superusers = {"QQ": [""]} + #官bot id:账号id + bot_id_data = {"BOT_ACCOUNT":"bot1","BOT_APPID": "user1",} + + def get_bot_uid(self, bot_id: str) -> str | None: + """获取官bot账号id + + 参数: + bot_id: 官bot id + + 返回: + str: 账号id + """ + return self.bot_id_data.get(bot_id) + + def get_superuser(self, platform: str) -> list[str]: + """获取超级用户 + + 参数: + platform: 对应平台 + + 返回: + list[str]: 超级用户id + """ + if self.platform_superusers: + return self.platform_superusers.get(platform, []) + return [] + + def get_sql_type(self) -> str: + """获取数据库类型 + + 返回: + str: 数据库类型, postgres, mysql, sqlite + """ + return self.db_url.split(":", 1)[0] if self.db_url else "" + diff --git a/src/configs/path_config.py b/src/configs/path_config.py new file mode 100644 index 0000000..e100ca2 --- /dev/null +++ b/src/configs/path_config.py @@ -0,0 +1,27 @@ +from pathlib import Path + +# 图片路径 +IMAGE_PATH = Path() / "resources" / "image" +# 语音路径 +RECORD_PATH = Path() / "resources" / "record" +# 文本路径 +TEXT_PATH = Path() / "resources" / "text" +# 日志路径 +LOG_PATH = Path() / "log" +# 字体路径 +FONT_PATH = Path() / "resources" / "font" +# 数据路径 +DATA_PATH = Path() / "data" +# 临时数据路径 +TEMP_PATH = Path() / "resources" / "temp" +# 网页模板路径 +TEMPLATE_PATH = Path() / "resources" / "template" + + +IMAGE_PATH.mkdir(parents=True, exist_ok=True) +RECORD_PATH.mkdir(parents=True, exist_ok=True) +TEXT_PATH.mkdir(parents=True, exist_ok=True) +LOG_PATH.mkdir(parents=True, exist_ok=True) +FONT_PATH.mkdir(parents=True, exist_ok=True) +DATA_PATH.mkdir(parents=True, exist_ok=True) +TEMP_PATH.mkdir(parents=True, exist_ok=True) diff --git a/src/configs/utils/__init__.py b/src/configs/utils/__init__.py new file mode 100644 index 0000000..e69de29