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)))
Exemplo n.º 2
0
 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
                 )
             ]
         )
     )
    def write(self):
        animation = types.InputWebDocument(url=self.animation_url,
                                           size=0,
                                           mime_type="image/gif",
                                           attributes=[])

        if self.thumb_url is None:
            thumb = animation
        else:
            thumb = types.InputWebDocument(url=self.thumb_url,
                                           size=0,
                                           mime_type="image/gif",
                                           attributes=[])

        return types.InputBotInlineResult(
            id=self.id,
            type=self.type,
            title=self.title,
            description=self.description,
            thumb=thumb,
            content=animation,
            send_message=(self.input_message_content.write(self.reply_markup)
                          if self.input_message_content else
                          types.InputBotInlineMessageMediaAuto(
                              reply_markup=self.reply_markup.write()
                              if self.reply_markup else None,
                              **(Parser(None)).parse(self.caption,
                                                     self.parse_mode))))
Exemplo n.º 4
0
async def inline_handler(c: bot, q: InlineQuery):
    text = q.query
    text = text if text else "Hello"
    cat_says_photo = await cat().cat_says(text)

    cat_says_photo_uploaded = await c.send_photo(
        chat_id=botCommon.dustbin,
        photo=str(cat_says_photo)
    )

    try:
        os.remove(cat_says_photo)
    except Exception as e:
        logging.error(str(e))

    cat_says_file_properties = await CustomFileProperties().get_properties(
        client=c,
        m_message_id=cat_says_photo_uploaded.message_id,
        m_chat_id=cat_says_photo_uploaded.chat.id
    )

    try:
        await c.send(
            functions.messages.SetInlineBotResults(
                query_id=int(q.id),
                cache_time=0,
                results=[
                    types.InputBotInlineResultPhoto(
                        id=str(secrets.token_hex(4)),
                        type="photo",
                        photo=types.InputPhoto(
                            id=cat_says_file_properties.document_id,
                            access_hash=cat_says_file_properties.access_hash,
                            file_reference=utils.decode_file_ref(cat_says_file_properties.file_ref)
                        ),
                        send_message=types.InputBotInlineMessageMediaAuto(
                            message=q.query
                        )
                    )

                ]
            )
        )
    except QueryIdInvalid:
        pass