From 6be799d21a55c2838ebc64c6ae65b6444d592388 Mon Sep 17 00:00:00 2001 From: KurimuzonAkuma Date: Sun, 29 Oct 2023 10:36:26 +0300 Subject: [PATCH] Moved apply_boost to premium section --- pyrogram/methods/__init__.py | 2 + pyrogram/methods/premium/__init__.py | 24 ++++++ .../{stories => premium}/apply_boost.py | 12 ++- pyrogram/methods/stories/__init__.py | 2 - pyrogram/types/messages_and_media/__init__.py | 3 +- .../types/messages_and_media/message_story.py | 4 +- pyrogram/types/messages_and_media/my_boost.py | 79 +++++++++++++++++++ 7 files changed, 118 insertions(+), 8 deletions(-) create mode 100644 pyrogram/methods/premium/__init__.py rename pyrogram/methods/{stories => premium}/apply_boost.py (82%) create mode 100644 pyrogram/types/messages_and_media/my_boost.py diff --git a/pyrogram/methods/__init__.py b/pyrogram/methods/__init__.py index 18fc8391..f3d164b5 100644 --- a/pyrogram/methods/__init__.py +++ b/pyrogram/methods/__init__.py @@ -25,6 +25,7 @@ from .decorators import Decorators from .invite_links import InviteLinks from .messages import Messages from .password import Password +from .premium import Premium from .users import Users from .stories import Stories from .utilities import Utilities @@ -36,6 +37,7 @@ class Methods( Bots, Contacts, Password, + Premium, Chats, Users, Stories, diff --git a/pyrogram/methods/premium/__init__.py b/pyrogram/methods/premium/__init__.py new file mode 100644 index 00000000..5f68ffc3 --- /dev/null +++ b/pyrogram/methods/premium/__init__.py @@ -0,0 +1,24 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-present Dan +# +# 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 . + +from .apply_boost import ApplyBoost + +class Premium( + ApplyBoost, +): + pass diff --git a/pyrogram/methods/stories/apply_boost.py b/pyrogram/methods/premium/apply_boost.py similarity index 82% rename from pyrogram/methods/stories/apply_boost.py rename to pyrogram/methods/premium/apply_boost.py index 725157f6..d3a253cc 100644 --- a/pyrogram/methods/stories/apply_boost.py +++ b/pyrogram/methods/premium/apply_boost.py @@ -20,6 +20,7 @@ from typing import Union import pyrogram from pyrogram import raw +from pyrogram import types class ApplyBoost: @@ -36,7 +37,7 @@ class ApplyBoost: Unique identifier (int) or username (str) of the target chat. Returns: - ``str``: On success, a bool is returned. + :obj:`~pyrogram.types.MyBoost`: On success, a boost object is returned. Example: .. code-block:: python @@ -45,9 +46,14 @@ class ApplyBoost: app.apply_boost(chat_id) """ r = await self.invoke( - raw.functions.stories.ApplyBoost( + raw.functions.premium.ApplyBoost( peer=await self.resolve_peer(chat_id), ) ) - return r + return types.MyBoost._parse( + self, + r.my_boosts[0], + {i.id: i for i in r.users}, + {i.id: i for i in r.chats} + ) diff --git a/pyrogram/methods/stories/__init__.py b/pyrogram/methods/stories/__init__.py index a256a80e..c034cd37 100644 --- a/pyrogram/methods/stories/__init__.py +++ b/pyrogram/methods/stories/__init__.py @@ -16,7 +16,6 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -from .apply_boost import ApplyBoost from .can_send_story import CanSendStory from .copy_story import CopyStory from .delete_stories import DeleteStories @@ -35,7 +34,6 @@ from .read_stories import ReadStories from .send_story import SendStory class Stories( - ApplyBoost, CanSendStory, CopyStory, DeleteStories, diff --git a/pyrogram/types/messages_and_media/__init__.py b/pyrogram/types/messages_and_media/__init__.py index 5060e9db..ebba631e 100644 --- a/pyrogram/types/messages_and_media/__init__.py +++ b/pyrogram/types/messages_and_media/__init__.py @@ -51,6 +51,7 @@ from .web_app_data import WebAppData from .web_page import WebPage from .message_reactions import MessageReactions from .message_story import MessageStory +from .my_boost import MyBoost __all__ = [ "Animation", "Audio", "Contact", "Document", "ForumTopic", "ForumTopicCreated", @@ -58,5 +59,5 @@ __all__ = [ "GeneralTopicUnhidden", "Game", "Location", "Message", "MessageEntity", "Photo", "Thumbnail", "StrippedThumbnail", "Story", "StoryDeleted", "StorySkipped", "StoryViews", "Poll", "PollOption", "Sticker", "Venue", "Video", "VideoNote", "Voice", "WebPage", "Dice", "Reaction", "WebAppData", - "MessageReactions", "MessageStory" + "MessageReactions", "MessageStory", "MyBoost" ] diff --git a/pyrogram/types/messages_and_media/message_story.py b/pyrogram/types/messages_and_media/message_story.py index 5bda8169..11a6dad5 100644 --- a/pyrogram/types/messages_and_media/message_story.py +++ b/pyrogram/types/messages_and_media/message_story.py @@ -25,8 +25,8 @@ class MessageStory(Object): """Contains information about a forwarded story. Parameters: - chat_id (``int``): - Unique user identifier of story sender. + chat (:obj:`~pyrogram.types.Chat`): + Conversation the story belongs to. story_id (``int``): Unique story identifier. diff --git a/pyrogram/types/messages_and_media/my_boost.py b/pyrogram/types/messages_and_media/my_boost.py new file mode 100644 index 00000000..90060da7 --- /dev/null +++ b/pyrogram/types/messages_and_media/my_boost.py @@ -0,0 +1,79 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-present Dan +# +# 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 . + +from datetime import datetime + +import pyrogram +from pyrogram import raw, types, utils +from ..object import Object + + +class MyBoost(Object): + """Contains information about boost. + + Parameters: + slot (``int``): + Unique user identifier of story sender. + + date (:py:obj:`~datetime.datetime`): + Date the boost was sent. + + expire_date (:py:obj:`~datetime.datetime`): + Point in time when the boost will expire. + + chat (:obj:`~pyrogram.types.Chat`): + Conversation the boost belongs to. + + cooldown_until_date (:py:obj:`~datetime.datetime`): + Point in time when you'll be able to boost again. + + """ + + def __init__( + self, + *, + slot: int, + date: datetime, + expire_date: datetime, + chat: "types.Chat", + cooldown_until_date: datetime + ): + super().__init__() + + self.slot = slot + self.date = date + self.expire_date = expire_date + self.chat = chat + self.cooldown_until_date = cooldown_until_date + + @staticmethod + def _parse(client: "pyrogram.Client", my_boost: "raw.types.MyBoost", users, chats) -> "MyBoost": + peer_id = utils.get_raw_peer_id(my_boost.peer) + + if isinstance(my_boost.peer, raw.types.PeerChannel): + chat = types.Chat._parse_channel_chat(client, chats.get(peer_id, None)) + else: + chat = types.Chat._parse_user_chat(client, users.get(peer_id, None)) + + return MyBoost( + slot=my_boost.slot, + date=utils.timestamp_to_datetime(my_boost.date), + expire_date=utils.timestamp_to_datetime(my_boost.expire_date), + chat=chat, + cooldown_until_date=utils.timestamp_to_datetime(my_boost.cooldown_until_date), + )