diff --git a/telegram_bot.py b/telegram_bot.py
index 9eda085..371de01 100644
--- a/telegram_bot.py
+++ b/telegram_bot.py
@@ -160,6 +160,7 @@ class ProvisionerBot:
("clean_teams", self.cmd_clean_teams),
("keys_usage", self.cmd_keys_usage),
("autogptplus", self.cmd_autogptplus),
+ ("update_token", self.cmd_update_token),
]
for cmd, handler in handlers:
self.app.add_handler(CommandHandler(cmd, handler))
@@ -292,6 +293,7 @@ class ProvisionerBot:
BotCommand("team_register", "GPT Team 自动注册"),
# AutoGPTPlus
BotCommand("autogptplus", "AutoGPTPlus 管理面板"),
+ BotCommand("update_token", "更新邮件 API Token"),
]
try:
await self.app.bot.set_my_commands(commands)
@@ -367,6 +369,7 @@ class ProvisionerBot:
🔧 AutoGPTPlus:
/autogptplus - ChatGPT 订阅自动化管理面板
+/update_token <token> - 更新邮件 API Token
💡 示例:
/list - 查看所有待处理账号
@@ -3643,6 +3646,68 @@ class ProvisionerBot:
self.current_task = None
self.current_team = None
+ @admin_only
+ async def cmd_update_token(self, update: Update, context: ContextTypes.DEFAULT_TYPE):
+ """更新 config.toml 中的邮件 API Token"""
+ if not context.args:
+ await update.message.reply_text(
+ "📝 更新邮件 API Token\n\n"
+ "用法: /update_token <new_token>\n\n"
+ "此命令会更新 config.toml 中的:\n"
+ "• [autogptplus] mail_api_token",
+ parse_mode="HTML"
+ )
+ return
+
+ new_token = context.args[0].strip()
+ if not new_token:
+ await update.message.reply_text("❌ Token 不能为空")
+ return
+
+ try:
+ import tomllib
+ import tomli_w
+
+ # 读取当前配置
+ with open(CONFIG_FILE, "rb") as f:
+ config = tomllib.load(f)
+
+ # 确保 autogptplus section 存在
+ if "autogptplus" not in config:
+ config["autogptplus"] = {}
+
+ # 获取旧 token (用于显示)
+ old_token = config["autogptplus"].get("mail_api_token", "")
+ old_display = f"{old_token[:8]}...{old_token[-4:]}" if len(old_token) > 12 else old_token or "(空)"
+
+ # 更新 token
+ config["autogptplus"]["mail_api_token"] = new_token
+
+ # 写回文件
+ with open(CONFIG_FILE, "wb") as f:
+ tomli_w.dump(config, f)
+
+ # 重载配置
+ reload_config()
+
+ new_display = f"{new_token[:8]}...{new_token[-4:]}" if len(new_token) > 12 else new_token
+
+ await update.message.reply_text(
+ f"✅ Token 更新成功\n\n"
+ f"旧 Token: {old_display}\n"
+ f"新 Token: {new_display}\n\n"
+ f"配置已自动重载生效",
+ parse_mode="HTML"
+ )
+
+ except ImportError:
+ await update.message.reply_text(
+ "❌ 缺少 tomli_w 依赖\n"
+ "请运行: uv add tomli_w"
+ )
+ except Exception as e:
+ await update.message.reply_text(f"❌ 更新 Token 失败: {e}")
+
@admin_only
async def cmd_autogptplus(self, update: Update, context: ContextTypes.DEFAULT_TYPE):
"""AutoGPTPlus 配置管理 - 交互式菜单"""