예제 #1
0
    def __init__(
            self,
            id: str,
            photo_url: str,
            thumb_url: str,
            photo_width: int = 0,
            photo_height: int = 0,
            title: str = None,
            description: str = None,
            caption: str = "",
            parse_mode: str = "",
            reply_markup=None,
            input_message_content=None
    ):
        self.id = id  # string
        self.photo_url = photo_url  # string
        self.thumb_url = thumb_url  # string
        self.photo_width = photo_width  # flags.0?int
        self.photo_height = photo_height  # flags.1?int
        self.title = title  # flags.2?string
        self.description = description  # flags.3?string
        self.caption = caption  # flags.4?string
        self.parse_mode = parse_mode  # flags.5?string
        self.reply_markup = reply_markup  # flags.6?InlineKeyboardMarkup
        self.input_message_content = input_message_content  # flags.7?InputMessageContent

        self.style = HTML() if parse_mode.lower() == "html" else Markdown()
    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()
class InlineQueryResultCachedAudio(Object):
    """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.

    Parameters:
        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, 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.

        reply_markup (:obj:`InlineKeyboardMarkup <pyrogram.types.InlineKeyboardMarkup>`, *optional*):
            Inline keyboard attached to the message.

        input_message_content (:obj:`InputMessageContent <pyrogram.types.InputMessageContent>`, *optional*):
            Content of the message to be sent instead of the audio.

    """
    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 = "<iiqqqqi" if len(decoded) > 24 else "<iiqq"
            unpacked = struct.unpack(fmt, decoded)
        except (AssertionError, binascii.Error, struct.error):
            raise FileIdInvalid from None
        else:
            if unpacked[0] != 9:
                media_type = BaseClient.MEDIA_TYPE_ID.get(unpacked[0], None)

                if media_type:
                    raise FileIdInvalid(
                        "The file_id belongs to a {}".format(media_type))
                else:
                    raise FileIdInvalid("Unknown media type: {}".format(
                        unpacked[0]))

        audio = types.InputDocument(id=unpacked[2], access_hash=unpacked[3])

        return types.InputBotInlineResultDocument(
            id=self.id,
            type="audio",
            document=audio,
            send_message=types.InputBotInlineMessageMediaAuto(
                reply_markup=self.reply_markup.write()
                if self.reply_markup else None,
                **self.style.parse(self.caption)))
예제 #4
0
class InlineQueryResultPhoto(PyrogramType):
    """Represents a link to a photo. By default, this photo will be sent by the user with optional caption.
    Alternatively, you can use input_message_content to send a message with the specified content instead of the photo.

    Args:
        id (``str``):
            Unique identifier for this result, 1-64 bytes.

        photo_url (``str``):
            A valid URL of the photo. Photo must be in jpeg format. Photo size must not exceed 5MB.

        thumb_url (``str``):
            URL of the thumbnail for the photo.

        photo_width (``int``, *optional*):
            Width of the photo.

        photo_height (``int``, *optional*):
            Height of the photo.

        title (``str``, *optional*):
            Title for the result.

        description (``str``, *optional*):
            Short description of the result.

        caption (``str``, *optional*):
            Caption of the photo to be sent, 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.

        reply_markup (:obj:`InlineKeyboardMarkup <pyrogram.types.InlineKeyboardMarkup>`, *optional*):
            Inline keyboard attached to the message.

        input_message_content (:obj:`InputMessageContent <pyrogram.types.InputMessageContent>`, *optional*):
            Content of the message to be sent instead of the photo.

    """

    def __init__(
            self,
            id: str,
            photo_url: str,
            thumb_url: str,
            photo_width: int = 0,
            photo_height: int = 0,
            title: str = None,
            description: str = None,
            caption: str = "",
            parse_mode: str = "",
            reply_markup=None,
            input_message_content=None
    ):
        self.id = id  # string
        self.photo_url = photo_url  # string
        self.thumb_url = thumb_url  # string
        self.photo_width = photo_width  # flags.0?int
        self.photo_height = photo_height  # flags.1?int
        self.title = title  # flags.2?string
        self.description = description  # flags.3?string
        self.caption = caption  # flags.4?string
        self.parse_mode = parse_mode  # flags.5?string
        self.reply_markup = reply_markup  # flags.6?InlineKeyboardMarkup
        self.input_message_content = input_message_content  # flags.7?InputMessageContent

        self.style = HTML() if parse_mode.lower() == "html" else Markdown()

    def write(self):
        return types.InputBotInlineResult(
            id=self.id,
            type="photo",
            send_message=types.InputBotInlineMessageMediaAuto(
                reply_markup=self.reply_markup.write() if self.reply_markup else None,
                **self.style.parse(self.caption)
            ),
            title=self.title,
            description=self.description,
            url=self.photo_url,
            thumb=types.InputWebDocument(
                url=self.thumb_url,
                size=0,
                mime_type="image/jpeg",
                attributes=[
                    types.DocumentAttributeImageSize(
                        w=0,
                        h=0
                    )
                ]
            ),
            content=types.InputWebDocument(
                url=self.thumb_url,
                size=0,
                mime_type="image/jpeg",
                attributes=[
                    types.DocumentAttributeImageSize(
                        w=self.photo_width,
                        h=self.photo_height
                    )
                ]
            )
        )