fix emojis
This commit is contained in:
parent
c45c6992ae
commit
287b1b154f
5 changed files with 39 additions and 32 deletions
|
|
@ -62,7 +62,7 @@ class TelegramBot:
|
|||
await self._send_message(msg)
|
||||
except Exception as e:
|
||||
logger.error(f"Error resetting listings: {e}")
|
||||
await self._send_message(f"❌ Error resetting listings: {str(e)}")
|
||||
await self._send_message(f"[ERROR] Error resetting listings: {str(e)}")
|
||||
|
||||
def __init__(self, monitor, bot_token: str | None = None, chat_id: str | None = None, event_loop=None) -> None:
|
||||
self.monitor = monitor
|
||||
|
|
@ -174,9 +174,9 @@ class TelegramBot:
|
|||
and app.get("retries", 0) < max_retries
|
||||
and not app.get("deactivated", False)
|
||||
]
|
||||
await self._send_message(f"🔄 Retrying {len(failed)} failed applications (max retries: {max_retries})...")
|
||||
await self._send_message(f"[RETRY] Retrying {len(failed)} failed applications (max retries: {max_retries})...")
|
||||
if not failed:
|
||||
await self._send_message("✅ No failed applications to retry (or all reached max retries).")
|
||||
await self._send_message("[INFO] No failed applications to retry (or all reached max retries).")
|
||||
return
|
||||
results = {}
|
||||
details = []
|
||||
|
|
@ -197,7 +197,7 @@ class TelegramBot:
|
|||
result["timestamp"] = app.get("timestamp", result["timestamp"])
|
||||
self.app_handler.save_application(result)
|
||||
results[listing["id"]] = result
|
||||
status_emoji = "✅" if result["success"] else "❌"
|
||||
status_emoji = "[SUCCESS]" if result["success"] else "[FAILED]"
|
||||
details.append(
|
||||
f"{status_emoji} <b>{result.get('address', '')}</b> ({result.get('company', '')})\n"
|
||||
f"<code>{result.get('link', '')}</code>\n"
|
||||
|
|
@ -205,7 +205,7 @@ class TelegramBot:
|
|||
)
|
||||
n_success = sum(1 for r in results.values() if r["success"])
|
||||
n_fail = sum(1 for r in results.values() if not r["success"])
|
||||
summary = f"🔄 Retried {len(results)} failed applications.\n✅ Success: {n_success}\n❌ Still failed: {n_fail}"
|
||||
summary = f"[RETRY] Retried {len(results)} failed applications.\n[SUCCESS]: {n_success}\n[FAILED]: {n_fail}"
|
||||
if details:
|
||||
summary += "\n\n<b>Details:</b>\n" + "\n".join(details)
|
||||
await self._send_message(summary)
|
||||
|
|
@ -220,7 +220,7 @@ class TelegramBot:
|
|||
if action == "on":
|
||||
logger.info("Enabling autopilot mode")
|
||||
self.monitor.set_autopilot(True)
|
||||
await self._send_message("🤖 <b>Autopilot ENABLED</b>\n\nI will automatically apply to new listings!")
|
||||
await self._send_message("<b>Autopilot ENABLED</b>\n\nI will automatically apply to new listings!")
|
||||
elif action == "off":
|
||||
self.monitor.set_autopilot(False)
|
||||
await self._send_message("🛑 <b>Autopilot DISABLED</b>\n\nI will only notify you of new listings.")
|
||||
|
|
@ -231,7 +231,7 @@ class TelegramBot:
|
|||
state = self.app_handler.load_state()
|
||||
autopilot = state.get("autopilot", False)
|
||||
applications = self.app_handler.load_applications()
|
||||
status = "🤖 <b>Autopilot:</b> " + ("ON ✅" if autopilot else "OFF ❌")
|
||||
status = "<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():
|
||||
|
|
@ -264,7 +264,7 @@ class TelegramBot:
|
|||
logger.error(f"Error generating errorrate plot: {e}")
|
||||
import traceback
|
||||
logger.error(traceback.format_exc())
|
||||
await self._send_message(f"❌ Error generating errorrate plot: {str(e)}")
|
||||
await self._send_message(f"[ERROR] Error generating errorrate plot: {str(e)}")
|
||||
|
||||
|
||||
async def _send_message(self, text: str) -> None:
|
||||
|
|
@ -274,6 +274,9 @@ class TelegramBot:
|
|||
logger.warning("Telegram bot token or chat ID not configured, cannot send message")
|
||||
return
|
||||
|
||||
# Clean text: remove invalid unicode surrogates
|
||||
text = text.encode('utf-8', errors='ignore').decode('utf-8')
|
||||
|
||||
url = f"https://api.telegram.org/bot{self.bot_token}/sendMessage"
|
||||
|
||||
# Split message into chunks if too long
|
||||
|
|
@ -340,6 +343,9 @@ class TelegramBot:
|
|||
logger.warning("Telegram bot token or chat ID not configured, cannot send photo")
|
||||
return
|
||||
|
||||
# Clean caption: remove invalid unicode surrogates
|
||||
caption = caption.encode('utf-8', errors='ignore').decode('utf-8')
|
||||
|
||||
url = f"https://api.telegram.org/bot{self.bot_token}/sendPhoto"
|
||||
max_retries = 3
|
||||
retry_delay = 1 # Initial delay in seconds
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue