|
| 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 | +import pyrogram |
| 20 | +from pyrogram import raw, types |
| 21 | +from .inline_query_result import InlineQueryResult |
| 22 | +from ...file_id import FileId |
| 23 | + |
| 24 | + |
| 25 | +class InlineQueryResultCachedSticker(InlineQueryResult): |
| 26 | + """A link to a sticker stored on the Telegram servers |
| 27 | +
|
| 28 | + By default, this sticker will be sent by the user. Alternatively, you can use *input_message_content* to send a |
| 29 | + message with the specified content instead of the sticker. |
| 30 | +
|
| 31 | + Parameters: |
| 32 | + sticker_file_id (``str``): |
| 33 | + A valid file identifier of the sticker. |
| 34 | +
|
| 35 | + id (``str``, *optional*): |
| 36 | + Unique identifier for this result, 1-64 bytes. |
| 37 | + Defaults to a randomly generated UUID4. |
| 38 | +
|
| 39 | + reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup`, *optional*): |
| 40 | + An InlineKeyboardMarkup object. |
| 41 | +
|
| 42 | + input_message_content (:obj:`~pyrogram.types.InputMessageContent`): |
| 43 | + Content of the message to be sent instead of the photo. |
| 44 | + """ |
| 45 | + |
| 46 | + def __init__( |
| 47 | + self, |
| 48 | + sticker_file_id: str, |
| 49 | + id: str = None, |
| 50 | + reply_markup: "types.InlineKeyboardMarkup" = None, |
| 51 | + input_message_content: "types.InputMessageContent" = None |
| 52 | + ): |
| 53 | + super().__init__("sticker", id, input_message_content, reply_markup) |
| 54 | + |
| 55 | + self.sticker_file_id = sticker_file_id |
| 56 | + self.reply_markup = reply_markup |
| 57 | + self.input_message_content = input_message_content |
| 58 | + |
| 59 | + async def write(self, client: "pyrogram.Client"): |
| 60 | + file_id = FileId.decode(self.sticker_file_id) |
| 61 | + |
| 62 | + return raw.types.InputBotInlineResultDocument( |
| 63 | + id=self.id, |
| 64 | + type=self.type, |
| 65 | + document=raw.types.InputDocument( |
| 66 | + id=file_id.media_id, |
| 67 | + access_hash=file_id.access_hash, |
| 68 | + file_reference=file_id.file_reference, |
| 69 | + ), |
| 70 | + send_message=( |
| 71 | + await self.input_message_content.write(client, self.reply_markup) |
| 72 | + if self.input_message_content |
| 73 | + else raw.types.InputBotInlineMessageMediaAuto( |
| 74 | + reply_markup=await self.reply_markup.write(client) if self.reply_markup else None, |
| 75 | + message="", |
| 76 | + ) |
| 77 | + ) |
| 78 | + ) |
0 commit comments