fix wgcompany

This commit is contained in:
Aron Petau 2026-01-02 23:29:17 +01:00
parent 29a3f629e2
commit bc0c369a92
3 changed files with 33 additions and 3 deletions

View file

@ -28,6 +28,7 @@ class TelegramBot:
"/errorrate - Show autopilot error rate plot\n"
"/retryfailed - Retry failed applications\n"
"/resetlistings - Reset listings file\n"
"/logs - Show last 50 log lines\n"
"/help - Show this help message"
)
await self._send_message(help_text)
@ -59,6 +60,32 @@ class TelegramBot:
)
logger.info("Monitoring paused via /stop command")
async def _handle_logs_command(self) -> None:
"""Send the last 50 lines of the log file."""
log_file = "data/monitor.log"
try:
if not os.path.exists(log_file):
await self._send_message("📋 No log file found.")
return
with open(log_file, "r", encoding="utf-8") as f:
lines = f.readlines()
last_lines = lines[-50:] if len(lines) > 50 else lines
log_text = "".join(last_lines)
# Truncate if too long for Telegram (4096 char limit)
if len(log_text) > 4000:
log_text = log_text[-4000:]
log_text = "..." + log_text[log_text.find("\n") + 1:] # Start from next newline
message = f"📋 <b>Last {len(last_lines)} log lines:</b>\n\n<pre>{log_text}</pre>"
await self._send_message(message)
logger.info("Sent last 50 log lines via /logs command")
except Exception as e:
logger.error(f"Failed to read log file: {e}")
await self._send_message(f"❌ Error reading logs: {e}")
async def _handle_reset_listings_command(self) -> None:
"""Move listings.json to data/old/ with a timestamp, preserving statistics and application history."""
import shutil
@ -179,6 +206,8 @@ class TelegramBot:
logger.error(f"/retryfailed command failed: {e}")
elif text == "/resetlistings":
asyncio.run_coroutine_threadsafe(self._handle_reset_listings_command(), loop)
elif text == "/logs":
asyncio.run_coroutine_threadsafe(self._handle_logs_command(), loop)
elif text.startswith("/"):
asyncio.run_coroutine_threadsafe(self._handle_unknown_command(text), loop)