feat: Update Telegram bot implementation and its main execution script.

This commit is contained in:
2026-01-18 06:39:10 +08:00
parent b75d12b5aa
commit 930cd203ee
2 changed files with 32 additions and 7 deletions

6
run.py
View File

@@ -344,14 +344,20 @@ def process_accounts(accounts: list, team_name: str, team_index: int = 0,
# 已授权但未入库的状态 (直接尝试入库,不重新授权) # 已授权但未入库的状态 (直接尝试入库,不重新授权)
# - authorized: 授权成功但入库失败 # - authorized: 授权成功但入库失败
# - partial: 部分完成 # - partial: 部分完成
# 注意: S2A 模式下 partial 状态需要重新授权,因为入库是授权过程的一部分
if AUTH_PROVIDER == "s2a":
need_crs_only = account_status == "authorized" # S2A: partial 需要重新授权
else:
need_crs_only = account_status in ["authorized", "partial"] need_crs_only = account_status in ["authorized", "partial"]
# 已注册但未授权的状态 (使用密码登录授权) # 已注册但未授权的状态 (使用密码登录授权)
# - registered: 已注册,需要授权 # - registered: 已注册,需要授权
# - auth_failed: 授权失败,重试 # - auth_failed: 授权失败,重试
# - partial (S2A模式): 入库验证失败,需要重新授权
# - 新格式 Owner (role=owner 且状态不是 team_owner/completed) 也走密码登录 # - 新格式 Owner (role=owner 且状态不是 team_owner/completed) 也走密码登录
need_auth_only = ( need_auth_only = (
account_status in ["registered", "auth_failed"] account_status in ["registered", "auth_failed"]
or (AUTH_PROVIDER == "s2a" and account_status == "partial") # S2A: partial 需要重新授权
or (account_role == "owner" and account_status not in ["team_owner", "completed", "authorized", "partial"]) or (account_role == "owner" and account_status not in ["team_owner", "completed", "authorized", "partial"])
) )

View File

@@ -709,6 +709,13 @@ class ProvisionerBot:
team_name = TEAMS[team_idx].get("name", f"Team{team_idx}") team_name = TEAMS[team_idx].get("name", f"Team{team_idx}")
self.current_team = team_name self.current_team = team_name
# 重置停止标志,确保新任务可以正常运行
try:
import run
run._shutdown_requested = False
except Exception:
pass
await update.message.reply_text(f"🚀 开始处理 Team {team_idx}: {team_name}...") await update.message.reply_text(f"🚀 开始处理 Team {team_idx}: {team_name}...")
# 在后台线程执行任务 # 在后台线程执行任务
@@ -732,6 +739,14 @@ class ProvisionerBot:
return return
self.current_team = "全部" self.current_team = "全部"
# 重置停止标志,确保新任务可以正常运行
try:
import run
run._shutdown_requested = False
except Exception:
pass
await update.message.reply_text(f"🚀 开始处理所有 Team (共 {len(TEAMS)} 个)...") await update.message.reply_text(f"🚀 开始处理所有 Team (共 {len(TEAMS)} 个)...")
loop = asyncio.get_event_loop() loop = asyncio.get_event_loop()
@@ -781,6 +796,13 @@ class ProvisionerBot:
# 启动任务 (run_all_teams 会自动处理未完成的账号) # 启动任务 (run_all_teams 会自动处理未完成的账号)
self.current_team = "继续处理" self.current_team = "继续处理"
# 重置停止标志,确保新任务可以正常运行
try:
import run
run._shutdown_requested = False
except Exception:
pass
loop = asyncio.get_event_loop() loop = asyncio.get_event_loop()
self.current_task = loop.run_in_executor( self.current_task = loop.run_in_executor(
self.executor, self.executor,
@@ -805,12 +827,9 @@ class ProvisionerBot:
self.current_team = None self.current_team = None
# 清理进度跟踪 # 清理进度跟踪
progress_finish() progress_finish()
# 重置停止标志,以便下次任务可以正常运行 # 注意: 不在这里重置 _shutdown_requested
try: # 让标志保持 True直到下次任务启动时再重置
import run # 这样可以确保线程池中的任务能够正确检测到停止信号
run._shutdown_requested = False
except Exception:
pass
def _run_team_task(self, team_idx: int): def _run_team_task(self, team_idx: int):
"""执行单个 Team 任务 (在线程池中运行)""" """执行单个 Team 任务 (在线程池中运行)"""