Check channel_post and edited_channel_post in Update.effective_user (#5237)

This commit is contained in:
karin0
2026-05-21 06:44:41 +09:00
committed by GitHub
parent b4067ce363
commit 6fdab3a58d
5 changed files with 27 additions and 19 deletions
+1
View File
@@ -75,6 +75,7 @@ The following wonderful people contributed directly or indirectly to this projec
- `jossalgon <https://github.com/jossalgon>`_
- `JRoot3D <https://github.com/JRoot3D>`_
- `Juan Cuevas <https://github.com/cuevasrja>`
- `karin0 <https://github.com/karin0>`_
- `kenjitagawa <https://github.com/kenjitagawa>`_
- `kennethcheo <https://github.com/kennethcheo>`_
- `Kirill Vasin <https://github.com/vasinkd>`_
@@ -0,0 +1,5 @@
bugfixes = "`Update.effective_user` now checks for `channel_post` and `edited_channel_post`"
[[pull_requests]]
uid = "5237"
author_uids = ["karin0"]
closes_threads = ["5236"]
+8 -3
View File
@@ -500,8 +500,6 @@ class Update(TelegramObject):
is. If no user is associated with this update, this gives :obj:`None`. This is the case
if any of
* :attr:`channel_post`
* :attr:`edited_channel_post`
* :attr:`poll`
* :attr:`chat_boost`
* :attr:`removed_chat_boost`
@@ -518,7 +516,8 @@ class Update(TelegramObject):
This property now also considers :attr:`purchased_paid_media`.
.. versionchanged:: NEXT.VERSION
This property now also considers :attr:`managed_bot`.
This property now also considers :attr:`managed_bot`, :attr:`channel_post`
and :attr:`edited_channel_post`.
Example:
* If :attr:`message` is present, this will give
@@ -537,6 +536,12 @@ class Update(TelegramObject):
elif self.edited_message:
user = self.edited_message.from_user
elif self.channel_post:
user = self.channel_post.from_user
elif self.edited_channel_post:
user = self.edited_channel_post.from_user
elif self.inline_query:
user = self.inline_query.from_user
+1 -16
View File
@@ -95,22 +95,7 @@ class TestMessageHandler:
and isinstance(context.job_queue, JobQueue)
and isinstance(context.chat_data, dict)
and isinstance(context.bot_data, dict)
and (
(
isinstance(context.user_data, dict)
and (
isinstance(update.message, Message)
or isinstance(update.edited_message, Message)
)
)
or (
context.user_data is None
and (
isinstance(update.channel_post, Message)
or isinstance(update.edited_channel_post, Message)
)
)
)
and isinstance(context.user_data, dict)
)
def callback_regex1(self, update, context):
+12
View File
@@ -401,6 +401,18 @@ class TestUpdateWithoutRequest(UpdateTestBase):
cached = update.effective_sender
assert cached is sender
def test_effective_sender_signed_channel_post(self):
# channel_post with signatures can have its from_user
user = User(1, "", False)
post = Message(
1, dtm.datetime.utcnow(), Chat(1, ""), author_signature="", from_user=user, text="Text"
)
update = Update(update_id=1, channel_post=post)
assert update.effective_sender == update.effective_user == user
update = Update(update_id=2, edited_channel_post=post)
assert update.effective_sender == update.effective_user == user
def test_effective_message(self, update):
# Test that it's sometimes None per docstring
eff_message = update.effective_message