Files
DanDingNoneBot/danding_bot/plugins/danding_qqpush/config.py

61 lines
1.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""Danding_QqPush 插件配置模块"""
import os
from pydantic import BaseModel, model_validator
class Config(BaseModel):
"""插件配置"""
Token: str = "danding-8HkL9xQ2"
"""API 访问 Token用于鉴权必须在 .env 中配置 DANDING_QQPUSH_TOKEN"""
# 图片生成配置
ImageWidth: int = 800
"""生成的图片宽度(像素)"""
ImageFontSize: int = 24
"""字体大小(像素)"""
ImagePadding: int = 30
"""图片内边距(像素)"""
ImageLineSpacing: float = 1.4
"""行距倍数"""
ImageBgColor: tuple = (252, 252, 252)
"""图片背景颜色 (R, G, B)"""
ImageTextColor: tuple = (0, 0, 0)
"""文本颜色 (R, G, B)"""
# 文本处理配置
MaxTextLength: int = 2000
"""最大文本长度(字符数),超过将截断"""
# 字体路径配置
FontPaths: list = ("/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc",
"/usr/share/fonts/wqy-microhei/wqy-microhei.ttc",
"/usr/share/fonts/wqy-zenhei/wqy-zenhei.ttc",
"C:/Windows/Fonts/msyh.ttc",
"C:/Windows/Fonts/simhei.ttf",)
"""字体文件路径列表"""
@model_validator(mode="before")
@classmethod
def load_token_aliases(cls, values):
"""兼容 NoneBot 配置和环境变量中的 QQPush Token 命名。"""
if not isinstance(values, dict):
return values
token = (
values.get("Token")
or values.get("token")
or values.get("DANDING_QQPUSH_TOKEN")
or values.get("danding_qqpush_token")
or os.getenv("DANDING_QQPUSH_TOKEN")
)
if token:
values["Token"] = token
return values