Exemple #1
0
async def inline_echo(iq_iq: InlineQuery):
    result_id = random.uniform(0, 2384723684723684)
    catt = Animals.give_me_a_cat()
    cat = InlineQueryResultPhoto(id=result_id,
                                 photo_url=catt[0],
                                 thumb_url=catt[0],
                                 title="😺",
                                 caption=catt[1])
    await BOT.answer_inline_query(iq_iq.id, results=[cat], cache_time=1)
Exemple #2
0
async def qrInlineHandler(inline_query: InlineQuery):
    awaitingButton = inline_keyboard.InlineKeyboardButton(
        'Ожидайте...', callback_data='awaiting')

    awaitingKeyboard = inline_keyboard.InlineKeyboardMarkup(
        row_width=1).insert(awaitingButton)
    items = [
        InlineQueryResultPhoto(
            id=str(time() + 1),
            photo_url="https://i.ibb.co/n16zcs0/rnfoxbot-QR.jpg",
            thumb_url='https://i.ibb.co/KsbFqjG/rnfoxbot-QR.jpg',
            photo_width=200,
            photo_height=200,
            caption=markdown.italic("QR—code генерируется..."),
            reply_markup=awaitingKeyboard,
            parse_mode='MarkdownV2')
    ]

    await bot.answer_inline_query(inline_query.id, results=items, cache_time=0)
Exemple #3
0
async def inline_function(inline_query: InlineQuery):
    query = inline_query.query
    offset = inline_query.offset
    if offset != '':
        query = offset.split(' ', 1)[0]
        offset = int(offset.split('page=', 1)[1])
        offset += 1
        offset = ' page=' + str(offset)
    else:
        offset = ' page=1'
    if query is None:
        query = 'rating:s'
    client = Moebooru('yandere')
    posts = client.post_list(tags=query,
                             limit=50,
                             page=int(offset.split('page=', 1)[1]))
    lposts = len(posts)
    inlinequery = list()
    for post in posts:
        inlinequery.append(
            InlineQueryResultPhoto(
                id=str(uuid4()),
                photo_url=post['sample_url'],
                photo_width=post['width'],
                photo_height=post['height'],
                thumb_url=post['preview_url'],
                caption=
                '<a href="https://t.me/NekobinRobot?start=%s">Download</a>' %
                (post['id']),
                parse_mode=ParseMode.HTML), )
    if lposts >= 50:
        await bot.answer_inline_query(inline_query.id,
                                      results=inlinequery,
                                      next_offset=query + offset)
    else:
        await bot.answer_inline_query(inline_query.id, results=inlinequery)
    inlinequery.clear()
Exemple #4
0
    async def _inline_handler(self, inline_query: InlineQuery) -> None:
        """Inline query handler (forms' calls)"""
        # Retrieve query from passed object
        query = inline_query.query

        # If we didn't get any query, return help
        if not query:
            _help = ""
            for mod in self._allmodules.modules:
                if (not hasattr(mod, "inline_handlers")
                        or not isinstance(mod.inline_handlers, dict)
                        or not mod.inline_handlers):
                    continue

                _ihandlers = dict(mod.inline_handlers.items())
                for name, fun in _ihandlers.items():
                    # If user doesn't have enough permissions
                    # to run this inline command, do not show it
                    # in help
                    if not self.check_inline_security(
                            fun, inline_query.from_user.id):
                        continue

                    # Retrieve docs from func
                    doc = utils.escape_html("\n".join([
                        line.strip()
                        for line in inspect.getdoc(fun).splitlines()
                        if not line.strip().startswith("@")
                    ]))

                    _help += f"🎹 <code>@{self.bot_username} {name}</code> - {doc}\n"

            await inline_query.answer(
                [
                    InlineQueryResultArticle(
                        id=rand(20),
                        title="Show available inline commands",
                        description=
                        f"You have {len(_help.splitlines())} available command(-s)",
                        input_message_content=InputTextMessageContent(
                            f"<b>ℹ️ Available inline commands:</b>\n\n{_help}",
                            "HTML",
                            disable_web_page_preview=True,
                        ),
                        thumb_url=
                        "https://img.icons8.com/fluency/50/000000/info-squared.png",
                        thumb_width=128,
                        thumb_height=128,
                    )
                ],
                cache_time=0,
            )

            return

        # First, dispatch all registered inline handlers
        for mod in self._allmodules.modules:
            if (not hasattr(mod, "inline_handlers")
                    or not isinstance(mod.inline_handlers, dict)
                    or not mod.inline_handlers):
                continue

            instance = GeekInlineQuery(inline_query)

            for query_text, query_func in mod.inline_handlers.items():
                if inline_query.query.split()[0].lower(
                ) == query_text.lower() and self.check_inline_security(
                        query_func, inline_query.from_user.id):
                    try:
                        await query_func(instance)
                    except BaseException:
                        logger.exception("Error on running inline watcher!")

        # Process forms
        for form in self._forms.copy().values():
            for button in array_sum(form.get("buttons", [])):
                if ("_switch_query" in button and "input" in button
                        and button["_switch_query"] == query.split()[0]
                        and inline_query.from_user.id in [self._me] + self.
                        _client.dispatcher.security._owner  # skipcq: PYL-W0212
                        + form["always_allow"]):
                    await inline_query.answer(
                        [
                            InlineQueryResultArticle(
                                id=rand(20),
                                title=button["input"],
                                description=
                                "⚠️ Please, do not remove identifier!",
                                input_message_content=InputTextMessageContent(
                                    "🔄 <b>Transferring value to userbot...</b>\n"
                                    "<i>This message is gonna be deleted...</i>",
                                    "HTML",
                                    disable_web_page_preview=True,
                                ),
                            )
                        ],
                        cache_time=60,
                    )
                    return

        # Process galleries
        for gallery in self._galleries.copy().values():
            if (inline_query.from_user.id in [
                    self._me
            ] + self._client.dispatcher.security._owner  # skipcq: PYL-W0212
                    + gallery["always_allow"] and query == gallery["uid"]):
                markup = InlineKeyboardMarkup()
                markup.add(
                    InlineKeyboardButton(
                        "Next ➡️", callback_data=gallery["btn_call_data"]))

                caption = gallery["caption"]
                caption = caption() if callable(caption) else caption

                await inline_query.answer(
                    [
                        InlineQueryResultPhoto(
                            id=rand(20),
                            title="Toss a coin",
                            photo_url=gallery["photo_url"],
                            thumb_url=gallery["photo_url"],
                            caption=caption,
                            description=caption,
                            reply_markup=markup,
                            parse_mode="HTML",
                        )
                    ],
                    cache_time=0,
                )
                return

        # If we don't know, what this query is for, just ignore it
        if query not in self._forms:
            return

        # Otherwise, answer it with templated form
        await inline_query.answer(
            [
                InlineQueryResultArticle(
                    id=rand(20),
                    title="GeekTG",
                    input_message_content=InputTextMessageContent(
                        self._forms[query]["text"],
                        "HTML",
                        disable_web_page_preview=True,
                    ),
                    reply_markup=self._generate_markup(query),
                )
            ],
            cache_time=60,
        )