Skip to content

Commit c4948ea

Browse files
committed
Add InlineQueryResultCachedVideo
1 parent 65a213b commit c4948ea

File tree

2 files changed

+116
-1
lines changed

2 files changed

+116
-1
lines changed

pyrogram/types/inline_mode/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from .inline_query_result_cached_document import InlineQueryResultCachedDocument
2727
from .inline_query_result_cached_photo import InlineQueryResultCachedPhoto
2828
from .inline_query_result_cached_sticker import InlineQueryResultCachedSticker
29+
from .inline_query_result_cached_video import InlineQueryResultCachedVideo
2930
from .inline_query_result_contact import InlineQueryResultContact
3031
from .inline_query_result_document import InlineQueryResultDocument
3132
from .inline_query_result_location import InlineQueryResultLocation
@@ -39,5 +40,5 @@
3940
"InlineQueryResultAnimation", "InlineQueryResultAudio", "InlineQueryResultVideo", "ChosenInlineResult",
4041
"InlineQueryResultContact", "InlineQueryResultDocument", "InlineQueryResultVoice", "InlineQueryResultLocation",
4142
"InlineQueryResultVenue", "InlineQueryResultCachedPhoto", "InlineQueryResultCachedAnimation",
42-
"InlineQueryResultCachedSticker", "InlineQueryResultCachedDocument"
43+
"InlineQueryResultCachedSticker", "InlineQueryResultCachedDocument", "InlineQueryResultCachedVideo"
4344
]
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
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 InlineQueryResultCachedVideo(InlineQueryResult):
28+
"""A link to a video file stored on the Telegram servers.
29+
30+
By default, this video file will be sent by the user with an optional caption.
31+
Alternatively, you can use *input_message_content* to send a message with the specified content instead of the
32+
video.
33+
34+
Parameters:
35+
video_file_id (``str``):
36+
A valid file identifier for the video file.
37+
38+
title (``str``):
39+
Title for the result.
40+
41+
id (``str``, *optional*):
42+
Unique identifier for this result, 1-64 bytes.
43+
Defaults to a randomly generated UUID4.
44+
45+
description (``str``, *optional*):
46+
Short description of the result.
47+
48+
caption (``str``, *optional*):
49+
Caption of the photo to be sent, 0-1024 characters.
50+
51+
parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
52+
By default, texts are parsed using both Markdown and HTML styles.
53+
You can combine both syntaxes together.
54+
55+
caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
56+
List of special entities that appear in the caption, which can be specified instead of *parse_mode*.
57+
58+
reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup`, *optional*):
59+
An InlineKeyboardMarkup object.
60+
61+
input_message_content (:obj:`~pyrogram.types.InputMessageContent`):
62+
Content of the message to be sent instead of the photo.
63+
"""
64+
65+
def __init__(
66+
self,
67+
video_file_id: str,
68+
title: str,
69+
id: str = None,
70+
description: str = None,
71+
caption: str = "",
72+
parse_mode: Optional["enums.ParseMode"] = None,
73+
caption_entities: List["types.MessageEntity"] = None,
74+
reply_markup: "types.InlineKeyboardMarkup" = None,
75+
input_message_content: "types.InputMessageContent" = None
76+
):
77+
super().__init__("video", id, input_message_content, reply_markup)
78+
79+
self.video_file_id = video_file_id
80+
self.title = title
81+
self.description = description
82+
self.caption = caption
83+
self.parse_mode = parse_mode
84+
self.caption_entities = caption_entities
85+
self.reply_markup = reply_markup
86+
self.input_message_content = input_message_content
87+
88+
async def write(self, client: "pyrogram.Client"):
89+
message, entities = (await utils.parse_text_entities(
90+
client, self.caption, self.parse_mode, self.caption_entities
91+
)).values()
92+
93+
file_id = FileId.decode(self.video_file_id)
94+
95+
return raw.types.InputBotInlineResultDocument(
96+
id=self.id,
97+
type=self.type,
98+
title=self.title,
99+
description=self.description,
100+
document=raw.types.InputDocument(
101+
id=file_id.media_id,
102+
access_hash=file_id.access_hash,
103+
file_reference=file_id.file_reference,
104+
),
105+
send_message=(
106+
await self.input_message_content.write(client, self.reply_markup)
107+
if self.input_message_content
108+
else raw.types.InputBotInlineMessageMediaAuto(
109+
reply_markup=await self.reply_markup.write(client) if self.reply_markup else None,
110+
message=message,
111+
entities=entities
112+
)
113+
)
114+
)

0 commit comments

Comments
 (0)