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

Duplicate messages forwarded #47

Closed
DaCaemboe opened this issue Dec 6, 2023 · 4 comments · Fixed by #55
Closed

Duplicate messages forwarded #47

DaCaemboe opened this issue Dec 6, 2023 · 4 comments · Fixed by #55

Comments

@DaCaemboe
Copy link

DaCaemboe commented Dec 6, 2023

Sometimes users spam the same message and they all get forwarded to discord.

How do I block duplicate messages from being sent?

I tried using an if/else statement for duplicate messages, but the script doesn't do anything when I apply those changes.
Any chance you can help me with this?

global last_message

async def process_message_text(event, forwarder_config: dict[str, Any],
                               mention_everyone: bool,
                               mention_roles: List[str],
                               openai_enabled: bool) -> str:  # pylint: disable=too-many-arguments
    """Process the message text and return the processed text."""
    message_text = event.message.message

    if last_message != message_text:

        if openai_enabled:
            suggestions = await analyze_message_sentiment(message_text)
            message_text = f'{message_text}\n{suggestions}'

        if mention_everyone:
            message_text += '\n' + '@everyone'

        if mention_roles:
            mention_text = ", ".join(role for role in mention_roles)
            message_text = f"{mention_text}\n{message_text}"

        last_message = message_text

        return telegram_entities_to_markdown(message_text, event.message.entities,
                                             forwarder_config["strip_off_links"])
    else:
        print("\n========================================\nDENIED MESSAGE\n========================================\n  Duplicate Last Message, Ignoring \n========================================\nDENIED MESSAGE\n========================================\n")

    last_message = message_text
@DaCaemboe
Copy link
Author

DaCaemboe commented Dec 6, 2023

Also, when a # or @ (user tagged) is added to the text it seems to strip off characters like dashes and double colons.

@hyp3rd
Copy link
Owner

hyp3rd commented Dec 14, 2023

Catching duplicate messages is a little tricky. But I'll check it out. I'm about to push a significant change for the whole codebase in the next days, then I'll pick it up this issue.

@DaCaemboe
Copy link
Author

sounds great!
any solution for the output fix?

I see that you filter out hashtags and dashes when a hashtag is found in the text, but it messes up some stuff. any workaround to leave the output text as is?

@hyp3rd
Copy link
Owner

hyp3rd commented Dec 18, 2023

I'm pushing today the change with an optional anti-spam filter.
For now is very basic, but it detects duplicates. That should do for your case. Once I finish the API I will add more features to it

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 a pull request may close this issue.

2 participants