From 38c452051e7ff7a9b423b8d5be19a434c4d2f6ef Mon Sep 17 00:00:00 2001 From: Guillermo Serrahima Date: Mon, 2 Feb 2026 04:15:55 +0100 Subject: More misc corrections --- main.py | 2 ++ velascobot2/bot.py | 9 ++++----- velascobot2/parrot.py | 2 +- velascobot2/utils.py | 2 +- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/main.py b/main.py index c01aa6b..37c5d12 100644 --- a/main.py +++ b/main.py @@ -1,3 +1,4 @@ +import asyncio import logging from pathlib import Path @@ -18,6 +19,7 @@ def load_config(config_path: Path | None) -> dict: def run_bot(bot: Bot) -> None: + asyncio.run(bot.wake_up()) bot.app.run_polling(poll_interval=1.0) assert "@" + bot.app.bot.username == bot.messenger.username diff --git a/velascobot2/bot.py b/velascobot2/bot.py index 5914906..9659a8d 100644 --- a/velascobot2/bot.py +++ b/velascobot2/bot.py @@ -170,8 +170,7 @@ class Bot: ) ) - if self.testing: - app.add_error_handler(error_handler) + app.add_error_handler(error_handler) self.app = app @@ -380,10 +379,9 @@ class Bot: for chat in self.messenger.get_all_chats(): if check(chat): try: + logger.info(f"Sending announcement to {chat.id}") await self.send(chat.id, Response.TEXT, announcement) - logger.info( - "Sending announcement to chat {}".format(chat.id) - ) + time.sleep(1) except Exception: pass @@ -404,6 +402,7 @@ class Bot: return "group" in chat.type or chat.id in self.motd_chats wake_text = random.choice(self.motd_list) + logger.info(f"Printing message of the day: {wake_text}") await self.announce(wake_text, valid_chat) async def should_reply(self, message: Message, chat: ChatData) -> bool: diff --git a/velascobot2/parrot.py b/velascobot2/parrot.py index c7ba217..9ca139a 100644 --- a/velascobot2/parrot.py +++ b/velascobot2/parrot.py @@ -103,7 +103,7 @@ class Parrot: words_count = self.db.count_words(chat_id, _normalize_key("", "")) total = graphics_count + words_count - if random.random() < graphics_count / total: + if total > 0 and random.random() < graphics_count / total: return Response.GRAPHIC else: return Response.TEXT diff --git a/velascobot2/utils.py b/velascobot2/utils.py index 24c5160..d9e929d 100644 --- a/velascobot2/utils.py +++ b/velascobot2/utils.py @@ -38,7 +38,7 @@ class ChatData: @staticmethod def from_sql_row(row: tuple[str, str, str, int, int, float, int, int]): - logger.debug("From SQL row:", repr(row)) + logger.debug(f"From SQL row: {repr(row)}") return ChatData( row[0], row[1], -- cgit v1.2.3