Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add add_to_gifs method #124

Merged
merged 2 commits into from
Dec 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions compiler/api/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def get_type_hint(type: str) -> str:
return f"Optional[{type}] = None" if is_flag else type
else:
ns, name = type.split(".") if "." in type else ("", type)
type = f'"raw.base.' + ".".join([ns, name]).strip(".") + '"'
type = '"raw.base.' + ".".join([ns, name]).strip(".") + '"'

return f'{type}{" = None" if is_flag else ""}'

Expand Down Expand Up @@ -394,7 +394,6 @@ def start(format: bool = False):
for i, arg in enumerate(sorted_args):
arg_name, arg_type = arg
is_optional = FLAGS_RE.match(arg_type)
flag_number = is_optional.group(1) if is_optional else -1
arg_type = arg_type.split("?")[-1]

arg_docs = combinator_docs.get(c.qualname, None)
Expand All @@ -408,7 +407,7 @@ def start(format: bool = False):
"{} ({}{}):\n {}\n".format(
arg_name,
get_docstring_arg_type(arg_type),
", *optional*".format(flag_number) if is_optional else "",
", *optional*" if is_optional else "",
arg_docs
)
)
Expand All @@ -429,11 +428,11 @@ def start(format: bool = False):
if function_docs:
docstring += function_docs["desc"] + "\n"
else:
docstring += f"Telegram API function."
docstring += "Telegram API function."

docstring += f"\n\n Details:\n - Layer: ``{layer}``\n - ID: ``{c.id[2:].upper()}``\n\n"
docstring += f" Parameters:\n " + \
(f"\n ".join(docstring_args) if docstring_args else "No parameters required.\n")
docstring += " Parameters:\n " + \
("\n ".join(docstring_args) if docstring_args else "No parameters required.\n")

if c.section == "functions":
docstring += "\n Returns:\n " + get_docstring_arg_type(c.qualtype)
Expand Down
5 changes: 5 additions & 0 deletions compiler/docs/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ def get_title_list(s: str) -> list:
delete_chat_history
send_paid_media
send_paid_reaction
add_to_gifs
""",
chats="""
Chats
Expand Down Expand Up @@ -845,6 +846,10 @@ def get_title_list(s: str) -> list:
StarGift
StarGift.show
StarGift.hide
""",
animation="""
Animation
Animation.add_to_gifs
"""
)

Expand Down
60 changes: 60 additions & 0 deletions pyrogram/methods/messages/add_to_gifs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# 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/>.

import pyrogram
from pyrogram import raw
from pyrogram.file_id import FileId

class AddToGifs():
async def add_to_gifs(
self: "pyrogram.Client",
file_id: str,
unsave: bool = False
) -> bool:
"""Add a GIF to the list of saved GIFs.

.. include:: /_includes/usable-by/users.rst

Parameters:
file_id (``str``):
Unique identifier for the GIF.

unsave (``bool``, optional):
Whether to remove the GIF from the list of saved GIFs. Defaults to ``False``.

Returns:
``bool``: True on success.

Example:
.. code-block:: python

await app.add_to_gifs(message.animation.file_id)

"""
decoded_file_id = FileId.decode(file_id)

return await self.invoke(
raw.functions.messages.SaveGif(
id=raw.types.InputDocument(
id=decoded_file_id.media_id,
file_reference=decoded_file_id.file_reference,
access_hash=decoded_file_id.access_hash,
),
unsave=unsave
)
)
23 changes: 23 additions & 0 deletions pyrogram/types/messages_and_media/animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,29 @@ def __init__(
self.height = height
self.duration = duration
self.thumbs = thumbs

async def add_to_gifs(
self,
unsave: bool = False
) -> bool:
"""Bound method *add_to_gifs* of :obj:`~pyrogram.types.Message`.

.. include:: /_includes/usable-by/users.rst

Use as a shortcut for:

.. code-block:: python

await app.add_to_gifs(message.animation.file_id)

Parameters:
unsave (``bool``, optional):
Whether to remove the GIF from the list of saved GIFs. Defaults to ``False``.

Returns:
``bool``: True on success.
"""
return await self._client.add_to_gifs(self.file_id, unsave)

@staticmethod
def _parse(
Expand Down
Loading