zhenxun_bot/zhenxun/configs/config.py
HibiKier 3deffcb46c
Some checks failed
检查bot是否运行正常 / bot check (push) Has been cancelled
CodeQL Code Security Analysis / Analyze (${{ matrix.language }}) (none, javascript-typescript) (push) Has been cancelled
CodeQL Code Security Analysis / Analyze (${{ matrix.language }}) (none, python) (push) Has been cancelled
Sequential Lint and Type Check / ruff-call (push) Has been cancelled
Release Drafter / Update Release Draft (push) Has been cancelled
Force Sync to Aliyun / sync (push) Has been cancelled
Update Version / update-version (push) Has been cancelled
Sequential Lint and Type Check / pyright-call (push) Has been cancelled
增强缓存功能,优化请求管理逻辑 (#2012)
- 在 `record_request.py` 和 `group_handle/__init__.py` 中引入了 `CacheRoot`,实现请求缓存,避免重复处理相同请求。
- 在 `exception.py` 中更新 `ForceAddGroupError` 类,新增 `group_id` 属性以便于错误处理。
- 在 `data_source.py` 中修改 `ForceAddGroupError` 的抛出逻辑,包含 `group_id` 信息。
- 更新 `cache` 类,支持类型化缓存字典和列表,增强缓存的类型安全性。

此更新提升了请求处理的效率和准确性,同时增强了错误信息的可追溯性。
2025-08-06 16:31:09 +08:00

59 lines
1.5 KiB
Python

from pathlib import Path
import nonebot
from pydantic import BaseModel, Field
from .utils import ConfigsManager
__all__ = ["BotConfig", "Config"]
class BotSetting(BaseModel):
self_nickname: str = ""
"""回复时NICKNAME"""
system_proxy: str | None = None
"""系统代理"""
db_url: str = ""
"""数据库链接, 默认值为sqlite:data/zhenxun.db"""
platform_superusers: dict[str, list[str]] = Field(default_factory=dict)
"""平台超级用户"""
qbot_id_data: dict[str, str] = Field(default_factory=dict)
"""官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)
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 ""
Config = ConfigsManager(Path() / "data" / "configs" / "plugins2config.yaml")
BotConfig = nonebot.get_plugin_config(BotSetting)