From c94c79edacd43f4b7cc668aff17be25579e206fc Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 16 Oct 2018 11:34:44 +0200 Subject: [PATCH] Implement InlineQueryResultCachedAudio --- pyrogram/__init__.py | 2 +- pyrogram/client/types/__init__.py | 2 +- .../bots/inline_query_result_cached_audio.py | 88 ++++++++++++++----- 3 files changed, 67 insertions(+), 25 deletions(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index 00d269eb..003e835a 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -32,7 +32,7 @@ from .client.types import ( Location, Message, MessageEntity, Dialog, Dialogs, Photo, PhotoSize, Sticker, Update, User, UserProfilePhotos, Venue, Animation, Video, VideoNote, Voice, CallbackQuery, Messages, ForceReply, InlineKeyboardButton, InlineKeyboardMarkup, KeyboardButton, ReplyKeyboardMarkup, ReplyKeyboardRemove, - InlineQuery, InlineQueryResultArticle, InlineQueryResultPhoto, InputTextMessageContent + InlineQuery, InlineQueryResultArticle, InlineQueryResultPhoto, InputTextMessageContent, InlineQueryResultCachedAudio ) from .client import ( Client, ChatAction, ParseMode, Emoji, diff --git a/pyrogram/client/types/__init__.py b/pyrogram/client/types/__init__.py index cceac77a..3f5eb39c 100644 --- a/pyrogram/client/types/__init__.py +++ b/pyrogram/client/types/__init__.py @@ -19,7 +19,7 @@ from .bots import ( CallbackQuery, ForceReply, InlineKeyboardButton, InlineKeyboardMarkup, KeyboardButton, ReplyKeyboardMarkup, ReplyKeyboardRemove, InlineQuery, - InlineQueryResultArticle, InlineQueryResultPhoto + InlineQueryResultArticle, InlineQueryResultPhoto, InlineQueryResultCachedAudio ) from .bots import ( ForceReply, InlineKeyboardButton, InlineKeyboardMarkup, diff --git a/pyrogram/client/types/bots/inline_query_result_cached_audio.py b/pyrogram/client/types/bots/inline_query_result_cached_audio.py index 3dc53982..c2e1779d 100644 --- a/pyrogram/client/types/bots/inline_query_result_cached_audio.py +++ b/pyrogram/client/types/bots/inline_query_result_cached_audio.py @@ -16,45 +16,87 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -from pyrogram.api.core import Object +import binascii +import struct + +from pyrogram.api import types +from pyrogram.api.errors import FileIdInvalid +from pyrogram.client.ext import utils, BaseClient +from pyrogram.client.style import HTML, Markdown -class InlineQueryResultCachedAudio(Object): - """Represents a link to an mp3 audio file stored on the Telegram servers. By default, this audio file will be sent by the user. Alternatively, you can use input_message_content to send a message with the specified content instead of the audio. - - Attributes: - ID: ``0xb0700018`` +class InlineQueryResultCachedAudio: + """Represents a link to an audio file stored on the Telegram servers. + By default, this audio file will be sent by the user. Alternatively, you can use *input_message_content* to send a + message with the specified content instead of the audio. Args: - type (``str``): - Type of the result, must be audio. - id (``str``): Unique identifier for this result, 1-64 bytes. audio_file_id (``str``): A valid file identifier for the audio file. - caption (``str``, optional): + caption (``str``, *optional*): Caption, 0-200 characters. - parse_mode (``str``, optional): - Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. + parse_mode (``str``, *optional*): + Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in + the media caption. - reply_markup (:obj:`InlineKeyboardMarkup `, optional): + reply_markup (:obj:`InlineKeyboardMarkup `, *optional*): Inline keyboard attached to the message. - input_message_content (:obj:`InputMessageContent `, optional): + input_message_content (:obj:`InputMessageContent `, *optional*): Content of the message to be sent instead of the audio. """ - ID = 0xb0700018 - def __init__(self, type: str, id: str, audio_file_id: str, caption: str = None, parse_mode: str = None, reply_markup=None, input_message_content=None): - self.type = type # string - self.id = id # string - self.audio_file_id = audio_file_id # string - self.caption = caption # flags.0?string - self.parse_mode = parse_mode # flags.1?string - self.reply_markup = reply_markup # flags.2?InlineKeyboardMarkup - self.input_message_content = input_message_content # flags.3?InputMessageContent + def __init__( + self, + id: str, + audio_file_id: str, + caption: str = "", + parse_mode: str = "", + reply_markup=None, + input_message_content=None + ): + self.id = id + self.audio_file_id = audio_file_id + self.caption = caption + self.parse_mode = parse_mode + self.reply_markup = reply_markup + self.input_message_content = input_message_content + + self.style = HTML() if parse_mode.lower() == "html" else Markdown() + + def write(self): + try: + decoded = utils.decode(self.audio_file_id) + fmt = " 24 else "