From 27731414f76567712df952e2a6959093604635fe Mon Sep 17 00:00:00 2001 From: Vasily Zubarev Date: Wed, 13 Nov 2024 13:31:51 +0100 Subject: [PATCH] fix: more logs to debug --- bot/handlers/comments.py | 13 +++++++++++++ bot/handlers/common.py | 4 ++-- bot/handlers/upvotes.py | 8 ++++++++ bot/main.py | 2 ++ 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/bot/handlers/comments.py b/bot/handlers/comments.py index 09c609eef..9f8aab11f 100644 --- a/bot/handlers/comments.py +++ b/bot/handlers/comments.py @@ -19,7 +19,10 @@ def comment(update: Update, context: CallbackContext) -> None: + log.info("Comment handler triggered: %s", update) + if not update.message or not update.message.reply_to_message: + log.info("No message or reply_to_message in update. Skipping.") return None reply_text_start = ( @@ -28,6 +31,8 @@ def comment(update: Update, context: CallbackContext) -> None: "" )[:10] + log.info("Original message start: %s", reply_text_start) + if COMMENT_EMOJI_RE.match(reply_text_start): return reply_to_comment(update, context) @@ -35,17 +40,22 @@ def comment(update: Update, context: CallbackContext) -> None: return comment_to_post(update, context) # skip normal replies + log.info("Skipping...") return None @is_club_member def reply_to_comment(update: Update, context: CallbackContext) -> None: + log.info("Reply_to_comment handler triggered") + user = get_club_user(update) if not user: + log.info("User not found") return None comment = get_club_comment(update) if not comment: + log.info("Original comment not found. Skipping.") return None is_ok = Comment.check_rate_limits(user) @@ -101,8 +111,11 @@ def reply_to_comment(update: Update, context: CallbackContext) -> None: @is_club_member def comment_to_post(update: Update, context: CallbackContext) -> None: + log.info("Reply_to_post handler triggered") + user = get_club_user(update) if not user: + log.info("User not found") return None post = get_club_post(update) diff --git a/bot/handlers/common.py b/bot/handlers/common.py index 9c1e72e38..ca7743486 100644 --- a/bot/handlers/common.py +++ b/bot/handlers/common.py @@ -84,7 +84,7 @@ def get_club_comment(update: Update) -> Optional[Comment]: if comment_id: break else: - log.warning(f"Comment URL not found: {update.message.reply_to_message}") + log.warning(f"Comment URL not found in message: {update.message.reply_to_message}") return None comment = Comment.objects.filter(id=comment_id).first() @@ -107,7 +107,7 @@ def get_club_post(update: Update) -> Optional[Post]: if post_id: break else: - log.warning(f"Post URL not found: {update.message.reply_to_message}") + log.warning(f"Post URL not found in message: {update.message.reply_to_message}") return None post = Post.objects.filter(slug=post_id).first() diff --git a/bot/handlers/upvotes.py b/bot/handlers/upvotes.py index a6dec136c..f3948639e 100644 --- a/bot/handlers/upvotes.py +++ b/bot/handlers/upvotes.py @@ -14,6 +14,8 @@ @is_club_member def upvote(update: Update, context: CallbackContext) -> None: + log.info("Upvote handler triggered") + if not update.message or not update.message.reply_to_message: return None @@ -49,6 +51,8 @@ def upvote(update: Update, context: CallbackContext) -> None: def upvote_comment(update: Update, context: CallbackContext) -> None: + log.info("Upvote_comment handler triggered") + user = get_club_user(update) if not user: return None @@ -56,6 +60,7 @@ def upvote_comment(update: Update, context: CallbackContext) -> None: _, comment_id = update.callback_query.data.split(":", 1) comment = Comment.objects.filter(id=comment_id).select_related("post").first() if not comment: + log.info("Original comment not found. Skipping.") return None _, is_created = CommentVote.upvote( @@ -72,6 +77,8 @@ def upvote_comment(update: Update, context: CallbackContext) -> None: def upvote_post(update: Update, context: CallbackContext) -> None: + log.info("Upvote_post handler triggered") + user = get_club_user(update) if not user: return None @@ -79,6 +86,7 @@ def upvote_post(update: Update, context: CallbackContext) -> None: _, post_id = update.callback_query.data.split(":", 1) post = Post.objects.filter(id=post_id).first() if not post: + log.info("Original post not found. Skipping.") return None _, is_created = PostVote.upvote( diff --git a/bot/main.py b/bot/main.py index df9ab50a6..2c375a1a0 100644 --- a/bot/main.py +++ b/bot/main.py @@ -41,6 +41,8 @@ def command_help(update: Update, context: CallbackContext) -> None: def private_message(update: Update, context: CallbackContext) -> None: + log.info("Private message handler triggered") + club_users = cached_telegram_users() if str(update.effective_user.id) not in set(club_users): update.effective_chat.send_message(