Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 5 additions & 1 deletion src/spotted/handlers/spam_comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
4 changes: 3 additions & 1 deletion tests/integration/test_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down
Loading