security: move onmyoji_gacha BOT_TOKEN to env var (was hardcoded plaintext)

This commit is contained in:
2026-05-09 23:42:48 +08:00
parent fd2fd90f05
commit b444bd62f5
2 changed files with 125 additions and 118 deletions

View File

@@ -31,10 +31,11 @@ def mask_username(username: str) -> str:
# 获取配置 # 获取配置
config = Config() config = Config()
# API 端点配置 # API endpoint from config
DD_API_HOST = "https://api.danding.vip/DD/" # 蛋定服务器连接地址 DD_API_HOST = config.DD_API_HOST
BOT_TOKEN = "3340e353a49447f1be640543cbdcd937" # 对接服务器的Token # Secrets from config (sourced from environment variables)
BOT_USER_ID = "1424473282" # 机器人用户ID BOT_TOKEN = config.BOT_TOKEN
BOT_USER_ID = config.BOT_USER_ID
async def query_qq_binding(qq: str) -> Tuple[bool, Optional[str], Optional[str]]: async def query_qq_binding(qq: str) -> Tuple[bool, Optional[str], Optional[str]]:
""" """

View File

@@ -1,115 +1,121 @@
from pydantic_settings import BaseSettings, SettingsConfigDict from pydantic_settings import BaseSettings, SettingsConfigDict
import os import os
class Config(BaseSettings): class Config(BaseSettings):
model_config = SettingsConfigDict(extra="ignore") model_config = SettingsConfigDict(extra="ignore")
# 抽卡概率配置 # 抽卡概率配置
RARITY_PROBABILITY: dict = { RARITY_PROBABILITY: dict = {
"R": 78.75, "R": 78.75,
"SR": 20.0, "SR": 20.0,
"SSR": 1.0, "SSR": 1.0,
"SP": 0.25 "SP": 0.25
} }
# 每日抽卡限制 # 每日抽卡限制
DAILY_LIMIT: int = 3 DAILY_LIMIT: int = 3
# 数据文件路径 # 数据文件路径
DB_FILE: str = "data/onmyoji_gacha/gacha.db" DB_FILE: str = "data/onmyoji_gacha/gacha.db"
# 式神图片目录 # 式神图片目录
SHIKIGAMI_IMG_DIR: str = "data/chouka/" SHIKIGAMI_IMG_DIR: str = "data/chouka/"
# 触发指令 # 触发指令
GACHA_COMMANDS: list = ["抽卡","抽奖", "召唤"] GACHA_COMMANDS: list = ["抽卡","抽奖", "召唤"]
STATS_COMMANDS: list = ["我的抽卡","我的抽奖", "我的图鉴"] STATS_COMMANDS: list = ["我的抽卡","我的抽奖", "我的图鉴"]
DAILY_STATS_COMMANDS: list = ["今日抽卡", "今日统计", "抽卡统计"] DAILY_STATS_COMMANDS: list = ["今日抽卡", "今日统计", "抽卡统计"]
TRIPLE_GACHA_COMMANDS: list = ["三连", "三连抽"] TRIPLE_GACHA_COMMANDS: list = ["三连", "三连抽"]
ACHIEVEMENT_COMMANDS: list = ["查询成就", "抽卡成就"] ACHIEVEMENT_COMMANDS: list = ["查询成就", "抽卡成就"]
INTRO_COMMANDS: list = ["抽卡介绍", "抽卡说明", "抽卡帮助"] INTRO_COMMANDS: list = ["抽卡介绍", "抽卡说明", "抽卡帮助"]
# 成就系统配置 # 成就系统配置
ACHIEVEMENTS: dict = { ACHIEVEMENTS: dict = {
"consecutive_days_30_1": { "consecutive_days_30_1": {
"name": "勤勤恳恳Ⅰ", "name": "勤勤恳恳Ⅰ",
"description": "连续抽卡30天", "description": "连续抽卡30天",
"reward": "天卡", "reward": "天卡",
"threshold": 30, "threshold": 30,
"type": "consecutive_days", "type": "consecutive_days",
"level": 1, "level": 1,
"repeatable": True "repeatable": True
}, },
"consecutive_days_30_2": { "consecutive_days_30_2": {
"name": "勤勤恳恳Ⅱ", "name": "勤勤恳恳Ⅱ",
"description": "连续抽卡60天", "description": "连续抽卡60天",
"reward": "天卡", "reward": "天卡",
"threshold": 60, "threshold": 60,
"type": "consecutive_days", "type": "consecutive_days",
"level": 2, "level": 2,
"repeatable": True "repeatable": True
}, },
"consecutive_days_30_3": { "consecutive_days_30_3": {
"name": "勤勤恳恳Ⅲ", "name": "勤勤恳恳Ⅲ",
"description": "连续抽卡90天", "description": "连续抽卡90天",
"reward": "天卡", "reward": "天卡",
"threshold": 90, "threshold": 90,
"type": "consecutive_days", "type": "consecutive_days",
"level": 3, "level": 3,
"repeatable": True "repeatable": True
}, },
"consecutive_days_30_4": { "consecutive_days_30_4": {
"name": "勤勤恳恳Ⅳ", "name": "勤勤恳恳Ⅳ",
"description": "连续抽卡120天", "description": "连续抽卡120天",
"reward": "周卡", "reward": "周卡",
"threshold": 120, "threshold": 120,
"type": "consecutive_days", "type": "consecutive_days",
"level": 4, "level": 4,
"repeatable": True "repeatable": True
}, },
"consecutive_days_30_5": { "consecutive_days_30_5": {
"name": "勤勤恳恳Ⅴ", "name": "勤勤恳恳Ⅴ",
"description": "连续抽卡150天", "description": "连续抽卡150天",
"reward": "周卡", "reward": "周卡",
"threshold": 150, "threshold": 150,
"type": "consecutive_days", "type": "consecutive_days",
"level": 5, "level": 5,
"repeatable": True, "repeatable": True,
"repeat_reward": "天卡" "repeat_reward": "天卡"
}, },
"no_ssr_60": { "no_ssr_60": {
"name": "非酋", "name": "非酋",
"description": "连续60次未抽到SSR/SP", "description": "连续60次未抽到SSR/SP",
"reward": "天卡", "reward": "天卡",
"threshold": 60, "threshold": 60,
"type": "no_ssr_streak" "type": "no_ssr_streak"
}, },
"no_ssr_120": { "no_ssr_120": {
"name": "顶级非酋", "name": "顶级非酋",
"description": "连续120次未抽到SSR/SP", "description": "连续120次未抽到SSR/SP",
"reward": "周卡", "reward": "周卡",
"threshold": 120, "threshold": 120,
"type": "no_ssr_streak" "type": "no_ssr_streak"
}, },
"no_ssr_180": { "no_ssr_180": {
"name": "月见黑", "name": "月见黑",
"description": "连续180次未抽到SSR/SP", "description": "连续180次未抽到SSR/SP",
"reward": "月卡", "reward": "月卡",
"threshold": 180, "threshold": 180,
"type": "no_ssr_streak" "type": "no_ssr_streak"
} }
} }
# 权限配置 # 权限配置
ALLOWED_GROUP_ID: int = 621016172 ALLOWED_GROUP_ID: int = 621016172
ALLOWED_USER_ID: int = 1424473282 ALLOWED_USER_ID: int = 1424473282
# 特殊概率用户配置 # 特殊概率用户配置
SPECIAL_PROBABILITY_USERS: list = [] # 100%抽到SSR或SP的用户列表 SPECIAL_PROBABILITY_USERS: list = [] # 100%抽到SSR或SP的用户列表
# Web后台管理配置 # Web后台管理配置
WEB_ADMIN_TOKEN: str = os.getenv("WEB_ADMIN_TOKEN", "onmyoji_admin_token_2024") WEB_ADMIN_TOKEN: str = os.getenv("WEB_ADMIN_TOKEN", "onmyoji_admin_token_2024")
WEB_ADMIN_PORT: int = int(os.getenv("WEB_ADMIN_PORT", "8080")) WEB_ADMIN_PORT: int = int(os.getenv("WEB_ADMIN_PORT", "8080"))
# 时区 # 蛋定服务器对接配置
DD_API_HOST: str = "https://api.danding.vip/DD/"
BOT_TOKEN: str = os.getenv("ONMYOJI_BOT_TOKEN", os.getenv("BOT_TOKEN", "")) # 必须设置
BOT_USER_ID: str = "1424473282"
# 时区
TIMEZONE: str = "Asia/Shanghai" TIMEZONE: str = "Asia/Shanghai"