协议
This commit is contained in:
266
telegram_bot.py
266
telegram_bot.py
@@ -2862,7 +2862,7 @@ class ProvisionerBot:
|
||||
|
||||
async def _run_team_registration(self, chat_id: int, count: int, output_type: str):
|
||||
"""执行 GPT Team 注册任务"""
|
||||
from auto_gpt_team import run_single_registration, cleanup_chrome_processes
|
||||
from auto_gpt_team import run_single_registration_auto, cleanup_chrome_processes, get_register_mode
|
||||
import json
|
||||
import threading
|
||||
|
||||
@@ -2870,6 +2870,10 @@ class ProvisionerBot:
|
||||
success_count = 0
|
||||
fail_count = 0
|
||||
|
||||
# 获取当前注册模式
|
||||
current_mode = get_register_mode()
|
||||
mode_display = "🌐 协议模式" if current_mode == "api" else "🖥️ 浏览器模式"
|
||||
|
||||
# 当前步骤 (用于显示)
|
||||
current_step = ["初始化..."]
|
||||
current_account = [""]
|
||||
@@ -2884,6 +2888,7 @@ class ProvisionerBot:
|
||||
progress_msg = await self.app.bot.send_message(
|
||||
chat_id,
|
||||
f"<b>🚀 开始注册</b>\n\n"
|
||||
f"模式: {mode_display}\n"
|
||||
f"进度: 0/{count}\n"
|
||||
f"{'▱' * 20}",
|
||||
parse_mode="HTML"
|
||||
@@ -2908,6 +2913,7 @@ class ProvisionerBot:
|
||||
|
||||
text = (
|
||||
f"<b>🚀 注册中...</b>\n\n"
|
||||
f"模式: {mode_display}\n"
|
||||
f"进度: {success_count + fail_count}/{count}\n"
|
||||
f"{progress_bar}\n\n"
|
||||
f"✅ 成功: {success_count}\n"
|
||||
@@ -2947,7 +2953,7 @@ class ProvisionerBot:
|
||||
import functools
|
||||
|
||||
def run_with_callback():
|
||||
return run_single_registration(
|
||||
return run_single_registration_auto(
|
||||
progress_callback=None,
|
||||
step_callback=step_callback
|
||||
)
|
||||
@@ -3094,7 +3100,16 @@ class ProvisionerBot:
|
||||
|
||||
def _get_autogptplus_main_keyboard(self):
|
||||
"""获取 AutoGPTPlus 主菜单键盘"""
|
||||
return InlineKeyboardMarkup([
|
||||
# 检查协议模式是否可用
|
||||
try:
|
||||
from auto_gpt_team import is_api_mode_supported, get_register_mode
|
||||
api_supported = is_api_mode_supported()
|
||||
current_mode = get_register_mode()
|
||||
except ImportError:
|
||||
api_supported = False
|
||||
current_mode = "browser"
|
||||
|
||||
keyboard = [
|
||||
[
|
||||
InlineKeyboardButton("📋 查看配置", callback_data="autogptplus:config"),
|
||||
InlineKeyboardButton("🔑 设置 Token", callback_data="autogptplus:set_token"),
|
||||
@@ -3111,10 +3126,20 @@ class ProvisionerBot:
|
||||
InlineKeyboardButton("📧 测试邮件", callback_data="autogptplus:test_email"),
|
||||
InlineKeyboardButton("🔄 测试 API", callback_data="autogptplus:test_api"),
|
||||
],
|
||||
[
|
||||
InlineKeyboardButton("🚀 开始注册", callback_data="autogptplus:register"),
|
||||
],
|
||||
]
|
||||
|
||||
# 添加注册模式选择按钮
|
||||
mode_icon = "🌐" if current_mode == "api" else "🖥️"
|
||||
mode_text = "协议模式" if current_mode == "api" else "浏览器模式"
|
||||
keyboard.append([
|
||||
InlineKeyboardButton(f"⚙️ 注册模式: {mode_icon} {mode_text}", callback_data="autogptplus:select_mode"),
|
||||
])
|
||||
|
||||
keyboard.append([
|
||||
InlineKeyboardButton("🚀 开始注册", callback_data="autogptplus:register"),
|
||||
])
|
||||
|
||||
return InlineKeyboardMarkup(keyboard)
|
||||
|
||||
async def callback_autogptplus(self, update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||
"""处理 AutoGPTPlus 回调"""
|
||||
@@ -3148,6 +3173,11 @@ class ProvisionerBot:
|
||||
await self._toggle_autogptplus_fingerprint(query)
|
||||
elif action == "stats":
|
||||
await self._show_autogptplus_stats(query)
|
||||
|
||||
elif action == "select_mode":
|
||||
await self._show_autogptplus_mode_selection(query)
|
||||
elif action == "set_mode":
|
||||
await self._set_autogptplus_mode(query, sub_action)
|
||||
elif action == "register":
|
||||
await self._start_autogptplus_register(query, context)
|
||||
elif action == "back":
|
||||
@@ -3203,7 +3233,8 @@ class ProvisionerBot:
|
||||
try:
|
||||
from auto_gpt_team import (
|
||||
MAIL_API_TOKEN, MAIL_API_BASE, EMAIL_DOMAINS,
|
||||
SEPA_IBANS, RANDOM_FINGERPRINT, get_email_domains, get_sepa_ibans
|
||||
SEPA_IBANS, RANDOM_FINGERPRINT, get_email_domains, get_sepa_ibans,
|
||||
REGISTER_MODE, API_PROXY, is_api_mode_supported
|
||||
)
|
||||
|
||||
# 脱敏显示 Token
|
||||
@@ -3226,6 +3257,19 @@ class ProvisionerBot:
|
||||
# 随机指纹状态
|
||||
fingerprint_status = "✅ 已开启" if RANDOM_FINGERPRINT else "❌ 已关闭"
|
||||
|
||||
# 注册模式
|
||||
api_supported = is_api_mode_supported()
|
||||
if REGISTER_MODE == "api":
|
||||
mode_display = "🌐 协议模式 (API)"
|
||||
else:
|
||||
mode_display = "🖥️ 浏览器模式"
|
||||
|
||||
if not api_supported:
|
||||
mode_display += " (协议模式不可用)"
|
||||
|
||||
# 代理配置
|
||||
proxy_display = API_PROXY if API_PROXY else "未配置"
|
||||
|
||||
lines = [
|
||||
"<b>📋 AutoGPTPlus 配置</b>",
|
||||
"",
|
||||
@@ -3240,8 +3284,10 @@ class ProvisionerBot:
|
||||
"<b>💳 SEPA IBAN</b>",
|
||||
f" 数量: {len(ibans)} 个",
|
||||
"",
|
||||
"<b>🎭 随机指纹</b>",
|
||||
f" 状态: {fingerprint_status}",
|
||||
"<b>⚙️ 注册设置</b>",
|
||||
f" 模式: {mode_display}",
|
||||
f" 随机指纹: {fingerprint_status}",
|
||||
f" API 代理: {proxy_display}",
|
||||
]
|
||||
|
||||
# 配置状态检查
|
||||
@@ -3731,6 +3777,208 @@ class ProvisionerBot:
|
||||
reply_markup=reply_markup
|
||||
)
|
||||
|
||||
async def _show_autogptplus_mode_selection(self, query):
|
||||
"""显示注册模式选择界面"""
|
||||
try:
|
||||
from auto_gpt_team import is_api_mode_supported, get_register_mode
|
||||
|
||||
api_supported = is_api_mode_supported()
|
||||
current_mode = get_register_mode()
|
||||
|
||||
lines = [
|
||||
"<b>⚙️ 选择注册模式</b>\n",
|
||||
"请选择 ChatGPT Team 注册使用的方式:\n",
|
||||
]
|
||||
|
||||
# 浏览器模式说明
|
||||
browser_check = "✅" if current_mode == "browser" else "⬜"
|
||||
lines.append(f"<b>{browser_check} 🖥️ 浏览器模式</b>")
|
||||
lines.append("全程使用 DrissionPage 浏览器自动化")
|
||||
lines.append("• 兼容性好,无需额外依赖")
|
||||
lines.append("• 速度较慢,资源占用较高")
|
||||
lines.append("")
|
||||
|
||||
# 协议模式说明
|
||||
api_check = "✅" if current_mode == "api" else "⬜"
|
||||
api_status = "" if api_supported else " (不可用)"
|
||||
lines.append(f"<b>{api_check} 🌐 协议模式{api_status}</b>")
|
||||
lines.append("使用 API 快速注册,仅支付环节用浏览器")
|
||||
lines.append("• 速度快,资源占用少")
|
||||
lines.append("• 需要 curl_cffi 依赖")
|
||||
if not api_supported:
|
||||
lines.append("• <i>请安装: pip install curl_cffi</i>")
|
||||
|
||||
# 构建按钮
|
||||
keyboard = []
|
||||
|
||||
# 浏览器模式按钮
|
||||
browser_icon = "✅" if current_mode == "browser" else "🖥️"
|
||||
keyboard.append([
|
||||
InlineKeyboardButton(
|
||||
f"{browser_icon} 浏览器模式",
|
||||
callback_data="autogptplus:set_mode:browser"
|
||||
)
|
||||
])
|
||||
|
||||
# 协议模式按钮
|
||||
if api_supported:
|
||||
api_icon = "✅" if current_mode == "api" else "🌐"
|
||||
keyboard.append([
|
||||
InlineKeyboardButton(
|
||||
f"{api_icon} 协议模式 (推荐)",
|
||||
callback_data="autogptplus:set_mode:api"
|
||||
)
|
||||
])
|
||||
else:
|
||||
keyboard.append([
|
||||
InlineKeyboardButton(
|
||||
"🌐 协议模式 (需安装依赖)",
|
||||
callback_data="autogptplus:set_mode:api_unavailable"
|
||||
)
|
||||
])
|
||||
|
||||
keyboard.append([
|
||||
InlineKeyboardButton("◀️ 返回", callback_data="autogptplus:back")
|
||||
])
|
||||
|
||||
reply_markup = InlineKeyboardMarkup(keyboard)
|
||||
|
||||
await query.edit_message_text(
|
||||
"\n".join(lines),
|
||||
parse_mode="HTML",
|
||||
reply_markup=reply_markup
|
||||
)
|
||||
|
||||
except ImportError as e:
|
||||
keyboard = [[InlineKeyboardButton("◀️ 返回", callback_data="autogptplus:back")]]
|
||||
reply_markup = InlineKeyboardMarkup(keyboard)
|
||||
await query.edit_message_text(
|
||||
f"<b>❌ 模块导入失败</b>\n\n{e}",
|
||||
parse_mode="HTML",
|
||||
reply_markup=reply_markup
|
||||
)
|
||||
except Exception as e:
|
||||
keyboard = [[InlineKeyboardButton("◀️ 返回", callback_data="autogptplus:back")]]
|
||||
reply_markup = InlineKeyboardMarkup(keyboard)
|
||||
await query.edit_message_text(
|
||||
f"<b>❌ 获取配置失败</b>\n\n{e}",
|
||||
parse_mode="HTML",
|
||||
reply_markup=reply_markup
|
||||
)
|
||||
|
||||
async def _set_autogptplus_mode(self, query, mode: str):
|
||||
"""设置注册模式"""
|
||||
import tomli_w
|
||||
|
||||
try:
|
||||
from auto_gpt_team import is_api_mode_supported, get_register_mode, set_register_mode
|
||||
|
||||
# 处理协议模式不可用的情况
|
||||
if mode == "api_unavailable":
|
||||
keyboard = [[InlineKeyboardButton("◀️ 返回", callback_data="autogptplus:select_mode")]]
|
||||
reply_markup = InlineKeyboardMarkup(keyboard)
|
||||
await query.edit_message_text(
|
||||
"<b>❌ 协议模式不可用</b>\n\n"
|
||||
"需要安装 curl_cffi 依赖:\n"
|
||||
"<code>pip install curl_cffi</code>\n\n"
|
||||
"安装后重启程序即可使用协议模式",
|
||||
parse_mode="HTML",
|
||||
reply_markup=reply_markup
|
||||
)
|
||||
return
|
||||
|
||||
# 检查是否已经是当前模式
|
||||
current_mode = get_register_mode()
|
||||
if mode == current_mode:
|
||||
await query.answer(f"当前已是{'协议' if mode == 'api' else '浏览器'}模式", show_alert=False)
|
||||
return
|
||||
|
||||
# 检查协议模式是否可用
|
||||
if mode == "api" and not is_api_mode_supported():
|
||||
keyboard = [[InlineKeyboardButton("◀️ 返回", callback_data="autogptplus:select_mode")]]
|
||||
reply_markup = InlineKeyboardMarkup(keyboard)
|
||||
await query.edit_message_text(
|
||||
"<b>❌ 协议模式不可用</b>\n\n"
|
||||
"需要安装 curl_cffi 依赖:\n"
|
||||
"<code>pip install curl_cffi</code>\n\n"
|
||||
"安装后重启程序即可使用协议模式",
|
||||
parse_mode="HTML",
|
||||
reply_markup=reply_markup
|
||||
)
|
||||
return
|
||||
|
||||
# 读取当前配置
|
||||
with open(CONFIG_FILE, "rb") as f:
|
||||
import tomllib
|
||||
config = tomllib.load(f)
|
||||
|
||||
# 确保 autogptplus section 存在
|
||||
if "autogptplus" not in config:
|
||||
config["autogptplus"] = {}
|
||||
|
||||
# 更新配置
|
||||
config["autogptplus"]["register_mode"] = mode
|
||||
|
||||
# 写回文件
|
||||
with open(CONFIG_FILE, "wb") as f:
|
||||
tomli_w.dump(config, f)
|
||||
|
||||
# 更新运行时配置
|
||||
set_register_mode(mode)
|
||||
|
||||
# 重新加载模块
|
||||
import importlib
|
||||
import auto_gpt_team
|
||||
importlib.reload(auto_gpt_team)
|
||||
|
||||
# 显示成功消息
|
||||
if mode == "api":
|
||||
mode_name = "🌐 协议模式"
|
||||
mode_desc = (
|
||||
"使用 API 快速完成注册流程,仅支付环节使用浏览器\n\n"
|
||||
"<b>特点:</b>\n"
|
||||
"• 注册速度更快\n"
|
||||
"• 资源占用更少\n"
|
||||
"• 更稳定可靠"
|
||||
)
|
||||
else:
|
||||
mode_name = "🖥️ 浏览器模式"
|
||||
mode_desc = (
|
||||
"全程使用 DrissionPage 浏览器自动化\n\n"
|
||||
"<b>特点:</b>\n"
|
||||
"• 兼容性更好\n"
|
||||
"• 无需额外依赖\n"
|
||||
"• 可视化调试方便"
|
||||
)
|
||||
|
||||
keyboard = [[InlineKeyboardButton("◀️ 返回主菜单", callback_data="autogptplus:back")]]
|
||||
reply_markup = InlineKeyboardMarkup(keyboard)
|
||||
|
||||
await query.edit_message_text(
|
||||
f"<b>✅ 注册模式已设置</b>\n\n"
|
||||
f"当前模式: {mode_name}\n\n"
|
||||
f"{mode_desc}",
|
||||
parse_mode="HTML",
|
||||
reply_markup=reply_markup
|
||||
)
|
||||
|
||||
except ImportError as e:
|
||||
keyboard = [[InlineKeyboardButton("◀️ 返回", callback_data="autogptplus:back")]]
|
||||
reply_markup = InlineKeyboardMarkup(keyboard)
|
||||
await query.edit_message_text(
|
||||
f"<b>❌ 模块导入失败</b>\n\n{e}",
|
||||
parse_mode="HTML",
|
||||
reply_markup=reply_markup
|
||||
)
|
||||
except Exception as e:
|
||||
keyboard = [[InlineKeyboardButton("◀️ 返回", callback_data="autogptplus:back")]]
|
||||
reply_markup = InlineKeyboardMarkup(keyboard)
|
||||
await query.edit_message_text(
|
||||
f"<b>❌ 设置失败</b>\n\n{e}",
|
||||
parse_mode="HTML",
|
||||
reply_markup=reply_markup
|
||||
)
|
||||
|
||||
async def _show_autogptplus_stats(self, query):
|
||||
"""显示统计信息"""
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user