Command exited with code 0. Command output: --- /root/MayaXSenderbot/bridge.py.bak.20261105_055555 2026-11-05 05:55:55.214000017 +0000 +++ /root/MayaXSenderbot/bridge.py 2026-11-05 05:58:51.867248729 +0000 @@ -313,14 +313,8 @@ self.owner_phone = str(self.cfg.get("phone", "")).strip() self.logs_group_id = str(self.cfg.get("logs_group_id", "")).strip() - self.bot = Client( - "sam_bridge_bot", - api_id=self.api_id, - api_hash=self.api_hash, - bot_token=self.bot_token, - in_memory=True, - sleep_threshold=10, - ) + self.bot = None + self.bot_polling_task: Optional[asyncio.Task] = None self.http: Optional[aiohttp.ClientSession] = None self.workspaces: dict[str, Workspace] = {} @@ -483,76 +477,14 @@ return True return False - async def _restart_bot_client(self) -> None: - if self._bot_restarting: - return - self._bot_restarting = True - try: - log("[bot recovery] Bot client reconnect/restart triggered...") - old_bot = self.bot - if old_bot: - try: - await asyncio.wait_for(old_bot.stop(), timeout=4.0) - except Exception as exc: - log(f"[bot recovery] old_bot.stop() note: {exc}") - - await asyncio.sleep(1) - - success = False - for attempt in range(1, 4): - try: - new_bot = Client( - "sam_bridge_bot", - api_id=self.api_id, - api_hash=self.api_hash, - bot_token=self.bot_token, - in_memory=True, - sleep_threshold=10, - ) - new_bot.add_handler(MessageHandler(self._handle_bot_message)) - await asyncio.wait_for(new_bot.start(), timeout=12.0) - self.bot = new_bot - success = True - log(f"[bot recovery] Bot client restarted and listening successfully! (attempt {attempt})") - break - except Exception as exc: - log(f"[bot recovery] Attempt {attempt} failed: {exc}") - if attempt < 3: - await asyncio.sleep(2) - - if not success: - log("[bot recovery] Recovery attempts failed/timed out. Watchdog will retry on next cycle.") - except Exception as exc: - log(f"[bot recovery] Unexpected error in restart: {exc}") - finally: - self._bot_restarting = False - - async def _watchdog_loop(self) -> None: - while True: - try: - await asyncio.sleep(20) - # 1. Check bot client - if self.bot is not None: - is_connected = getattr(self.bot, "is_connected", False) - if not is_connected and not self._bot_restarting: - log("[watchdog] Bot client is disconnected! Triggering recovery...") - asyncio.create_task(self._restart_bot_client()) - - # 2. Check main client - if self.main_client_ready and self.main_client is not None: - if not getattr(self.main_client, "is_connected", False): - log("[watchdog] Main client is disconnected! Attempting reconnect...") - try: - await asyncio.wait_for(self.main_client.connect(), timeout=10.0) - log("[watchdog] Main client reconnected successfully!") - except Exception as e: - log(f"[watchdog] Main client reconnect failed: {e}") - except asyncio.CancelledError: - break - except Exception as exc: - log(f"[watchdog] Loop error: {exc}") + def _clean_keyboard_dict(self, obj: Any) -> Any: + if isinstance(obj, dict): + return {k: self._clean_keyboard_dict(v) for k, v in obj.items() if k != "_"} + elif isinstance(obj, list): + return [self._clean_keyboard_dict(item) for item in obj] + return obj - async def _send_http_fallback(self, target: str | int, text: str, keyboard: Optional[Any] = None) -> Optional[Any]: + async def _send_http(self, target: str | int, text: str, keyboard: Optional[Any] = None) -> Optional[Any]: if not self.http or not self.bot_token: return None try: @@ -565,21 +497,22 @@ if keyboard is not None: try: kb_data = json.loads(str(keyboard)) - kb_data.pop("_", None) - payload["reply_markup"] = kb_data + payload["reply_markup"] = self._clean_keyboard_dict(kb_data) except Exception: pass async with self.http.post(bot_url, json=payload, timeout=aiohttp.ClientTimeout(total=8)) as resp: if resp.status == 200: data = await resp.json() msg_id = data.get("result", {}).get("message_id", 0) - log(f"Successfully sent message to {target} via HTTP Bot API fallback.") return SimpleNamespace(id=msg_id) + elif resp.status == 403: + log(f"User {target} has blocked the bot.")