- Nov 7, 2026
- 3 min read
Two Strikes, Edits and the Owner Exemption
Deleting a spam message is easy. Deciding when someone should be removed is the real policy question.
Two strikes, counted per message
def moderate_delete(self, chat_id, message_id, user_id, key):
self.action(f"delete:{chat_id}:{message_id}", "deleteMessage", ...)
count = store.record_deletion(chat_id, message_id, user_id) # PK (chat_id, message_id)
if count >= 2 and user_id != OWNER:
store.ban(user_id, "Second moderated message deletion")
self.action(f"ban:{chat_id}:{user_id}:{message_id}", "banChatMember", ...)
- A strike is a deleted message, not a high score. Uncertain messages that I Keep don’t count.
- Automatic deletions and my Delete button go through the same function, so they count the same.
- The database primary key makes “counted once per message” a hard rule, not something the code has to remember.
- A member who posts one off-topic message gets a warning-by-deletion and stays. Someone who keeps posting spam is out on the second deletion.
The ban is saved in the database and sent to Telegram. That matters for join requests: approval requires admin review, and the bot declines anyone on its own ban list, even if a Telegram ban was lifted somewhere else.
Editing doesn’t get around it
A classic trick is to post something harmless, wait for the bot to approve it, then edit it into a referral link.
Telegram delivers the edit as a new edited_message update with its own update_id, so the bot scores it again
from scratch. Because strikes are keyed by message ID, an edited message that’s deleted counts once, even if it
was edited several times.
This was one of the live checks: a message that had been allowed was edited, scored again and deleted.
The owner exemption
My messages are classified and can be deleted like anyone else’s. Rules apply to me too, and it’s the best way to test thresholds. But the bot never bans the owner: being locked out of your own group by your own bot is a mistake you can’t fix from inside the group.
Undoing a ban
There’s no automatic unban, on purpose, but there is a one-liner:
make down # or Ctrl+C in local mode: one writer at a time
make unban USER_ID=123456789 # Telegram unban + delete DB ban + reset strikes
make up
The Makefile checks that USER_ID is a positive number before calling anything. The unban is recorded as a
decision like everything else, so the history shows who was banned, why, and when it was reversed.
Reviews that can’t be pressed twice
Review cards carry review:<id>:keep|delete. The callback is accepted only if it comes from the owner, in the
owner’s private chat, for a pending review. A double tap gets “Already reviewed”. A forwarded card pressed by
someone else gets “Not authorized”.
Next in this series: A Quiet Nightly RSS Digest for a Telegram Group
Part 4 of 6. Start with the series overview.