Пример #1
0
def search(client: Client, query: InlineQuery):
    answers = []
    string = query.query.lower().strip().rstrip()

    if string == "":
        client.answer_inline_query(query.id,
                                   results=answers,
                                   switch_pm_text=_("inline_1"),
                                   switch_pm_parameter="help",
                                   cache_time=0)
        return
    else:
        videosSearch = VideosSearch(string.lower(), limit=50)
        for v in videosSearch.result()["result"]:
            answers.append(
                InlineQueryResultArticle(
                    title=v["title"],
                    description=_("inline_2").format(v["duration"],
                                                     v["viewCount"]["short"]),
                    input_message_content=InputTextMessageContent(
                        "https://www.youtube.com/watch?v={}".format(v["id"])),
                    thumb_url=v["thumbnails"][0]["url"]))
        try:
            query.answer(results=answers, cache_time=0)
        except errors.QueryIdInvalid:
            query.answer(
                results=answers,
                cache_time=0,
                switch_pm_text=_("inline_3"),
                switch_pm_parameter="",
            )
Пример #2
0
def inline_query_handler(_, query: InlineQuery):
    query.answer(results=[
        InlineQueryResultArticle(
            title="Tic-Tac-Toe",
            input_message_content=InputTextMessageContent(
                f"**{query.from_user.first_name}** challenged you in XO!"),
            description="Tap here to challenge your friends in XO!",
            thumb_url=
            "https://upload.wikimedia.org/wikipedia/commons/thumb/3/32/Tic_tac_toe.svg/1200px-Tic_tac_toe"
            ".svg.png",
            reply_markup=InlineKeyboardMarkup([[
                InlineKeyboardButton(
                    emojis.swords + " Accept",
                    json.dumps({
                        "type": "P",
                        "id": query.from_user.id,
                        "name": query.from_user.first_name
                    }))
            ]]))
    ],
                 cache_time=1)