Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix reply command #148

Merged
merged 8 commits into from
Feb 14, 2024
Merged

Fix reply command #148

merged 8 commits into from
Feb 14, 2024

Conversation

Picred
Copy link
Member

@Picred Picred commented Dec 2, 2023

Prerequisites

  • I have read and understood the contributing guide.
  • The commit message follows the conventional commits guidelines.
  • Tested the changes locally with a real Telegram bot.
  • Introduced tests for the changes have been added (for bug fixes / features).
  • Docs have been added/updated (for bug fixes / features).
  • I have updated the CHANGELOG.rst file with an overview of the changes made.

Description

Fix reply command when it is triggered by bot's menu command

Issue closed by this PR

Does this PR introduce a breaking change?

  • Yes
  • No

Python version you are using

Python 3.10.12

@@ -16,7 +16,7 @@ async def reply_cmd(update: Update, context: CallbackContext):
"""
info = EventInfo.from_message(update, context)

if len(info.text) <= 7: # the reply is empty
if len(info.text) <= 7 or Config.post_get("channel_tag")[1:] in info.text.lower(): # the reply is empty
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but if I have
/reply@Spotted_DMI_Bot blablabla
this condition will be true but I am using the reply correctly

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think when you use the full-command /reply@Spotted_DMI_Bot answer it is only because you accidentally click the suggested command of the bot menu. Usually you just use /reply answer without including @Spotted_DMI_bot in the command

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but it's wrong conceptually that you can't use the full-command
you could change the condition into something like
if len(...) <= SOMETHING:

where SOMETHING is

  • 7 when not bot_tag in info.text.lower()
  • 7 + len(config bot_tag) when bot_tag in info.text.lower()

@Picred Picred marked this pull request as draft December 2, 2023 17:40
@TendTo
Copy link
Member

TendTo commented Dec 3, 2023

This small change in the src/spotted/handlers/reply.py file should fix the issue:

async def reply_cmd(update: Update, context: CallbackContext):
    info = EventInfo.from_message(update, context)
    ### use the new args property of the info object
    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=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=f"COMUNICAZIONE DEGLI ADMIN SUL TUO ULTIMO REPORT:\n{reply_text}"
        )

It appears that both the command's short and long versions (with the bot tag) behave correctly this way.
Maybe add a couple of tests to make sure the problem won't appear again in the future.

@TendTo
Copy link
Member

TendTo commented Dec 3, 2023

And a smaller thing: don't add this fix in the changelog under version 3.0.0 since that version has already been released and cannot be changed.
Add a new version (3.0.1) and the fix under that one. We will accumulate all the changes under that version until it gets released. Then, we increase the version and proceed in the same way for future features or fixes.

@Picred
Copy link
Member Author

Picred commented Dec 17, 2023

I updated the reply command and removed the previous addition of the entry in the CHANGELOG.md.
I prefer to better understand how it is used before introducing new lines

Unfortunately I don't have time to add the tests, sorry.

Thanks so much @TendTo for the suggestion 😄

@Picred Picred marked this pull request as ready for review December 17, 2023 17:07
@TendTo
Copy link
Member

TendTo commented Dec 17, 2023

Just fix the linting issues (there is an unused import and you accidentally removed the function docstring) and we will be golden.

@TendTo TendTo requested a review from Helias February 13, 2024 23:31
@Helias Helias merged commit f31bf02 into main Feb 14, 2024
18 checks passed
@Helias Helias deleted the fix-reply branch February 14, 2024 09:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

empty reply
3 participants