Skip to content

Commit

Permalink
fix: more logs to debug
Browse files Browse the repository at this point in the history
  • Loading branch information
vas3k committed Nov 13, 2024
1 parent 1a79966 commit 2773141
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
13 changes: 13 additions & 0 deletions bot/handlers/comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand All @@ -28,24 +31,31 @@ 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)

if POST_EMOJI_RE.match(reply_text_start):
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)
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions bot/handlers/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down
8 changes: 8 additions & 0 deletions bot/handlers/upvotes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -49,13 +51,16 @@ 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

_, 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(
Expand All @@ -72,13 +77,16 @@ 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

_, 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(
Expand Down
2 changes: 2 additions & 0 deletions bot/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 2773141

Please sign in to comment.