33
This commit is contained in:
163
telegram_bot.py
163
telegram_bot.py
@@ -25,6 +25,15 @@ from config import (
|
||||
TEAM_JSON_FILE,
|
||||
TELEGRAM_CHECK_INTERVAL,
|
||||
TELEGRAM_LOW_STOCK_THRESHOLD,
|
||||
CONFIG_FILE,
|
||||
EMAIL_PROVIDER,
|
||||
BROWSER_HEADLESS,
|
||||
ACCOUNTS_PER_TEAM,
|
||||
PROXY_ENABLED,
|
||||
PROXIES,
|
||||
S2A_API_BASE,
|
||||
CPA_API_BASE,
|
||||
CRS_API_BASE,
|
||||
)
|
||||
from utils import load_team_tracker
|
||||
from bot_notifier import BotNotifier, set_notifier, progress_finish
|
||||
@@ -74,6 +83,9 @@ class ProvisionerBot:
|
||||
("help", self.cmd_help),
|
||||
("status", self.cmd_status),
|
||||
("team", self.cmd_team),
|
||||
("list", self.cmd_list),
|
||||
("config", self.cmd_config),
|
||||
("headless", self.cmd_headless),
|
||||
("run", self.cmd_run),
|
||||
("run_all", self.cmd_run_all),
|
||||
("stop", self.cmd_stop),
|
||||
@@ -133,27 +145,33 @@ class ProvisionerBot:
|
||||
"""显示帮助信息"""
|
||||
help_text = """<b>🤖 OpenAI Team 批量注册 Bot</b>
|
||||
|
||||
<b>📋 命令列表:</b>
|
||||
/status - 查看所有 Team 状态
|
||||
/team <n> - 查看第 n 个 Team 详情
|
||||
<b>📋 查看信息:</b>
|
||||
/list - 查看 team.json 账号列表
|
||||
/status - 查看任务处理状态
|
||||
/team <n> - 查看第 n 个 Team 处理详情
|
||||
/config - 查看系统配置
|
||||
/logs [n] - 查看最近 n 条日志
|
||||
|
||||
<b>🚀 任务控制:</b>
|
||||
/run <n> - 开始处理第 n 个 Team
|
||||
/run_all - 开始处理所有 Team
|
||||
/stop - 停止当前任务
|
||||
/logs [n] - 查看最近 n 条日志 (默认 10)
|
||||
|
||||
<b>⚙️ 配置管理:</b>
|
||||
/headless - 开启/关闭无头模式
|
||||
|
||||
<b>📊 S2A 专属:</b>
|
||||
/dashboard - 查看 S2A 仪表盘
|
||||
/stock - 查看账号库存
|
||||
/import - 导入账号到 team.json
|
||||
/help - 显示此帮助
|
||||
|
||||
<b>📤 上传账号:</b>
|
||||
直接发送 JSON 文件,或使用 /import 加 JSON 数据:
|
||||
<code>[{"account":"邮箱","password":"密码","token":"jwt"},...]</code>
|
||||
上传后使用 /run 开始处理
|
||||
<b>📤 导入账号:</b>
|
||||
/import - 导入账号到 team.json
|
||||
或直接发送 JSON 文件
|
||||
|
||||
<b>💡 示例:</b>
|
||||
<code>/list</code> - 查看所有待处理账号
|
||||
<code>/run 0</code> - 处理第一个 Team
|
||||
<code>/team 1</code> - 查看第二个 Team 状态
|
||||
<code>/logs 20</code> - 查看最近 20 条日志"""
|
||||
<code>/config</code> - 查看当前配置"""
|
||||
await update.message.reply_text(help_text, parse_mode="HTML")
|
||||
|
||||
@admin_only
|
||||
@@ -227,6 +245,127 @@ class ProvisionerBot:
|
||||
|
||||
await update.message.reply_text("\n".join(lines), parse_mode="HTML")
|
||||
|
||||
@admin_only
|
||||
async def cmd_list(self, update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||
"""查看 team.json 中的账号列表"""
|
||||
if not TEAMS:
|
||||
await update.message.reply_text("📭 team.json 中没有账号")
|
||||
return
|
||||
|
||||
lines = [f"<b>📋 team.json 账号列表 (共 {len(TEAMS)} 个)</b>\n"]
|
||||
|
||||
for i, team in enumerate(TEAMS):
|
||||
email = team.get("owner_email", "")
|
||||
has_token = "🔑" if team.get("auth_token") else "🔒"
|
||||
authorized = "✅" if team.get("authorized") else ""
|
||||
needs_login = " [需登录]" if team.get("needs_login") else ""
|
||||
|
||||
lines.append(f"{i}. {has_token} {email}{authorized}{needs_login}")
|
||||
|
||||
# 统计
|
||||
with_token = sum(1 for t in TEAMS if t.get("auth_token"))
|
||||
authorized = sum(1 for t in TEAMS if t.get("authorized"))
|
||||
|
||||
lines.append(f"\n<b>📊 统计:</b>")
|
||||
lines.append(f"有 Token: {with_token}/{len(TEAMS)}")
|
||||
lines.append(f"已授权: {authorized}/{len(TEAMS)}")
|
||||
|
||||
# 消息太长时分段发送
|
||||
text = "\n".join(lines)
|
||||
if len(text) > 4000:
|
||||
# 分段
|
||||
for i in range(0, len(lines), 30):
|
||||
chunk = "\n".join(lines[i:i+30])
|
||||
await update.message.reply_text(chunk, parse_mode="HTML")
|
||||
else:
|
||||
await update.message.reply_text(text, parse_mode="HTML")
|
||||
|
||||
@admin_only
|
||||
async def cmd_config(self, update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||
"""查看当前系统配置"""
|
||||
# 授权服务地址
|
||||
if AUTH_PROVIDER == "s2a":
|
||||
auth_url = S2A_API_BASE or "未配置"
|
||||
elif AUTH_PROVIDER == "cpa":
|
||||
auth_url = CPA_API_BASE or "未配置"
|
||||
else:
|
||||
auth_url = CRS_API_BASE or "未配置"
|
||||
|
||||
# 代理信息
|
||||
if PROXY_ENABLED and PROXIES:
|
||||
proxy_info = f"已启用 ({len(PROXIES)} 个)"
|
||||
else:
|
||||
proxy_info = "未启用"
|
||||
|
||||
# 无头模式状态
|
||||
headless_status = "✅ 已开启" if BROWSER_HEADLESS else "❌ 未开启"
|
||||
|
||||
lines = [
|
||||
"<b>⚙️ 系统配置</b>",
|
||||
"",
|
||||
"<b>📧 邮箱服务</b>",
|
||||
f" 提供商: {EMAIL_PROVIDER}",
|
||||
"",
|
||||
"<b>🔐 授权服务</b>",
|
||||
f" 模式: {AUTH_PROVIDER.upper()}",
|
||||
f" 地址: {auth_url}",
|
||||
"",
|
||||
"<b>🌐 浏览器</b>",
|
||||
f" 无头模式: {headless_status}",
|
||||
"",
|
||||
"<b>👥 账号设置</b>",
|
||||
f" 每 Team 账号数: {ACCOUNTS_PER_TEAM}",
|
||||
f" team.json 账号: {len(TEAMS)}",
|
||||
"",
|
||||
"<b>🔗 代理</b>",
|
||||
f" 状态: {proxy_info}",
|
||||
"",
|
||||
"<b>💡 提示:</b>",
|
||||
"使用 /headless 开启/关闭无头模式",
|
||||
]
|
||||
|
||||
await update.message.reply_text("\n".join(lines), parse_mode="HTML")
|
||||
|
||||
@admin_only
|
||||
async def cmd_headless(self, update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||
"""切换无头模式"""
|
||||
import tomli_w
|
||||
|
||||
try:
|
||||
# 读取当前配置
|
||||
with open(CONFIG_FILE, "rb") as f:
|
||||
import tomllib
|
||||
config = tomllib.load(f)
|
||||
|
||||
# 获取当前状态
|
||||
current = config.get("browser", {}).get("headless", False)
|
||||
new_value = not current
|
||||
|
||||
# 更新配置
|
||||
if "browser" not in config:
|
||||
config["browser"] = {}
|
||||
config["browser"]["headless"] = new_value
|
||||
|
||||
# 写回文件
|
||||
with open(CONFIG_FILE, "wb") as f:
|
||||
tomli_w.dump(config, f)
|
||||
|
||||
status = "✅ 已开启" if new_value else "❌ 已关闭"
|
||||
await update.message.reply_text(
|
||||
f"<b>🌐 无头模式</b>\n\n"
|
||||
f"状态: {status}\n\n"
|
||||
f"⚠️ 需要重启 Bot 生效",
|
||||
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"❌ 修改配置失败: {e}")
|
||||
|
||||
@admin_only
|
||||
async def cmd_run(self, update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||
"""启动处理指定 Team"""
|
||||
|
||||
Reference in New Issue
Block a user