mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
Add getting user from chat_boost
This commit is contained in:
parent
6d655330af
commit
252f3ca879
1 changed files with 9 additions and 0 deletions
|
|
@ -3,6 +3,7 @@ from typing import Any, Awaitable, Callable, Dict, Optional
|
|||
|
||||
from aiogram.dispatcher.middlewares.base import BaseMiddleware
|
||||
from aiogram.types import Chat, InaccessibleMessage, TelegramObject, Update, User
|
||||
from aiogram.types.chat_boost_source_premium import ChatBoostSourcePremium
|
||||
|
||||
EVENT_CONTEXT_KEY = "event_context"
|
||||
|
||||
|
|
@ -115,6 +116,14 @@ class UserContextMiddleware(BaseMiddleware):
|
|||
if event.message_reaction_count:
|
||||
return EventContext(chat=event.message_reaction_count.chat)
|
||||
if event.chat_boost:
|
||||
# We only check the premium source, because only it has a sender user,
|
||||
# other sources have a user, but it is not the sender, but the recipient
|
||||
if isinstance(event.chat_boost.boost.source, ChatBoostSourcePremium):
|
||||
return EventContext(
|
||||
chat=event.chat_boost.chat,
|
||||
user=event.chat_boost.boost.source.user,
|
||||
)
|
||||
|
||||
return EventContext(chat=event.chat_boost.chat)
|
||||
if event.removed_chat_boost:
|
||||
return EventContext(chat=event.removed_chat_boost.chat)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue