mirror of
https://github.com/PaiGramTeam/PaiGram.git
synced 2024-11-26 18:20:39 +00:00
8f424bf0d4
♻️ 重构插件系统 ⚙️ 重写插件 🎨 改进代码结构 📝 完善文档 Co-authored-by: zhxy-CN <admin@owo.cab> Co-authored-by: 洛水居室 <luoshuijs@outlook.com> Co-authored-by: xtaodada <xtao@xtaolink.cn> Co-authored-by: Li Chuangbo <im@chuangbo.li>
89 lines
1.6 KiB
Python
89 lines
1.6 KiB
Python
from typing import (
|
|
List,
|
|
Optional,
|
|
Union,
|
|
)
|
|
|
|
import dotenv
|
|
import ujson as json
|
|
from pydantic import (
|
|
BaseModel,
|
|
BaseSettings,
|
|
)
|
|
|
|
__all__ = ['BotConfig', 'config']
|
|
|
|
dotenv.load_dotenv()
|
|
|
|
|
|
class BotConfig(BaseSettings):
|
|
debug: bool = False
|
|
|
|
db_host: str
|
|
db_port: int
|
|
db_username: str
|
|
db_password: str
|
|
db_database: str
|
|
|
|
redis_host: str
|
|
redis_port: int
|
|
redis_db: int
|
|
|
|
bot_token: str
|
|
error_notification_chat_id: str
|
|
|
|
channels: List['ConfigChannel'] = []
|
|
admins: List['ConfigUser'] = []
|
|
verify_groups: List[Union[int, str]] = []
|
|
|
|
class Config:
|
|
case_sensitive = False
|
|
json_loads = json.loads
|
|
json_dumps = json.dumps
|
|
|
|
@property
|
|
def mysql(self) -> "MySqlConfig":
|
|
return MySqlConfig(
|
|
host=self.db_host,
|
|
port=self.db_port,
|
|
username=self.db_username,
|
|
password=self.db_password,
|
|
database=self.db_database,
|
|
)
|
|
|
|
@property
|
|
def redis(self) -> "RedisConfig":
|
|
return RedisConfig(
|
|
host=self.redis_host,
|
|
port=self.redis_port,
|
|
database=self.redis_db,
|
|
)
|
|
|
|
|
|
class ConfigChannel(BaseModel):
|
|
name: str
|
|
chat_id: int
|
|
|
|
|
|
class ConfigUser(BaseModel):
|
|
username: Optional[str]
|
|
user_id: int
|
|
|
|
|
|
class MySqlConfig(BaseModel):
|
|
host: str = "127.0.0.1"
|
|
port: int = 3306
|
|
username: str
|
|
password: str
|
|
database: str
|
|
|
|
|
|
class RedisConfig(BaseModel):
|
|
host: str = '127.0.0.1'
|
|
port: int
|
|
database: int = 0
|
|
|
|
|
|
BotConfig.update_forward_refs()
|
|
config = BotConfig()
|