From ce182999a075ee5d054295125e021ff7f73a6914 Mon Sep 17 00:00:00 2001 From: profitroll Date: Tue, 13 Dec 2022 14:50:21 +0100 Subject: [PATCH] Improved comments --- classes/holo_user.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/classes/holo_user.py b/classes/holo_user.py index 96015a9..c6de204 100644 --- a/classes/holo_user.py +++ b/classes/holo_user.py @@ -114,6 +114,7 @@ class HoloUser(): * adm_context (`bool`, *optional*): Whether context sender is an admin. Defaults to False. """ + # Check if any text available and log message sending if text is not None: logWrite(f"{context.from_user.id} sent message '{text}' to {self.id}") elif caption is not None: @@ -121,6 +122,7 @@ class HoloUser(): else: logWrite(f"{context.from_user.id} sent message to {self.id}") + # Add notices for admin or user if text is not None: if adm_context: text += locale("message_reply_notice", "message") @@ -137,8 +139,11 @@ class HoloUser(): else: caption = locale("message_reply_notice", "message") + # Try sending the message try: + # Check if origin message exists + # This check decides whether we send_ a message or reply_ to one if origin is not None: if photo is not None: @@ -189,11 +194,17 @@ class HoloUser(): else: new_message = await app.send_message(self.id, text) + # Acknowledge sending a message and save entry into DB await context.reply_text(locale("message_sent", "message"), quote=should_quote(context)) col_messages.insert_one({"origin": {"chat": context.chat.id, "id": context.id}, "destination": {"chat": new_message.chat.id, "id": new_message.id}}) + # Report to admin and to sender about message sending failure except Exception as exp: - await context.reply_text(locale("message_traceback", "message").format(context.from_user.id, self.id, exp, print_exc())) + logWrite(f"Exception {exp} happened as {context.from_user.id} tried to send message to {self.id}. Traceback:\n{print_exc()}") + try: + await app.send_message(configGet("owner"), locale("message_traceback", "message").format(context.from_user.id, self.id, exp, print_exc())) + except bad_request_400.PeerIdInvalid: + logWrite(f"Could not notify admin about failure when sending message! Admin has never interacted with bot!") await context.reply_text(locale("message_error", "message"), quote=should_quote(context)) async def set_label(self, chat: Chat, label: str):