Skip to content

Commit

Permalink
fix: fix reply command
Browse files Browse the repository at this point in the history
  • Loading branch information
Picred committed Dec 17, 2023
1 parent 49b1f56 commit ad7d1ce
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 13 deletions.
1 change: 0 additions & 1 deletion .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Anonymous messages are deleted [ rebase over #132 ]
- Preview feature [ cherry-pick #138 ]
- Display the right message when the post is rejected with a reason [ cherry-pick #139 ]
- Reply command with empty content [ closes #147 ]

### Changed

Expand Down
17 changes: 5 additions & 12 deletions src/spotted/handlers/reply.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,26 @@


async def reply_cmd(update: Update, context: CallbackContext):
"""Handles the /reply command.
Send a message to a user by replying to one of his pending posts with /reply + the message you want to send
Args:
update: update event
context: context passed by the handler
"""
info = EventInfo.from_message(update, context)

if len(info.text) <= 7 or Config.post_get("channel_tag")[1:] in info.text.lower(): # the reply is empty
if len(info.args) == 0: # the reply is empty
await info.bot.send_message(
chat_id=info.chat_id,
text="La reply è vuota\n"
"Per mandare un messaggio ad un utente, rispondere al suo post o report con /reply "
"seguito da ciò che gli si vuole dire",
)
return

### build the reply text from the args
reply_text = " ".join(info.args)
g_message_id = update.message.reply_to_message.message_id
if (pending_post := PendingPost.from_group(admin_group_id=info.chat_id, g_message_id=g_message_id)) is not None:
await info.bot.send_message(
chat_id=pending_post.user_id,
text="COMUNICAZIONE DEGLI ADMIN SUL TUO ULTIMO POST:\n" + info.text[7:].strip(),
text=f"COMUNICAZIONE DEGLI ADMIN SUL TUO ULTIMO POST:\n{reply_text}",
)
elif (report := Report.from_group(admin_group_id=info.chat_id, g_message_id=g_message_id)) is not None:
await info.bot.send_message(
chat_id=report.user_id, text="COMUNICAZIONE DEGLI ADMIN SUL TUO ULTIMO REPORT:\n" + info.text[7:].strip()
chat_id=report.user_id, text=f"COMUNICAZIONE DEGLI ADMIN SUL TUO ULTIMO REPORT:\n{reply_text}"
)
else: # the reply does not refer to a pending post or a report
await info.bot.send_message(
Expand Down

0 comments on commit ad7d1ce

Please sign in to comment.