Skip to content

Commit 0b0af2d

Browse files
committed
Add InlineQueryResultCachedAnimation
1 parent d87810c commit 0b0af2d

File tree

2 files changed

+110
-1
lines changed

2 files changed

+110
-1
lines changed

pyrogram/types/inline_mode/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from .inline_query_result_animation import InlineQueryResultAnimation
2323
from .inline_query_result_article import InlineQueryResultArticle
2424
from .inline_query_result_audio import InlineQueryResultAudio
25+
from .inline_query_result_cached_animation import InlineQueryResultCachedAnimation
2526
from .inline_query_result_cached_photo import InlineQueryResultCachedPhoto
2627
from .inline_query_result_contact import InlineQueryResultContact
2728
from .inline_query_result_document import InlineQueryResultDocument
@@ -35,5 +36,5 @@
3536
"InlineQuery", "InlineQueryResult", "InlineQueryResultArticle", "InlineQueryResultPhoto",
3637
"InlineQueryResultAnimation", "InlineQueryResultAudio", "InlineQueryResultVideo", "ChosenInlineResult",
3738
"InlineQueryResultContact", "InlineQueryResultDocument", "InlineQueryResultVoice", "InlineQueryResultLocation",
38-
"InlineQueryResultVenue", "InlineQueryResultCachedPhoto"
39+
"InlineQueryResultVenue", "InlineQueryResultCachedPhoto", "InlineQueryResultCachedAnimation"
3940
]
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# Pyrogram - Telegram MTProto API Client Library for Python
2+
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
3+
#
4+
# This file is part of Pyrogram.
5+
#
6+
# Pyrogram is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU Lesser General Public License as published
8+
# by the Free Software Foundation, either version 3 of the License, or
9+
# (at your option) any later version.
10+
#
11+
# Pyrogram is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU Lesser General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU Lesser General Public License
17+
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
18+
19+
from typing import Optional, List
20+
21+
import pyrogram
22+
from pyrogram import raw, types, utils, enums
23+
from .inline_query_result import InlineQueryResult
24+
from ...file_id import FileId
25+
26+
27+
class InlineQueryResultCachedAnimation(InlineQueryResult):
28+
"""A link to an animation file stored on the Telegram servers.
29+
30+
By default, this animation file will be sent by the user with an optional caption.
31+
Alternatively, you can use *input_message_content* to send a message with specified content instead of the
32+
animation.
33+
34+
Parameters:
35+
animation_file_id (``str``):
36+
A valid file identifier for the animation file.
37+
38+
id (``str``, *optional*):
39+
Unique identifier for this result, 1-64 bytes.
40+
Defaults to a randomly generated UUID4.
41+
42+
title (``str``, *optional*):
43+
Title for the result.
44+
45+
caption (``str``, *optional*):
46+
Caption of the photo to be sent, 0-1024 characters.
47+
48+
parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
49+
By default, texts are parsed using both Markdown and HTML styles.
50+
You can combine both syntaxes together.
51+
52+
caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
53+
List of special entities that appear in the caption, which can be specified instead of *parse_mode*.
54+
55+
reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup`, *optional*):
56+
An InlineKeyboardMarkup object.
57+
58+
input_message_content (:obj:`~pyrogram.types.InputMessageContent`):
59+
Content of the message to be sent instead of the photo.
60+
"""
61+
62+
def __init__(
63+
self,
64+
animation_file_id: str,
65+
id: str = None,
66+
title: str = None,
67+
caption: str = "",
68+
parse_mode: Optional["enums.ParseMode"] = None,
69+
caption_entities: List["types.MessageEntity"] = None,
70+
reply_markup: "types.InlineKeyboardMarkup" = None,
71+
input_message_content: "types.InputMessageContent" = None
72+
):
73+
super().__init__("gif", id, input_message_content, reply_markup)
74+
75+
self.animation_file_id = animation_file_id
76+
self.title = title
77+
self.caption = caption
78+
self.parse_mode = parse_mode
79+
self.caption_entities = caption_entities
80+
self.reply_markup = reply_markup
81+
self.input_message_content = input_message_content
82+
83+
async def write(self, client: "pyrogram.Client"):
84+
message, entities = (await utils.parse_text_entities(
85+
client, self.caption, self.parse_mode, self.caption_entities
86+
)).values()
87+
88+
file_id = FileId.decode(self.animation_file_id)
89+
90+
return raw.types.InputBotInlineResultDocument(
91+
id=self.id,
92+
type=self.type,
93+
title=self.title,
94+
document=raw.types.InputDocument(
95+
id=file_id.media_id,
96+
access_hash=file_id.access_hash,
97+
file_reference=file_id.file_reference,
98+
),
99+
send_message=(
100+
await self.input_message_content.write(client, self.reply_markup)
101+
if self.input_message_content
102+
else raw.types.InputBotInlineMessageMediaAuto(
103+
reply_markup=await self.reply_markup.write(client) if self.reply_markup else None,
104+
message=message,
105+
entities=entities
106+
)
107+
)
108+
)

0 commit comments

Comments
 (0)