Moved apply_boost to premium section

This commit is contained in:
KurimuzonAkuma 2023-10-29 10:36:26 +03:00
parent 7f3a2916fd
commit 6be799d21a
7 changed files with 118 additions and 8 deletions

View File

@ -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,

View File

@ -0,0 +1,24 @@
# 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 .apply_boost import ApplyBoost
class Premium(
ApplyBoost,
):
pass

View File

@ -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}
)

View File

@ -16,7 +16,6 @@
# 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 .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,

View File

@ -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"
]

View File

@ -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.

View File

@ -0,0 +1,79 @@
# 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 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),
)