Add filters.FORUM (#4906)

This commit is contained in:
Harshil
2025-08-17 05:20:02 -04:00
committed by GitHub
parent 4654d195f5
commit 47fd9fcc7e
3 changed files with 25 additions and 0 deletions
@@ -0,0 +1,5 @@
features = "Add ``filters.FORUM`` to filter messages from forum topic chats"
[[pull_requests]]
uid = "4906"
author_uid = "harshil21"
closes_threads = []
+15
View File
@@ -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__ = ()
+5
View File
@@ -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")