Skip to content

Commit

Permalink
Update API schema to Layer 190
Browse files Browse the repository at this point in the history
  • Loading branch information
KurimuzonAkuma committed Oct 14, 2024
1 parent f7d932c commit c6d18ff
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 33 deletions.
8 changes: 4 additions & 4 deletions compiler/api/source/main_api.tl
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,13 @@ messageActionSetChatTheme#aa786345 emoticon:string = MessageAction;
messageActionChatJoinedByRequest#ebbca3cb = MessageAction;
messageActionWebViewDataSentMe#47dd8079 text:string data:string = MessageAction;
messageActionWebViewDataSent#b4c38cb5 text:string = MessageAction;
messageActionGiftPremium#c83d6aec flags:# currency:string amount:long months:int crypto_currency:flags.0?string crypto_amount:flags.0?long = MessageAction;
messageActionGiftPremium#6c6274fa flags:# currency:string amount:long months:int crypto_currency:flags.0?string crypto_amount:flags.0?long message:flags.1?TextWithEntities = MessageAction;
messageActionTopicCreate#d999256 flags:# title:string icon_color:int icon_emoji_id:flags.0?long = MessageAction;
messageActionTopicEdit#c0944820 flags:# title:flags.0?string icon_emoji_id:flags.1?long closed:flags.2?Bool hidden:flags.3?Bool = MessageAction;
messageActionSuggestProfilePhoto#57de635e photo:Photo = MessageAction;
messageActionRequestedPeer#31518e9b button_id:int peers:Vector<Peer> = MessageAction;
messageActionSetChatWallPaper#5060a3f4 flags:# same:flags.0?true for_both:flags.1?true wallpaper:WallPaper = MessageAction;
messageActionGiftCode#678c2e09 flags:# via_giveaway:flags.0?true unclaimed:flags.2?true boost_peer:flags.1?Peer months:int slug:string currency:flags.2?string amount:flags.2?long crypto_currency:flags.3?string crypto_amount:flags.3?long = MessageAction;
messageActionGiftCode#56d03994 flags:# via_giveaway:flags.0?true unclaimed:flags.2?true boost_peer:flags.1?Peer months:int slug:string currency:flags.2?string amount:flags.2?long crypto_currency:flags.3?string crypto_amount:flags.3?long message:flags.4?TextWithEntities = MessageAction;
messageActionGiveawayLaunch#a80f51e4 flags:# stars:flags.0?long = MessageAction;
messageActionGiveawayResults#87e2f155 flags:# stars:flags.0?true winners_count:int unclaimed_count:int = MessageAction;
messageActionBoostApply#cc02aa6d boosts:int = MessageAction;
Expand Down Expand Up @@ -1484,7 +1484,7 @@ help.premiumPromo#5334759c status_text:string status_entities:Vector<MessageEnti

inputStorePaymentPremiumSubscription#a6751e66 flags:# restore:flags.0?true upgrade:flags.1?true = InputStorePaymentPurpose;
inputStorePaymentGiftPremium#616f7fe8 user_id:InputUser currency:string amount:long = InputStorePaymentPurpose;
inputStorePaymentPremiumGiftCode#a3805f3f flags:# users:Vector<InputUser> boost_peer:flags.0?InputPeer currency:string amount:long = InputStorePaymentPurpose;
inputStorePaymentPremiumGiftCode#fb790393 flags:# users:Vector<InputUser> boost_peer:flags.0?InputPeer currency:string amount:long message:flags.1?TextWithEntities = InputStorePaymentPurpose;
inputStorePaymentPremiumGiveaway#160544ca flags:# only_new_subscribers:flags.0?true winners_are_visible:flags.3?true boost_peer:InputPeer additional_peers:flags.1?Vector<InputPeer> countries_iso2:flags.2?Vector<string> prize_description:flags.4?string random_id:long until_date:int currency:string amount:long = InputStorePaymentPurpose;
inputStorePaymentStarsTopup#dddd0f56 stars:long currency:string amount:long = InputStorePaymentPurpose;
inputStorePaymentStarsGift#1d741ef7 user_id:InputUser stars:long currency:string amount:long = InputStorePaymentPurpose;
Expand Down Expand Up @@ -2573,4 +2573,4 @@ smsjobs.finishJob#4f1ebf24 flags:# job_id:string error:flags.0?string = Bool;

fragment.getCollectibleInfo#be1e85ba collectible:InputCollectible = fragment.CollectibleInfo;

// LAYER 189
// LAYER 190
29 changes: 21 additions & 8 deletions pyrogram/types/messages_and_media/gift_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
# 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 typing import Optional, List

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

