Skip to content

Commit

Permalink
Update some types to new layer
Browse files Browse the repository at this point in the history
  • Loading branch information
KurimuzonAkuma committed Mar 7, 2025
1 parent b4b01fe commit 83f675d
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 6 deletions.
6 changes: 6 additions & 0 deletions pyrogram/types/messages_and_media/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,9 @@ class Message(Object, Update):
reactions (List of :obj:`~pyrogram.types.Reaction`):
List of the reactions to this message.
paid_message_stars (``int``, *optional*):
Number of stars for a paid message.
raw (:obj:`~pyrogram.raw.types.Message`, *optional*):
The raw message object, as received from the Telegram API.
Expand Down Expand Up @@ -584,6 +587,7 @@ def __init__(
"types.ForceReply"
] = None,
reactions: List["types.Reaction"] = None,
paid_message_stars: int = None,
raw: "raw.types.Message" = None
):
super().__init__(client)
Expand Down Expand Up @@ -703,6 +707,7 @@ def __init__(
self.connected_website = connected_website
self.contact_registered = contact_registered
self.reactions = reactions
self.paid_message_stars = paid_message_stars
self.raw = raw

@staticmethod
Expand Down Expand Up @@ -1287,6 +1292,7 @@ async def _parse(
reply_markup=reply_markup,
reactions=reactions,
from_offline=getattr(message, "offline", None),
paid_message_stars=getattr(message, "paid_message_stars", None),
raw=message,
client=client
)
Expand Down
23 changes: 19 additions & 4 deletions pyrogram/types/user_and_chats/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,13 @@ class Chat(Object):
Invoking this method will update the value of this flag.
Returned only in :meth:`~pyrogram.Client.get_chat`
send_paid_messages_stars (``int``, *optional*):
The number of stars you need to pay to send a message to this chat.
is_paid_messages_available (``bool``, *optional*):
True, if paid messages are available in this chat.
Returned only in :meth:`~pyrogram.Client.get_chat`
raw (:obj:`~pyrogram.raw.types.UserFull` | :obj:`~pyrogram.raw.types.ChatFull` | :obj:`~pyrogram.raw.types.ChannelFull`, *optional*):
The raw chat or user object, as received from the Telegram API.
Expand Down Expand Up @@ -556,6 +563,8 @@ def __init__(
theme_emoji: Optional[str] = None,
unread_count: Optional[int] = None,
view_forum_as_messages: Optional[bool] = None,
send_paid_messages_stars: Optional[int] = None,
is_paid_messages_available: Optional[bool] = None,
raw: Optional[Union["raw.types.UserFull", "raw.types.ChatFull", "raw.types.ChannelFull"]] = None
):
super().__init__(client)
Expand Down Expand Up @@ -673,10 +682,12 @@ def __init__(
self.theme_emoji = theme_emoji
self.unread_count = unread_count
self.view_forum_as_messages = view_forum_as_messages
self.send_paid_messages_stars = send_paid_messages_stars
self.is_paid_messages_available = is_paid_messages_available
self.raw = raw

@staticmethod
def _parse_user_chat(client, user: raw.types.User) -> Optional["Chat"]:
def _parse_user_chat(client, user: "raw.types.User") -> Optional["Chat"]:
if user is None or isinstance(user, raw.types.UserEmpty):
return None

Expand All @@ -702,12 +713,13 @@ def _parse_user_chat(client, user: raw.types.User) -> Optional["Chat"]:
dc_id=getattr(getattr(user, "photo", None), "dc_id", None),
reply_color=types.ChatColor._parse(getattr(user, "color", None)),
profile_color=types.ChatColor._parse_profile_color(getattr(user, "profile_color", None)),
send_paid_messages_stars=getattr(user, "send_paid_messages_stars", None),
raw=user,
client=client
)

@staticmethod
def _parse_chat_chat(client, chat: raw.types.Chat) -> Optional["Chat"]:
def _parse_chat_chat(client, chat: "raw.types.Chat") -> Optional["Chat"]:
if chat is None or isinstance(chat, raw.types.ChatEmpty):
return None

Expand Down Expand Up @@ -745,7 +757,7 @@ def _parse_chat_chat(client, chat: raw.types.Chat) -> Optional["Chat"]:
)

@staticmethod
def _parse_channel_chat(client, channel: raw.types.Channel) -> Optional["Chat"]:
def _parse_channel_chat(client, channel: "raw.types.Channel") -> Optional["Chat"]:
if channel is None:
return None

Expand Down Expand Up @@ -793,14 +805,15 @@ def _parse_channel_chat(client, channel: raw.types.Channel) -> Optional["Chat"]:
reply_color=types.ChatColor._parse(getattr(channel, "color", None)),
profile_color=types.ChatColor._parse(getattr(channel, "profile_color", None)),
subscription_until_date=utils.timestamp_to_datetime(getattr(channel, "subscription_until_date", None)),
send_paid_messages_stars=getattr(channel, "send_paid_messages_stars", None),
raw=channel,
client=client
)

