Skip to content

Commit

Permalink
add gift_code and fix chat_ttl_changed exception
Browse files Browse the repository at this point in the history
Signed-off-by: eyMarv <[email protected]>
  • Loading branch information
eyMarv committed Feb 28, 2024
1 parent 1247731 commit 00695d3
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 1 deletion.
9 changes: 9 additions & 0 deletions pyrogram/enums/message_service_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,14 @@ class MessageServiceType(AutoName):
GIVEAWAY_RESULT = auto()
"Giveaway Result"

GIFT_CODE = auto()
"Gift code"

REQUESTED_CHAT = auto()
"Requested chat"

CHAT_TTL_CHANGED = auto()
"Chat TTL changed"

BOOST_APPLY = auto()
"Boost apply"
76 changes: 76 additions & 0 deletions pyrogram/types/messages_and_media/gift_code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
#
# This file is part of Pyrogram.
#
# Pyrogram is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Pyrogram is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.

from pyrogram import raw, types, utils
from ..object import Object


class GiftCode(Object):
"""Contains gift code data.
Parameters:
via_giveaway (``bool``):
True if the gift code is received via giveaway.
unclaimed (``bool``):
True if the gift code is unclaimed.
boost_peer (:obj:`~pyrogram.types.Chat`):
The channel where the gift code was won.
months (``int``):
Number of months of subscription.
slug (``str``):
Identifier of gift code.
You can combine it with `t.me/giftcode/{slug}`
to get link for this gift.
"""

def __init__(
self,
*,
via_giveaway: bool,
unclaimed: bool,
boost_peer,
months: int,
slug: str
):
super().__init__()

self.via_giveaway = via_giveaway
self.unclaimed = unclaimed
self.boost_peer = boost_peer
self.months = months
self.slug = slug

@staticmethod
def _parse(client, giftcode: "raw.types.MessageActionGiftCode", chats):
peer = chats.get(utils.get_raw_peer_id(giftcode.boost_peer))

return GiftCode(
via_giveaway=giftcode.via_giveaway,
unclaimed=giftcode.unclaimed,
boost_peer=types.Chat._parse_chat(client, peer) if peer else None,
months=giftcode.months,
slug=giftcode.slug
)

@property
def link(self) -> str:
return f"https://t.me/giftcode/{self.slug}"
2 changes: 1 addition & 1 deletion pyrogram/types/messages_and_media/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,7 @@ async def _parse(
)

parsed_message.service = enums.MessageServiceType.PINNED_MESSAGE
except MessageIdsEmpty:
except Exception:
pass

if isinstance(action, raw.types.MessageActionGameScore):
Expand Down

0 comments on commit 00695d3

Please sign in to comment.