mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2026-06-19 07:35:19 +00:00
Add filters.FORUM (#4906)
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
features = "Add ``filters.FORUM`` to filter messages from forum topic chats"
|
||||
[[pull_requests]]
|
||||
uid = "4906"
|
||||
author_uid = "harshil21"
|
||||
closes_threads = []
|
||||
@@ -50,6 +50,7 @@ __all__ = (
|
||||
"COMMAND",
|
||||
"CONTACT",
|
||||
"EFFECT_ID",
|
||||
"FORUM",
|
||||
"FORWARDED",
|
||||
"GAME",
|
||||
"GIVEAWAY",
|
||||
@@ -1366,6 +1367,20 @@ class Entity(MessageFilter):
|
||||
return any(entity.type == self.entity_type for entity in message.entities)
|
||||
|
||||
|
||||
class _Forum(UpdateFilter):
|
||||
__slots__ = ()
|
||||
|
||||
def filter(self, update: Update) -> bool:
|
||||
return bool(update.effective_chat and update.effective_chat.is_forum)
|
||||
|
||||
|
||||
FORUM = _Forum(name="filters.FORUM")
|
||||
"""Messages that are from a forum (topics enabled) chat.
|
||||
|
||||
.. versionadded:: NEXT.VERSION
|
||||
"""
|
||||
|
||||
|
||||
class _Forwarded(MessageFilter):
|
||||
__slots__ = ()
|
||||
|
||||
|
||||
@@ -1496,6 +1496,11 @@ class TestFilters:
|
||||
with pytest.raises(RuntimeError, match="Cannot set name"):
|
||||
f.name = "foo"
|
||||
|
||||
def test_filters_forum(self, update):
|
||||
assert not filters.FORUM.check_update(update)
|
||||
update.message.chat.is_forum = True
|
||||
assert filters.FORUM.check_update(update)
|
||||
|
||||
def test_filters_forwarded_from_init(self):
|
||||
with pytest.raises(RuntimeError, match="in conjunction with"):
|
||||
filters.ForwardedFrom(chat_id=1, username="chat")
|
||||
|
||||
Reference in New Issue
Block a user