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
21 changes: 21 additions & 0 deletions ptbcontrib/true_reply_filter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# True Reply Filter

Provides a `TRUE_REPLY_FILTER` that allows you to filter only **real replies** in Telegram groups and forum topics, ignoring topic starters.

```python
from telegram.ext import MessageHandler
from ptbcontrib.true_reply_filter import TRUE_REPLY_FILTER

MessageHandler(
TRUE_REPLY_FILTER,
callback
)
```

## Requirements

* `python-telegram-bot>=20.0`

## Authors

* [Daniel](https://github.com/rozari0)
25 changes: 25 additions & 0 deletions ptbcontrib/true_reply_filter/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# A library containing community-based extension for the python-telegram-bot library
# Copyright (C) 2020-2026
# The ptbcontrib developers
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser Public License for more details.
#
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""
This module contains a filter that filters correctly in a group with topics.
"""

from .true_reply_filter import TRUE_REPLY_FILTER

__all__ = [
"TRUE_REPLY_FILTER",
]
1 change: 1 addition & 0 deletions ptbcontrib/true_reply_filter/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python-telegram-bot>=20.0

Check notice on line 1 in ptbcontrib/true_reply_filter/requirements.txt

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

ptbcontrib/true_reply_filter/requirements.txt#L1

Statement seems to have no effect
19 changes: 19 additions & 0 deletions ptbcontrib/true_reply_filter/true_reply_filter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from telegram import Message
from telegram.ext.filters import MessageFilter


class _Reply(MessageFilter):
__slots__ = ()

def filter(self, message: Message) -> bool:
if not message.reply_to_message:
return False
if (
message.is_topic_message
and message.message_thread_id == message.reply_to_message.message_id
):
return False
return True


TRUE_REPLY_FILTER = _Reply(name="true_reply_filter.REPLY")
Loading