Пример #1
0
def make_result_from_db_entry(db_entry):

    data = db_entry["data"]

    dbManager.inline_update_tag(db_entry)

    if data["type"] == "text":
        return InlineQueryResultArticle(
            id=uuid4(),
            title=db_entry["hashtag"] + ": " + data["data"],
            input_message_content=InputTextMessageContent(data["data"]))

    if data["type"] == "image":
        return telegram.InlineQueryResultCachedPhoto(
            id=uuid4(),
            title=db_entry["hashtag"],
            photo_file_id=data["data"],
            caption=db_entry["hashtag"])

    if data["type"] == "gif":
        return telegram.InlineQueryResultCachedDocument(
            id=uuid4(),
            title=db_entry["hashtag"],
            document_file_id=data["data"],
            caption=db_entry["hashtag"])

    if data["type"] == "sticker":
        return telegram.InlineQueryResultCachedSticker(
            id=uuid4(),
            title=db_entry["hashtag"],
            sticker_file_id=data["data"])

    if data["type"] == "audio":
        return telegram.InlineQueryResultCachedAudio(
            id=uuid4(),
            title=db_entry["hashtag"],
            audio_file_id=data["data"],
            caption=db_entry["hashtag"])

    if data["type"] == "voice":
        return telegram.InlineQueryResultCachedVoice(
            id=uuid4(),
            title=db_entry["hashtag"],
            voice_file_id=data["data"],
            caption=db_entry["hashtag"])

    if data["type"] == "video":
        return telegram.InlineQueryResultCachedVideo(
            id=uuid4(),
            title=db_entry["hashtag"],
            video_file_id=data["data"],
            caption=db_entry["hashtag"])
Пример #2
0
    def test_equality(self):
        a = telegram.InlineQueryResultCachedVoice(self._id, self.voice_file_id,
                                                  self.title)
        b = telegram.InlineQueryResultCachedVoice(self._id, self.voice_file_id,
                                                  self.title)
        c = telegram.InlineQueryResultCachedVoice(self._id, "", self.title)
        d = telegram.InlineQueryResultCachedVoice("", self.voice_file_id,
                                                  self.title)
        e = telegram.InlineQueryResultCachedAudio(self._id, "", "")

        self.assertEqual(a, b)
        self.assertEqual(hash(a), hash(b))
        self.assertIsNot(a, b)

        self.assertEqual(a, c)
        self.assertEqual(hash(a), hash(c))

        self.assertNotEqual(a, d)
        self.assertNotEqual(hash(a), hash(d))

        self.assertNotEqual(a, e)
        self.assertNotEqual(hash(a), hash(e))
    def test_equality(self):
        a = telegram.InlineQueryResultCachedGif(self._id, self.gif_file_id)
        b = telegram.InlineQueryResultCachedGif(self._id, self.gif_file_id)
        c = telegram.InlineQueryResultCachedGif(self._id, "")
        d = telegram.InlineQueryResultCachedGif("", self.gif_file_id)
        e = telegram.InlineQueryResultCachedVoice(self._id, "", "")

        self.assertEqual(a, b)
        self.assertEqual(hash(a), hash(b))
        self.assertIsNot(a, b)

        self.assertEqual(a, c)
        self.assertEqual(hash(a), hash(c))

        self.assertNotEqual(a, d)
        self.assertNotEqual(hash(a), hash(d))

        self.assertNotEqual(a, e)
        self.assertNotEqual(hash(a), hash(e))