From fed2f466a9fbeceacef5801a7a3d86c482ebc72c Mon Sep 17 00:00:00 2001 From: drendog Date: Fri, 8 Aug 2025 18:00:13 +0200 Subject: [PATCH 1/4] fix: ban the spammer to prevent account reuse --- src/spotted/handlers/spam_comment.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/spotted/handlers/spam_comment.py b/src/spotted/handlers/spam_comment.py index 200d7ee..deca28c 100644 --- a/src/spotted/handlers/spam_comment.py +++ b/src/spotted/handlers/spam_comment.py @@ -9,7 +9,7 @@ async def spam_comment_msg(update: Update, context: CallbackContext) -> None: """Handles a spam comment on a post in the comment group. - Deletes the original post. + Deletes the original post and bans the user. Args: update: update event @@ -21,4 +21,8 @@ async def spam_comment_msg(update: Update, context: CallbackContext) -> None: for message in Config.post_get("blacklist_messages"): if message in info.message.text: await info.message.delete() + await info.bot.ban_chat_member( + chat_id=info.chat_id, + user_id=info.message.from_user.id, + ) return From bc0566c0715d9d5a8593b57114382b2dd06862df Mon Sep 17 00:00:00 2001 From: drendog Date: Fri, 8 Aug 2025 18:16:06 +0200 Subject: [PATCH 2/4] test: check user is banned --- tests/integration/test_bot.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/integration/test_bot.py b/tests/integration/test_bot.py index 30151e9..ad35397 100644 --- a/tests/integration/test_bot.py +++ b/tests/integration/test_bot.py @@ -908,17 +908,19 @@ async def test_spam_comment_msg( """Tests the replacement of an anonymous comment. Copies the message and deletes the original """ + user_id = 10 for word in Config.post_get("blacklist_messages"): spam_comment = await telegram.send_message( f"a message with the {word} will be deleted", chat=channel_group, reply_to_message=published_post.reply_to_message, - user=TGUser(10, first_name="user", is_bot=False), + user=TGUser(user_id, first_name="user", is_bot=False), sender_chat=channel, ) assert telegram.get_message_by_id(spam_comment.message_id) is None # the spam comment is deleted assert telegram.last_message.from_user.is_bot is True + assert User(user_id).is_banned is True class TestFollow: """Tests the follow feature""" From 3bf94dff71c3dcca8cb9a5e38bd7acfbf1bd6943 Mon Sep 17 00:00:00 2001 From: drendog Date: Fri, 8 Aug 2025 18:20:01 +0200 Subject: [PATCH 3/4] fix: typo --- .github/PULL_REQUEST_TEMPLATE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index cd2df88..1811788 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -5,7 +5,7 @@ - [ ] 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. +- [ ] I have updated the `CHANGELOG.md` file with an overview of the changes made. ### Description From b82ce5050e0c1771ed4e3266b82d3c32842b0d62 Mon Sep 17 00:00:00 2001 From: drendog Date: Fri, 8 Aug 2025 18:21:05 +0200 Subject: [PATCH 4/4] chore: update changelog --- .github/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/CHANGELOG.md b/.github/CHANGELOG.md index b9bc6d7..044f863 100644 --- a/.github/CHANGELOG.md +++ b/.github/CHANGELOG.md @@ -8,7 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] - Show credit username during approval process - +- Ban users who post spam on the comment group ... ## [3.1.0] - 2024-02-18