Skip to content

Commit

Permalink
Allow accessing from_user by user, sender_user property method
Browse files Browse the repository at this point in the history
  • Loading branch information
z44d committed Sep 25, 2024
1 parent 3f32729 commit 73425d7
Show file tree
Hide file tree
Showing 15 changed files with 110 additions and 11 deletions.
18 changes: 14 additions & 4 deletions tgram/bound/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
from .message import MessageB
from .callback_query import CallbackB
from .user import UserB
from .chat_join_request import ChatJoinRequestB
from .chat_member_updated import ChatMemberUpdatedB
from .chat import ChatB
from .chosen_inline_result import ChosenInlineResultB
from .inline_query import InlineQueryB
from .message import MessageB
from .paid_media_purchased import PaidMediaPurchasedB
from .pre_checkout_query import PreCheckoutQueryB
from .shipping_query import ShippingQueryB
from .user import UserB

from tgram import sync

Expand All @@ -15,10 +20,15 @@
sync.wrap(obj)

__all__ = [
"MessageB",
"CallbackB",
"UserB",
"ChatJoinRequestB",
"ChatMemberUpdatedB",
"ChatB",
"ChosenInlineResultB",
"InlineQueryB",
"MessageB",
"PaidMediaPurchasedB",
"PreCheckoutQueryB",
"ShippingQueryB",
"UserB",
]
8 changes: 7 additions & 1 deletion tgram/bound/callback_query.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import tgram

from typing import List, Union
from typing import List, Union, Optional


class CallbackB:
Expand Down Expand Up @@ -113,3 +113,9 @@ async def edit_message_live_location(
proximity_alert_radius=proximity_alert_radius,
reply_markup=reply_markup,
)

@property
def user(self: "tgram.types.CallbackQuery") -> Optional["tgram.types.User"]:
return self.from_user

sender_user = user
11 changes: 11 additions & 0 deletions tgram/bound/chat_join_request.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import tgram

from typing import Optional


class ChatJoinRequestB:
@property
def user(self: "tgram.types.ChatJoinRequest") -> Optional["tgram.types.User"]:
return self.from_user

sender_user = user
11 changes: 11 additions & 0 deletions tgram/bound/chat_member_updated.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import tgram

from typing import Optional


class ChatMemberUpdatedB:
@property
def user(self: "tgram.types.ChatMemberUpdated") -> Optional["tgram.types.User"]:
return self.from_user

sender_user = user
11 changes: 11 additions & 0 deletions tgram/bound/chosen_inline_result.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import tgram

from typing import Optional


class ChosenInlineResultB:
@property
def user(self: "tgram.types.ChosenInlineResult") -> Optional["tgram.types.User"]:
return self.from_user

sender_user = user
8 changes: 7 additions & 1 deletion tgram/bound/inline_query.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import tgram

from typing import List
from typing import List, Optional


class InlineQueryB:
Expand All @@ -20,3 +20,9 @@ async def answer(
next_offset=next_offset,
button=button,
)

@property
def user(self: "tgram.types.InlineQuery") -> Optional["tgram.types.User"]:
return self.from_user

sender_user = user
6 changes: 6 additions & 0 deletions tgram/bound/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,12 @@ def link(self: "tgram.types.Message") -> Optional[str]:
else None
)

@property
def user(self: "tgram.types.Message") -> Optional["tgram.types.User"]:
return self.from_user

sender_user = user

@property
def __reply_param(self) -> "tgram.types.ReplyParameters":
return tgram.types.ReplyParameters(self.id, allow_sending_without_reply=True)
11 changes: 11 additions & 0 deletions tgram/bound/paid_media_purchased.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import tgram

from typing import Optional


class PaidMediaPurchasedB:
@property
def user(self: "tgram.types.PaidMediaPurchased") -> Optional["tgram.types.User"]:
return self.from_user

sender_user = user
8 changes: 8 additions & 0 deletions tgram/bound/pre_checkout_query.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import tgram

from typing import Optional


class PreCheckoutQueryB:
async def answer(
Expand All @@ -10,3 +12,9 @@ async def answer(
return await self._me.answer_pre_checkout_query(
pre_checkout_query_id=self.id, ok=ok, error_message=error_message
)

@property
def user(self: "tgram.types.PreCheckoutQuery") -> Optional["tgram.types.User"]:
return self.from_user

sender_user = user
11 changes: 11 additions & 0 deletions tgram/bound/shipping_query.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import tgram

from typing import Optional


class ShippingQueryB:
@property
def user(self: "tgram.types.ShippingQuery") -> Optional["tgram.types.User"]:
return self.from_user

sender_user = user
3 changes: 2 additions & 1 deletion tgram/types/_chat_join_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
from .type_ import Type_

from typing import Optional
from tgram import bound


class ChatJoinRequest(Type_):
class ChatJoinRequest(Type_, bound.ChatJoinRequestB):
"""
Represents a join request sent to a chat.
Expand Down
4 changes: 3 additions & 1 deletion tgram/types/_chat_member_updated.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@

from typing import Union, Optional

from tgram import bound

class ChatMemberUpdated(Type_):

class ChatMemberUpdated(Type_, bound.ChatMemberUpdatedB):
"""
This object represents changes in the status of a chat member.
Expand Down
4 changes: 3 additions & 1 deletion tgram/types/_chosen_inline_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@

from typing import Optional

from tgram import bound

class ChosenInlineResult(Type_):

class ChosenInlineResult(Type_, bound.ChosenInlineResultB):
"""
Represents a result of an inline query that was chosen by the user and sent to their chat partner.
Expand Down
4 changes: 3 additions & 1 deletion tgram/types/_paid_media_purchased.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

from typing import Optional

from tgram import bound

class PaidMediaPurchased(Type_):

class PaidMediaPurchased(Type_, bound.PaidMediaPurchasedB):
"""
This object contains information about a paid media purchase.
Expand Down
3 changes: 2 additions & 1 deletion tgram/types/_shipping_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
from .type_ import Type_

from typing import Optional
from tgram import bound


class ShippingQuery(Type_):
class ShippingQuery(Type_, bound.ShippingQueryB):
"""
This object contains information about an incoming shipping query.
Expand Down

0 comments on commit 73425d7

Please sign in to comment.