Expand All @@ -32,13 +34,19 @@ class GiftCode(Object):
You can combine it with `t.me/giftcode/{slug}`
to get link for this gift.
via_giveaway (``bool``):
text (``str``, *optional*):
Text message.
entities (List of :obj:`~pyrogram.types.MessageEntity`, *optional*):
For text messages, special entities like usernames, URLs, bot commands, etc. that appear in the text.
via_giveaway (``bool``, *optional*):
True if the gift code is received via giveaway.
is_unclaimed (``bool``):
is_unclaimed (``bool``, *optional*):
True if the winner for the corresponding Telegram Premium subscription wasn't chosen.
boosted_chat (:obj:`~pyrogram.types.Chat`):
boosted_chat (:obj:`~pyrogram.types.Chat`, *optional*):
The channel where the gift code was won.
link (``str``, *property*):
Expand All @@ -50,28 +58,33 @@ def __init__(
*,
months: int,
slug: str,
via_giveaway: bool = None,
is_unclaimed: bool = None,
boosted_chat: "types.Chat" = None
text: Optional[str] = None,
entities: List["types.MessageEntity"] = None,
via_giveaway: Optional[bool] = None,
is_unclaimed: Optional[bool] = None,
boosted_chat: Optional["types.Chat"] = None
):
super().__init__()

self.months = months
self.slug = slug
self.text = text
self.entities = entities
self.via_giveaway = via_giveaway
self.is_unclaimed = is_unclaimed
self.boosted_chat = boosted_chat

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

return GiftCode(
months=giftcode.months,
slug=giftcode.slug,
via_giveaway=getattr(giftcode, "via_giveaway"),
is_unclaimed=getattr(giftcode, "unclaimed"),
boosted_chat=types.Chat._parse_chat(client, peer) if peer else None
boosted_chat=types.Chat._parse_chat(client, peer) if peer else None,
**utils.parse_text_with_entities(client, getattr(giftcode, "message", None), users)
)

@property
Expand Down
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 @@ -789,7 +789,7 @@ async def _parse(
stars_amount = getattr(action, "stars", None)
service_type = enums.MessageServiceType.GIVEAWAY_LAUNCH
elif isinstance(action, raw.types.MessageActionGiftCode):
gift_code = types.GiftCode._parse(client, action, chats)
gift_code = types.GiftCode._parse(client, action, users, chats)
service_type = enums.MessageServiceType.GIFT_CODE
elif isinstance(action, (raw.types.MessageActionRequestedPeer, raw.types.MessageActionRequestedPeerSentMe)):
requested_chats = types.RequestedChats._parse(client, action)
Expand Down
22 changes: 2 additions & 20 deletions pyrogram/types/messages_and_media/star_gift.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,6 @@ async def _parse_user_star_gift(
user_star_gift: "raw.types.UserStarGift",
users: dict
) -> "StarGift":
text = None
entities = None

if getattr(user_star_gift, "message", None):
text = user_star_gift.message.text
entities = [types.MessageEntity._parse(client, entity, users) for entity in user_star_gift.message.entities]
entities = types.List(filter(lambda x: x is not None, entities))

doc = user_star_gift.gift.sticker
attributes = {type(i): i for i in doc.attributes}

Expand All @@ -159,9 +151,8 @@ async def _parse_user_star_gift(
is_name_hidden=getattr(user_star_gift, "name_hidden", None),
is_saved=not user_star_gift.unsaved if getattr(user_star_gift, "unsaved", None) else None,
from_user=types.User._parse(client, users.get(user_star_gift.from_id)) if getattr(user_star_gift, "from_id", None) else None,
text=text,
entities=entities,
message_id=getattr(user_star_gift, "msg_id", None),
**utils.parse_text_with_entities(client, getattr(user_star_gift, "message", None), users),
client=client
)

Expand All @@ -173,14 +164,6 @@ async def _parse_action(
) -> "StarGift":
action = message.action

text = None
entities = None

if getattr(action, "message", None):
text = action.message.text
entities = [types.MessageEntity._parse(client, entity, users) for entity in action.message.entities]
entities = types.List(filter(lambda x: x is not None, entities))

doc = action.gift.sticker
attributes = {type(i): i for i in doc.attributes}

Expand All @@ -196,9 +179,8 @@ async def _parse_action(
is_name_hidden=getattr(action, "name_hidden", None),
is_saved=getattr(action, "saved", None),
from_user=types.User._parse(client, users.get(utils.get_raw_peer_id(message.peer_id))),
text=text,
entities=entities,
message_id=message.id,
**utils.parse_text_with_entities(client, getattr(action, "message", None), users),
client=client
)

Expand Down
15 changes: 15 additions & 0 deletions pyrogram/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,3 +498,18 @@ def get_first_url(text):
matches = re.findall(r"(https?):\/\/([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])", text)

return f"{matches[0][0]}://{matches[0][1]}{matches[0][2]}" if matches else None


def parse_text_with_entities(client, message: "raw.types.TextWithEntities", users):
return {
"text": getattr(message, "text", None),
"entities": types.List(
filter(
lambda x: x is not None,
[
types.MessageEntity._parse(client, entity, users)
for entity in getattr(message, "entities", [])
]
)
) or None
}

0 comments on commit c6d18ff

Please sign in to comment.