add start stop

This commit is contained in:
Aron Petau 2026-01-02 13:41:21 +01:00
parent c68ee12d4e
commit 29a3f629e2
4 changed files with 69 additions and 3 deletions

View file

@ -20,6 +20,8 @@ class TelegramBot:
"""Send a help message with available commands."""
help_text = (
"<b>Available commands:</b>\n"
"/start - Resume monitoring\n"
"/stop - Pause monitoring\n"
"/autopilot on|off - Enable/disable autopilot\n"
"/status - Show current status\n"
"/plot - Show weekly listing pattern plot\n"
@ -38,6 +40,25 @@ class TelegramBot:
)
await self._send_message(msg)
async def _handle_start_command(self) -> None:
"""Resume monitoring for new listings."""
self.monitor.state_manager.set_monitoring_enabled(True)
await self._send_message(
"▶️ <b>Monitoring RESUMED</b>\n\n"
"Bot will now check for new listings and notify you."
)
logger.info("Monitoring resumed via /start command")
async def _handle_stop_command(self) -> None:
"""Pause monitoring without stopping the bot."""
self.monitor.state_manager.set_monitoring_enabled(False)
await self._send_message(
"⏸️ <b>Monitoring PAUSED</b>\n\n"
"Bot will not check for new listings until you send /start.\n"
"Commands like /status, /plot, and /retryfailed still work."
)
logger.info("Monitoring paused via /stop command")
async def _handle_reset_listings_command(self) -> None:
"""Move listings.json to data/old/ with a timestamp, preserving statistics and application history."""
import shutil
@ -133,7 +154,11 @@ class TelegramBot:
return
logger.info(f"Received Telegram command: {text}")
loop = self.event_loop
if text.startswith("/autopilot"):
if text == "/start":
asyncio.run_coroutine_threadsafe(self._handle_start_command(), loop)
elif text == "/stop":
asyncio.run_coroutine_threadsafe(self._handle_stop_command(), loop)
elif text.startswith("/autopilot"):
asyncio.run_coroutine_threadsafe(self._handle_autopilot_command(text), loop)
elif text == "/status":
asyncio.run_coroutine_threadsafe(self._handle_status_command(), loop)
@ -230,9 +255,13 @@ class TelegramBot:
async def _handle_status_command(self) -> None:
state = self.app_handler.load_state()
autopilot = state.get("autopilot", False)
monitoring = state.get("monitoring_enabled", True)
applications = self.app_handler.load_applications()
status = "<b>Autopilot:</b> " + ("ON" if autopilot else "OFF")
status = "<b>Monitoring:</b> " + ("▶️ RUNNING" if monitoring else "⏸️ PAUSED")
status += "\n<b>Autopilot:</b> " + ("✅ ON" if autopilot else "🛑 OFF")
status += f"\n📝 <b>Applications sent:</b> {len(applications)}"
by_company: dict[str, int] = {}
for app in applications.values():
company = app.get("company", "unknown")