8000 Handle Non-Message Updates in `InvertedRole` (#94) · python-telegram-bot/ptbcontrib@0efef67 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0efef67

Browse files
authored
Handle Non-Message Updates in InvertedRole (#94)
* Added non-message tests for `InvertedRole` * fix non-message updates not being handled
1 parent 222ae22 commit 0efef67

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

ptbcontrib/roles/roles.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,13 @@ def __init__(self, role: Role):
396396
super().__init__(name=f"<inverted {role}>", data_filter=False)
397397
self.role = role
398398

399+
def check_update(self, update: Update) -> bool:
400+
"""Check if the update is allowed by this role. This is just an alias for
401+
:meth:`filter`.
402+
"""
403+
# Override UpdateFilter.check_update to handle also updates that are not messages
404+
return self.filter(update)
405+
399406
def filter(self, update: Update) -> bool:
400407
"""Checks if the update should be handled."""
401408
return self.role.filter(update, inverted=True)

tests/test_roles.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,16 +296,19 @@ def test_always_allow_admin(self, update, role):
296296
def test_non_message_update(self, update, role):
297297
update.message = None
298298
assert not role.check_update(update)
299+
assert not (~role).check_update(update)
299300

300301
update.callback_query = CallbackQuery(
301302
id="id",
302303
from_user=User(id=0, is_bot=False, first_name="first_name"),
303304
chat_instance="chat_instance",
304305
)
305306
assert not role.check_update(update)
307+
assert (~role).check_update(update)
306308

307309
role.add_member(0)
308310
assert role.check_update(update)
311+
assert not (~role).check_update(update)
309312

310313
def test_pickle(self, role, parent_role):
311314
role.add_member([0, 1, 3])

0 commit comments

Comments
 (0)
0