@staticmethod
def _parse(
client,
message: Union[raw.types.Message, raw.types.MessageService],
message: Union["raw.types.Message", "raw.types.MessageService"],
users: dict,
chats: dict,
is_chat: bool
Expand Down Expand Up @@ -907,6 +920,7 @@ async def _parse_full_user(client: "pyrogram.Client", user: "raw.types.UserFull"
getattr(user, "bot_verification", None),
users
)
parsed_chat.send_paid_messages_stars = getattr(user, "send_paid_messages_stars", None)

return parsed_chat

Expand Down Expand Up @@ -1048,6 +1062,7 @@ async def _parse_full_channel(client: "pyrogram.Client", channel: "raw.types.Cha
)
parsed_chat.gifts_count = getattr(channel, "stargifts_count", None)
parsed_chat.sticker_set_name = getattr(channel.stickerset, "short_name", None)
parsed_chat.is_paid_messages_available = getattr(channel, "paid_messages_available", None)

return parsed_chat

Expand Down
34 changes: 32 additions & 2 deletions pyrogram/types/user_and_chats/chat_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,21 @@ class ChatSettings(Object):
business_bot_manage_url (``str``, *optional*):
Contains a deep link used to open a management menu in the business bot.
charge_paid_message_stars (``int``, *optional*):
Number of stars for the paid message.
registration_date (``str``, *optional*):
Date when the user registered on Telegram, in format MM.YYYY.
phone_country (``str``, *optional*):
Country code of the user's phone number.
name_change_date (:py:obj:`~datetime.datetime`, *optional*):
Date when the user's name was changed.
photo_change_date (:py:obj:`~datetime.datetime`, *optional*):
Date when the user's photo was changed.
"""

def __init__(
Expand All @@ -98,7 +113,12 @@ def __init__(
request_chat_title: Optional[str] = None,
request_chat_date: Optional[datetime] = None,
business_bot: Optional["types.User"] = None,
business_bot_manage_url: Optional[str] = None
business_bot_manage_url: Optional[str] = None,
charge_paid_message_stars: Optional[int] = None,
registration_date: Optional[str] = None,
phone_country: Optional[str] = None,
name_change_date: Optional[datetime] = None,
photo_change_date: Optional[datetime] = None
):
super().__init__()

Expand All @@ -118,6 +138,11 @@ def __init__(
self.request_chat_date = request_chat_date
self.business_bot = business_bot
self.business_bot_manage_url = business_bot_manage_url
self.charge_paid_message_stars = charge_paid_message_stars
self.registration_date = registration_date
self.phone_country = phone_country
self.name_change_date = name_change_date
self.photo_change_date = photo_change_date

@staticmethod
def _parse(client, chat_settings: "raw.types.PeerSettings", users) -> Optional["ChatSettings"]:
Expand All @@ -140,5 +165,10 @@ def _parse(client, chat_settings: "raw.types.PeerSettings", users) -> Optional["
request_chat_title=getattr(chat_settings, "request_chat_title", None),
request_chat_date=utils.timestamp_to_datetime(getattr(chat_settings, "request_chat_date", None)),
business_bot=types.User._parse(client, users.get(getattr(chat_settings, "business_bot_id", None))),
business_bot_manage_url=getattr(chat_settings, "business_bot_manage_url", None)
business_bot_manage_url=getattr(chat_settings, "business_bot_manage_url", None),
charge_paid_message_stars=getattr(chat_settings, "charge_paid_message_stars", None),
registration_date=getattr(chat_settings, "registration_month", None),
phone_country=getattr(chat_settings, "phone_country", None),
name_change_date=utils.timestamp_to_datetime(getattr(chat_settings, "name_change_date", None)),
photo_change_date=utils.timestamp_to_datetime(getattr(chat_settings, "photo_change_date", None)),
)
6 changes: 6 additions & 0 deletions pyrogram/types/user_and_chats/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ class User(Object, Update):
has_main_web_app (``bool``, *optional*):
True, if the bot has a main Web App. Returned only in get_me.
send_paid_messages_stars (``int``, *optional*):
The number of stars you need to pay to send a message to this user.
raw (:obj:`~pyrogram.raw.base.User` | :obj:`~pyrogram.raw.base.UserStatus`, *optional*):
The raw user or user status object, as received from the Telegram API.
Expand Down Expand Up @@ -249,6 +252,7 @@ def __init__(
can_join_groups: bool = None,
can_read_all_group_messages: bool = None,
has_main_web_app: bool = None,
send_paid_messages_stars: int = None,
raw: Union["raw.base.User", "raw.base.UserStatus"] = None
):
super().__init__(client)
Expand Down Expand Up @@ -294,6 +298,7 @@ def __init__(
self.can_join_groups = can_join_groups
self.can_read_all_group_messages = can_read_all_group_messages
self.has_main_web_app = has_main_web_app
self.send_paid_messages_stars = send_paid_messages_stars
self.raw = raw

@property
Expand Down Expand Up @@ -353,6 +358,7 @@ def _parse(client, user: "raw.base.User") -> Optional["User"]:
can_join_groups=getattr(user, "bot_nochats", None),
can_read_all_group_messages=getattr(user, "bot_chat_history", None),
has_main_web_app=getattr(user, "bot_has_main_app", None),
send_paid_messages_stars=getattr(user, "send_paid_messages_stars", None),
raw=user,
client=client
)
Expand Down

0 comments on commit 83f675d

Please sign in to comment.