refactor(config, telegram_bot): Simplify GPTMail API key configuration and remove redundant Telegram enabled flag
- Simplify GPTMail API key initialization logic by removing separate api_key and api_keys variables and consolidating into single line with fallback to ["gpt-test"] - Update config.toml.example to use api_keys list format instead of deprecated api_key single value - Remove TELEGRAM_ENABLED configuration variable and related check from telegram_bot.py - Simplify Telegram Bot startup validation to only check for bot_token and admin_chat_ids - Update default auth_provider from "cpa" to "s2a" in config.toml.example - Improve documentation comments in config.toml.example for GPTMail domains and CRS service - Localize error messages in telegram_bot.py to Chinese for consistency - Streamline configuration by removing unnecessary intermediate variables and checks
This commit is contained in:
12
config.py
12
config.py
@@ -265,9 +265,7 @@ def reload_config() -> dict:
|
|||||||
_gptmail = _cfg.get("gptmail", {})
|
_gptmail = _cfg.get("gptmail", {})
|
||||||
GPTMAIL_PREFIX = _gptmail.get("prefix", "")
|
GPTMAIL_PREFIX = _gptmail.get("prefix", "")
|
||||||
GPTMAIL_DOMAINS = _gptmail.get("domains", [])
|
GPTMAIL_DOMAINS = _gptmail.get("domains", [])
|
||||||
_gptmail_api_key = _gptmail.get("api_key", "")
|
GPTMAIL_API_KEYS = _gptmail.get("api_keys", []) or ["gpt-test"]
|
||||||
_gptmail_api_keys = _gptmail.get("api_keys", [])
|
|
||||||
GPTMAIL_API_KEYS = _gptmail_api_keys if _gptmail_api_keys else ([_gptmail_api_key] if _gptmail_api_key else ["gpt-test"])
|
|
||||||
|
|
||||||
# 代理配置
|
# 代理配置
|
||||||
_proxy_enabled_top = _cfg.get("proxy_enabled")
|
_proxy_enabled_top = _cfg.get("proxy_enabled")
|
||||||
@@ -333,11 +331,8 @@ GPTMAIL_API_BASE = _gptmail.get("api_base", "https://mail.chatgpt.org.uk")
|
|||||||
GPTMAIL_PREFIX = _gptmail.get("prefix", "")
|
GPTMAIL_PREFIX = _gptmail.get("prefix", "")
|
||||||
GPTMAIL_DOMAINS = _gptmail.get("domains", [])
|
GPTMAIL_DOMAINS = _gptmail.get("domains", [])
|
||||||
|
|
||||||
# GPTMail API Keys 支持多个 Key 轮询
|
# GPTMail API Keys (支持多个 Key 轮询)
|
||||||
# 兼容旧配置: api_key (单个) 和新配置: api_keys (列表)
|
GPTMAIL_API_KEYS = _gptmail.get("api_keys", []) or ["gpt-test"]
|
||||||
_gptmail_api_key = _gptmail.get("api_key", "")
|
|
||||||
_gptmail_api_keys = _gptmail.get("api_keys", [])
|
|
||||||
GPTMAIL_API_KEYS = _gptmail_api_keys if _gptmail_api_keys else ([_gptmail_api_key] if _gptmail_api_key else ["gpt-test"])
|
|
||||||
|
|
||||||
# GPTMail Keys 文件 (用于动态管理)
|
# GPTMail Keys 文件 (用于动态管理)
|
||||||
GPTMAIL_KEYS_FILE = BASE_DIR / "gptmail_keys.json"
|
GPTMAIL_KEYS_FILE = BASE_DIR / "gptmail_keys.json"
|
||||||
@@ -554,7 +549,6 @@ TEAM_TRACKER_FILE = _files.get("tracker_file", str(BASE_DIR / "team_tracker.json
|
|||||||
|
|
||||||
# Telegram Bot 配置
|
# Telegram Bot 配置
|
||||||
_telegram = _cfg.get("telegram", {})
|
_telegram = _cfg.get("telegram", {})
|
||||||
TELEGRAM_ENABLED = _telegram.get("enabled", False)
|
|
||||||
TELEGRAM_BOT_TOKEN = _telegram.get("bot_token", "")
|
TELEGRAM_BOT_TOKEN = _telegram.get("bot_token", "")
|
||||||
TELEGRAM_ADMIN_CHAT_IDS = _telegram.get("admin_chat_ids", [])
|
TELEGRAM_ADMIN_CHAT_IDS = _telegram.get("admin_chat_ids", [])
|
||||||
TELEGRAM_NOTIFY_ON_COMPLETE = _telegram.get("notify_on_complete", True)
|
TELEGRAM_NOTIFY_ON_COMPLETE = _telegram.get("notify_on_complete", True)
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ email_provider = "gptmail"
|
|||||||
# 选择使用的授权服务: "crs" / "cpa" / "s2a"
|
# 选择使用的授权服务: "crs" / "cpa" / "s2a"
|
||||||
# - crs: 原有 CRS 系统,需手动添加账号到 CRS
|
# - crs: 原有 CRS 系统,需手动添加账号到 CRS
|
||||||
# - cpa: CPA (Codex/Copilot Authorization) 系统,后台自动处理账号
|
# - cpa: CPA (Codex/Copilot Authorization) 系统,后台自动处理账号
|
||||||
# - s2a: Sub2API 系统,支持 OAuth 授权和账号入库
|
# - s2a: Sub2API 系统,支持 OAuth 授权和账号入库 (推荐)
|
||||||
auth_provider = "cpa"
|
auth_provider = "s2a"
|
||||||
|
|
||||||
# 是否将 team.json 中的 Team Owner 也添加到授权服务
|
# 是否将 team.json 中的 Team Owner 也添加到授权服务
|
||||||
# 开启后,运行时会自动将 team.json 中的 Owner 账号也进行授权入库
|
# 开启后,运行时会自动将 team.json 中的 Owner 账号也进行授权入库
|
||||||
@@ -67,20 +67,14 @@ web_url = "https://your-email-service.com"
|
|||||||
# API 接口地址
|
# API 接口地址
|
||||||
api_base = "https://mail.chatgpt.org.uk"
|
api_base = "https://mail.chatgpt.org.uk"
|
||||||
|
|
||||||
# API 密钥配置 (支持两种方式)
|
# API 密钥列表 (支持多个 Key 轮询,可分散请求限制)
|
||||||
# 方式1: 单个 Key (兼容旧配置)
|
# 也可以通过 Telegram Bot 的 /gptmail_add 命令动态添加 Key
|
||||||
api_key = "gpt-test"
|
api_keys = ["gpt-test"]
|
||||||
|
|
||||||
# 方式2: 多个 Key 轮询 (推荐,可分散请求限制)
|
|
||||||
# api_keys = ["key1", "key2", "key3"]
|
|
||||||
|
|
||||||
# 注意: 也可以通过 Telegram Bot 的 /gptmail_add 命令动态添加 Key
|
|
||||||
|
|
||||||
# 邮箱前缀 (留空则自动生成 {8位随机字符}-oaiteam 格式)
|
# 邮箱前缀 (留空则自动生成 {8位随机字符}-oaiteam 格式)
|
||||||
prefix = ""
|
prefix = ""
|
||||||
# 可用域名列表,生成邮箱时随机选择
|
# 可用域名列表,生成邮箱时随机选择
|
||||||
# 这些域名已配置 MX 记录指向 GPTMail 服务器
|
# 这些域名已配置 MX 记录指向 GPTMail 服务器
|
||||||
# 下面域名是可用的
|
|
||||||
domains = [
|
domains = [
|
||||||
"29thnewport.org.uk", "2ndwhartonscoutgroup.org.uk",
|
"29thnewport.org.uk", "2ndwhartonscoutgroup.org.uk",
|
||||||
"abrahampath.org.uk", "aiccministry.com",
|
"abrahampath.org.uk", "aiccministry.com",
|
||||||
@@ -120,6 +114,7 @@ domains = [
|
|||||||
|
|
||||||
# ==================== CRS 服务配置 ====================
|
# ==================== CRS 服务配置 ====================
|
||||||
# CRS (Central Registration Service) 用于管理注册账号的中心服务
|
# CRS (Central Registration Service) 用于管理注册账号的中心服务
|
||||||
|
# 仅当 auth_provider = "crs" 时生效
|
||||||
[crs]
|
[crs]
|
||||||
# CRS API 接口地址
|
# CRS API 接口地址
|
||||||
api_base = "https://your-crs-service.com"
|
api_base = "https://your-crs-service.com"
|
||||||
@@ -213,8 +208,6 @@ tracker_file = "team_tracker.json"
|
|||||||
# ==================== Telegram Bot 配置 ====================
|
# ==================== Telegram Bot 配置 ====================
|
||||||
# 通过 Telegram Bot 远程控制和监控任务
|
# 通过 Telegram Bot 远程控制和监控任务
|
||||||
[telegram]
|
[telegram]
|
||||||
# 是否启用 Telegram Bot
|
|
||||||
enabled = false
|
|
||||||
# Bot Token (通过 @BotFather 创建获取)
|
# Bot Token (通过 @BotFather 创建获取)
|
||||||
bot_token = "your-bot-token"
|
bot_token = "your-bot-token"
|
||||||
# 授权管理员的 Chat ID 列表 (通过 @userinfobot 获取)
|
# 授权管理员的 Chat ID 列表 (通过 @userinfobot 获取)
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ from telegram.ext import (
|
|||||||
from config import (
|
from config import (
|
||||||
TELEGRAM_BOT_TOKEN,
|
TELEGRAM_BOT_TOKEN,
|
||||||
TELEGRAM_ADMIN_CHAT_IDS,
|
TELEGRAM_ADMIN_CHAT_IDS,
|
||||||
TELEGRAM_ENABLED,
|
|
||||||
TEAMS,
|
TEAMS,
|
||||||
AUTH_PROVIDER,
|
AUTH_PROVIDER,
|
||||||
TEAM_JSON_FILE,
|
TEAM_JSON_FILE,
|
||||||
@@ -1332,16 +1331,12 @@ class ProvisionerBot:
|
|||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
"""主函数"""
|
"""主函数"""
|
||||||
if not TELEGRAM_ENABLED:
|
|
||||||
print("Telegram Bot is disabled. Set telegram.enabled = true in config.toml")
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
if not TELEGRAM_BOT_TOKEN:
|
if not TELEGRAM_BOT_TOKEN:
|
||||||
print("Telegram Bot Token not configured. Set telegram.bot_token in config.toml")
|
print("Telegram Bot Token 未配置,请在 config.toml 中设置 telegram.bot_token")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if not TELEGRAM_ADMIN_CHAT_IDS:
|
if not TELEGRAM_ADMIN_CHAT_IDS:
|
||||||
print("No admin chat IDs configured. Set telegram.admin_chat_ids in config.toml")
|
print("管理员 Chat ID 未配置,请在 config.toml 中设置 telegram.admin_chat_ids")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
bot = ProvisionerBot()
|
bot = ProvisionerBot()
|
||||||
@@ -1349,7 +1344,7 @@ async def main():
|
|||||||
# 处理 Ctrl+C
|
# 处理 Ctrl+C
|
||||||
import signal
|
import signal
|
||||||
def signal_handler(sig, frame):
|
def signal_handler(sig, frame):
|
||||||
log.info("Shutting down...")
|
log.info("正在关闭...")
|
||||||
bot.request_shutdown()
|
bot.request_shutdown()
|
||||||
|
|
||||||
signal.signal(signal.SIGINT, signal_handler)
|
signal.signal(signal.SIGINT, signal_handler)
|
||||||
|
|||||||
Reference in New Issue
Block a user