mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-28 21:07:59 +00:00
Refactor send_gif. It is now called send_animation
This commit is contained in:
parent
b1c12c3232
commit
2b793dd2a1
@ -29,7 +29,7 @@ from .send_audio import SendAudio
|
|||||||
from .send_chat_action import SendChatAction
|
from .send_chat_action import SendChatAction
|
||||||
from .send_contact import SendContact
|
from .send_contact import SendContact
|
||||||
from .send_document import SendDocument
|
from .send_document import SendDocument
|
||||||
from .send_gif import SendGIF
|
from .send_gif import SendAnimation
|
||||||
from .send_location import SendLocation
|
from .send_location import SendLocation
|
||||||
from .send_media_group import SendMediaGroup
|
from .send_media_group import SendMediaGroup
|
||||||
from .send_message import SendMessage
|
from .send_message import SendMessage
|
||||||
@ -55,7 +55,7 @@ class Messages(
|
|||||||
SendChatAction,
|
SendChatAction,
|
||||||
SendContact,
|
SendContact,
|
||||||
SendDocument,
|
SendDocument,
|
||||||
SendGIF,
|
SendAnimation,
|
||||||
SendLocation,
|
SendLocation,
|
||||||
SendMediaGroup,
|
SendMediaGroup,
|
||||||
SendMessage,
|
SendMessage,
|
||||||
|
@ -26,22 +26,22 @@ from pyrogram.api.errors import FileIdInvalid, FilePartMissing
|
|||||||
from pyrogram.client.ext import BaseClient, utils
|
from pyrogram.client.ext import BaseClient, utils
|
||||||
|
|
||||||
|
|
||||||
class SendGIF(BaseClient):
|
class SendAnimation(BaseClient):
|
||||||
def send_gif(self,
|
def send_animation(self,
|
||||||
chat_id: int or str,
|
chat_id: int or str,
|
||||||
gif: str,
|
animation: str,
|
||||||
caption: str = "",
|
caption: str = "",
|
||||||
parse_mode: str = "",
|
parse_mode: str = "",
|
||||||
duration: int = 0,
|
duration: int = 0,
|
||||||
width: int = 0,
|
width: int = 0,
|
||||||
height: int = 0,
|
height: int = 0,
|
||||||
thumb: str = None,
|
thumb: str = None,
|
||||||
disable_notification: bool = None,
|
disable_notification: bool = None,
|
||||||
reply_to_message_id: int = None,
|
reply_to_message_id: int = None,
|
||||||
reply_markup=None,
|
reply_markup=None,
|
||||||
progress: callable = None,
|
progress: callable = None,
|
||||||
progress_args: tuple = ()):
|
progress_args: tuple = ()):
|
||||||
"""Use this method to send GIF files.
|
"""Use this method to send animation files (animation or H.264/MPEG-4 AVC video without sound).
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
chat_id (``int`` | ``str``):
|
chat_id (``int`` | ``str``):
|
||||||
@ -49,14 +49,14 @@ class SendGIF(BaseClient):
|
|||||||
For your personal cloud (Saved Messages) you can simply use "me" or "self".
|
For your personal cloud (Saved Messages) you can simply use "me" or "self".
|
||||||
For a contact that exists in your Telegram address book you can use his phone number (str).
|
For a contact that exists in your Telegram address book you can use his phone number (str).
|
||||||
|
|
||||||
gif (``str``):
|
animation (``str``):
|
||||||
GIF to send.
|
Animation to send.
|
||||||
Pass a file_id as string to send a GIF that exists on the Telegram servers,
|
Pass a file_id as string to send an animation that exists on the Telegram servers,
|
||||||
pass an HTTP URL as a string for Telegram to get a GIF from the Internet, or
|
pass an HTTP URL as a string for Telegram to get an animation from the Internet, or
|
||||||
pass a file path as string to upload a new GIF that exists on your local machine.
|
pass a file path as string to upload a new animation that exists on your local machine.
|
||||||
|
|
||||||
caption (``str``, *optional*):
|
caption (``str``, *optional*):
|
||||||
GIF caption, 0-200 characters.
|
Animation caption, 0-200 characters.
|
||||||
|
|
||||||
parse_mode (``str``, *optional*):
|
parse_mode (``str``, *optional*):
|
||||||
Use :obj:`MARKDOWN <pyrogram.ParseMode.MARKDOWN>` or :obj:`HTML <pyrogram.ParseMode.HTML>`
|
Use :obj:`MARKDOWN <pyrogram.ParseMode.MARKDOWN>` or :obj:`HTML <pyrogram.ParseMode.HTML>`
|
||||||
@ -64,16 +64,16 @@ class SendGIF(BaseClient):
|
|||||||
Defaults to Markdown.
|
Defaults to Markdown.
|
||||||
|
|
||||||
duration (``int``, *optional*):
|
duration (``int``, *optional*):
|
||||||
Duration of sent GIF in seconds.
|
Duration of sent animation in seconds.
|
||||||
|
|
||||||
width (``int``, *optional*):
|
width (``int``, *optional*):
|
||||||
GIF width.
|
Animation width.
|
||||||
|
|
||||||
height (``int``, *optional*):
|
height (``int``, *optional*):
|
||||||
GIF height.
|
Animation height.
|
||||||
|
|
||||||
thumb (``str``, *optional*):
|
thumb (``str``, *optional*):
|
||||||
GIF thumbnail.
|
Animation thumbnail.
|
||||||
Pass a file path as string to send an image that exists on your local machine.
|
Pass a file path as string to send an image that exists on your local machine.
|
||||||
Thumbnail should have 90 or less pixels of width and 90 or less pixels of height.
|
Thumbnail should have 90 or less pixels of width and 90 or less pixels of height.
|
||||||
|
|
||||||
@ -120,9 +120,9 @@ class SendGIF(BaseClient):
|
|||||||
file = None
|
file = None
|
||||||
style = self.html if parse_mode.lower() == "html" else self.markdown
|
style = self.html if parse_mode.lower() == "html" else self.markdown
|
||||||
|
|
||||||
if os.path.exists(gif):
|
if os.path.exists(animation):
|
||||||
thumb = None if thumb is None else self.save_file(thumb)
|
thumb = None if thumb is None else self.save_file(thumb)
|
||||||
file = self.save_file(gif, progress=progress, progress_args=progress_args)
|
file = self.save_file(animation, progress=progress, progress_args=progress_args)
|
||||||
media = types.InputMediaUploadedDocument(
|
media = types.InputMediaUploadedDocument(
|
||||||
mime_type=mimetypes.types_map[".mp4"],
|
mime_type=mimetypes.types_map[".mp4"],
|
||||||
file=file,
|
file=file,
|
||||||
@ -134,17 +134,17 @@ class SendGIF(BaseClient):
|
|||||||
w=width,
|
w=width,
|
||||||
h=height
|
h=height
|
||||||
),
|
),
|
||||||
types.DocumentAttributeFilename(os.path.basename(gif)),
|
types.DocumentAttributeFilename(os.path.basename(animation)),
|
||||||
types.DocumentAttributeAnimated()
|
types.DocumentAttributeAnimated()
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
elif gif.startswith("http"):
|
elif animation.startswith("http"):
|
||||||
media = types.InputMediaDocumentExternal(
|
media = types.InputMediaDocumentExternal(
|
||||||
url=gif
|
url=animation
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
decoded = utils.decode(gif)
|
decoded = utils.decode(animation)
|
||||||
fmt = "<iiqqqqi" if len(decoded) > 24 else "<iiqq"
|
fmt = "<iiqqqqi" if len(decoded) > 24 else "<iiqq"
|
||||||
unpacked = struct.unpack(fmt, decoded)
|
unpacked = struct.unpack(fmt, decoded)
|
||||||
except (AssertionError, binascii.Error, struct.error):
|
except (AssertionError, binascii.Error, struct.error):
|
||||||
@ -179,7 +179,7 @@ class SendGIF(BaseClient):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
except FilePartMissing as e:
|
except FilePartMissing as e:
|
||||||
self.save_file(gif, file_id=file.id, file_part=e.x)
|
self.save_file(animation, file_id=file.id, file_part=e.x)
|
||||||
else:
|
else:
|
||||||
for i in r.updates:
|
for i in r.updates:
|
||||||
if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)):
|
if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user