mirror of
https://github.com/Mayuri-Chan/pyrofork.git
synced 2026-01-08 07:54:52 +00:00
pyrofork: Add get_available_effects method
Signed-off-by: wulan17 <wulan17@nusantararom.org>
This commit is contained in:
parent
3db7bd1dae
commit
8b52f1f71d
5 changed files with 155 additions and 1 deletions
|
|
@ -193,6 +193,7 @@ def pyrogram_api():
|
||||||
edit_inline_reply_markup
|
edit_inline_reply_markup
|
||||||
send_chat_action
|
send_chat_action
|
||||||
delete_messages
|
delete_messages
|
||||||
|
get_available_effects
|
||||||
get_messages
|
get_messages
|
||||||
get_media_group
|
get_media_group
|
||||||
get_chat_history
|
get_chat_history
|
||||||
|
|
@ -461,6 +462,7 @@ def pyrogram_api():
|
||||||
Photo
|
Photo
|
||||||
Thumbnail
|
Thumbnail
|
||||||
Audio
|
Audio
|
||||||
|
AvailableEffect
|
||||||
Document
|
Document
|
||||||
Animation
|
Animation
|
||||||
Video
|
Video
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ from .edit_message_media import EditMessageMedia
|
||||||
from .edit_message_reply_markup import EditMessageReplyMarkup
|
from .edit_message_reply_markup import EditMessageReplyMarkup
|
||||||
from .edit_message_text import EditMessageText
|
from .edit_message_text import EditMessageText
|
||||||
from .forward_messages import ForwardMessages
|
from .forward_messages import ForwardMessages
|
||||||
|
from .get_available_effects import GetAvailableEffects
|
||||||
from .get_chat_history import GetChatHistory
|
from .get_chat_history import GetChatHistory
|
||||||
from .get_chat_history_count import GetChatHistoryCount
|
from .get_chat_history_count import GetChatHistoryCount
|
||||||
from .get_custom_emoji_stickers import GetCustomEmojiStickers
|
from .get_custom_emoji_stickers import GetCustomEmojiStickers
|
||||||
|
|
@ -75,6 +76,7 @@ class Messages(
|
||||||
EditMessageMedia,
|
EditMessageMedia,
|
||||||
EditMessageText,
|
EditMessageText,
|
||||||
ForwardMessages,
|
ForwardMessages,
|
||||||
|
GetAvailableEffects,
|
||||||
GetMediaGroup,
|
GetMediaGroup,
|
||||||
GetMessages,
|
GetMessages,
|
||||||
SendAudio,
|
SendAudio,
|
||||||
|
|
|
||||||
60
pyrogram/methods/messages/get_available_effects.py
Normal file
60
pyrogram/methods/messages/get_available_effects.py
Normal file
|
|
@ -0,0 +1,60 @@
|
||||||
|
# Pyrogram - Telegram MTProto API Client Library for Python
|
||||||
|
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
|
||||||
|
# Copyright (C) 2022-present Mayuri-Chan <https://github.com/Mayuri-Chan>
|
||||||
|
#
|
||||||
|
# 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/>.
|
||||||
|
|
||||||
|
import logging
|
||||||
|
from typing import List
|
||||||
|
|
||||||
|
import pyrogram
|
||||||
|
from pyrogram import raw
|
||||||
|
from pyrogram import types
|
||||||
|
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class GetAvailableEffects:
|
||||||
|
async def get_available_effects(
|
||||||
|
self: "pyrogram.Client"
|
||||||
|
) -> List["types.AvailableEffect"]:
|
||||||
|
"""Get all available effects.
|
||||||
|
|
||||||
|
.. include:: /_includes/usable-by/users.rst
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
List of :obj:`~pyrogram.types.AvailableEffect`: A list of available effects is returned.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
# Get all available effects
|
||||||
|
await app.get_available_effects()
|
||||||
|
"""
|
||||||
|
r = await self.invoke(
|
||||||
|
raw.functions.messages.GetAvailableEffects(
|
||||||
|
hash=0
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
documents = {d.id: d for d in r.documents}
|
||||||
|
|
||||||
|
return types.List(
|
||||||
|
[
|
||||||
|
await types.AvailableEffect._parse(self, effect, documents.get(effect.effect_sticker_id, None))
|
||||||
|
for effect in r.effects
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
from .animation import Animation
|
from .animation import Animation
|
||||||
from .audio import Audio
|
from .audio import Audio
|
||||||
|
from .available_effect import AvailableEffect
|
||||||
from .contact import Contact
|
from .contact import Contact
|
||||||
from .dice import Dice
|
from .dice import Dice
|
||||||
from .document import Document
|
from .document import Document
|
||||||
|
|
@ -64,7 +65,7 @@ from .story_views import StoryViews
|
||||||
from .exported_story_link import ExportedStoryLink
|
from .exported_story_link import ExportedStoryLink
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"Animation", "Audio", "Contact", "Document", "Game", "GiftedPremium", "Giveaway", "GiveawayLaunched", "GiveawayResult", "Location", "MediaArea", "MediaAreaChannelPost", "MediaAreaCoordinates", "Message", "MessageEntity", "Photo", "Thumbnail",
|
"Animation", "Audio", "AvailableEffect", "Contact", "Document", "Game", "GiftedPremium", "Giveaway", "GiveawayLaunched", "GiveawayResult", "Location", "MediaArea", "MediaAreaChannelPost", "MediaAreaCoordinates", "Message", "MessageEntity", "Photo", "Thumbnail",
|
||||||
"StrippedThumbnail", "Poll", "PollOption", "Sticker", "StickerSet", "Venue", "Video", "VideoNote", "Voice", "WebPage", "WebPageEmpty", "WebPagePreview", "Dice",
|
"StrippedThumbnail", "Poll", "PollOption", "Sticker", "StickerSet", "Venue", "Video", "VideoNote", "Voice", "WebPage", "WebPageEmpty", "WebPagePreview", "Dice",
|
||||||
"Reaction", "WebAppData", "MessageReactions", "ReactionCount", "ReactionType", "MessageReactionUpdated", "MessageReactionCountUpdated", "MessageStory", "Story", "StoryDeleted", "StorySkipped", "StoryViews", "StoryForwardHeader", "StoriesPrivacyRules", "ExportedStoryLink"
|
"Reaction", "WebAppData", "MessageReactions", "ReactionCount", "ReactionType", "MessageReactionUpdated", "MessageReactionCountUpdated", "MessageStory", "Story", "StoryDeleted", "StorySkipped", "StoryViews", "StoryForwardHeader", "StoriesPrivacyRules", "ExportedStoryLink"
|
||||||
]
|
]
|
||||||
|
|
|
||||||
89
pyrogram/types/messages_and_media/available_effect.py
Normal file
89
pyrogram/types/messages_and_media/available_effect.py
Normal file
|
|
@ -0,0 +1,89 @@
|
||||||
|
# Pyrogram - Telegram MTProto API Client Library for Python
|
||||||
|
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
|
||||||
|
# Copyright (C) 2022-present Mayuri-Chan <https://github.com/Mayuri-Chan>
|
||||||
|
#
|
||||||
|
# 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 typing import Optional
|
||||||
|
|
||||||
|
from pyrogram import raw, types
|
||||||
|
from ..object import Object
|
||||||
|
|
||||||
|
|
||||||
|
class AvailableEffect(Object):
|
||||||
|
"""Contains information about available effect.
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
id (``int``):
|
||||||
|
Unique effect identifier.
|
||||||
|
|
||||||
|
emoji (:py:obj:`~datetime.datetime`):
|
||||||
|
Emoji that represents the effect.
|
||||||
|
|
||||||
|
effect_sticker_id (``int``):
|
||||||
|
sticker identifier that represents the effect.
|
||||||
|
|
||||||
|
sticker (:obj:`~pyrogram.types.Sticker`, *optional*):
|
||||||
|
Sticker that represents the effect.
|
||||||
|
|
||||||
|
is_premium (``bool``, *optional*):
|
||||||
|
Whether the effect is available only for premium users.
|
||||||
|
|
||||||
|
static_icon_id (``int``, *optional*):
|
||||||
|
Static icon identifier that represents the effect.
|
||||||
|
|
||||||
|
effect_animation_id (``int``, *optional*):
|
||||||
|
Animation identifier that represents the effect.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
*,
|
||||||
|
id: int,
|
||||||
|
emoji: str,
|
||||||
|
effect_sticker_id: int,
|
||||||
|
sticker: Optional["types.Sticker"] = None,
|
||||||
|
is_premium: Optional[bool] = None,
|
||||||
|
static_icon_id: Optional[int] = None,
|
||||||
|
effect_animation_id: Optional[int] = None
|
||||||
|
):
|
||||||
|
super().__init__()
|
||||||
|
|
||||||
|
self.id = id
|
||||||
|
self.emoji = emoji
|
||||||
|
self.effect_sticker_id = effect_sticker_id
|
||||||
|
self.sticker = sticker
|
||||||
|
self.is_premium = is_premium
|
||||||
|
self.static_icon_id = static_icon_id
|
||||||
|
self.effect_animation_id = effect_animation_id
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
async def _parse(client, effect: "raw.types.AvailableEffect", document: "raw.types.Document" = None) -> "AvailableEffect":
|
||||||
|
sticker = None
|
||||||
|
|
||||||
|
if document:
|
||||||
|
attributes = {type(i): i for i in document.attributes}
|
||||||
|
sticker = await types.Sticker._parse(client, document, attributes)
|
||||||
|
|
||||||
|
return AvailableEffect(
|
||||||
|
id=effect.id,
|
||||||
|
emoji=effect.emoticon,
|
||||||
|
effect_sticker_id=effect.effect_sticker_id,
|
||||||
|
sticker=sticker,
|
||||||
|
is_premium=getattr(effect, "premium_required", None),
|
||||||
|
static_icon_id=getattr(effect, "static_icon_id", None),
|
||||||
|
effect_animation_id=getattr(effect, "effect_animation_id", None)
|
||||||
|
)
|
||||||
Loading…
Reference in a new issue