Ejemplo n.º 1
0
async def inline_handler(event):
    builder = event.builder
    input_str = event.pattern_match.group(1)
    plug = [*PLUGINS]
    plugs = []
    if input_str == "all":
        for i in plug:
            try:
                plugs.append(
                    await event.builder.document(
                        f"./plugins/{i}.py",
                        title=f"{i}.py",
                        description=f"Module Found",
                        text=f"{i}.py use .paste to paste in neko and raw..",
                        buttons=[
                            [
                                Button.switch_inline(
                                    "Search Again..?", query="send all", same_peer=True
                                )
                            ]
                        ],
                    )
                )
            except BaseException:
                pass
        await event.answer(plugs)
    else:
        try:
            ultroid = builder.document(
                f"./plugins/{input_str}.py",
                title=f"{input_str}.py",
                description=f"Module {input_str} Found",
                text=f"{input_str}.py use .paste to paste in neko and raw..",
                buttons=[
                    [
                        Button.switch_inline(
                            "Search Again..?", query="send ", same_peer=True
                        )
                    ]
                ],
            )
            await event.answer([ultroid])
            return
        except BaseException:
            ultroidcode = builder.article(
                title=f"Module {input_str}.py Not Found",
                description=f"No Such Module",
                text=f"No Module Named {input_str}.py",
                buttons=[
                    [
                        Button.switch_inline(
                            "Search Again", query="send ", same_peer=True
                        )
                    ]
                ],
            )
            await event.answer([ultroidcode])
            return
Ejemplo n.º 2
0
    async def start_help(self, event: telethon.events.NewMessage.Event):
        cmd = event.pattern_match.group(1)
        args = event.pattern_match.group(2)

        if cmd == 'start' and not args:
            await event.reply(
                "Hello! I am meant to be used in inline mode."
                "\nIf you are not sure what that means, try typing <code>@theanimebot</code> and a space or use the button below."
                "\nYou can also tap /help for more info on how to use me",
                parse_mode='HTML',
                buttons=[[
                    Button.switch_inline('Try out inline mode', 'Amagami SS')
                ]])
            return

        await event.reply(
            "Inline mode usage:\n"
            "@theanimebot [comma-separated list of genres or tags][: ][search query]\n"
            "Examples:\n"
            "- Search for more than one tag or genre:\n"
            "   @theanimebot aliens, mecha\n"
            "- Search for a tag and some text:\n"
            "   @theanimebot romance: april\n"
            "- Search without genres or tags:\n"
            "   @theanimebot your lie in april\n\n"
            f"Supported tags: tap this -> /tags\n"
            f"Supported genres: tap this -> /genres")
async def to_telethon(o, client, markup: ReplyKeyboardMarkupModel = None):
    """
    :type  markup: ReplyKeyboardMarkupModel
    :param markup: `KeyboardButtonModel`s need access to `resize_keyboard`, `one_time_keyboard` and `selective`.
    """
    if isinstance(o, ReplyKeyboardMarkupModel):
        buttons = []
        for row in o.keyboard:
            buttons.append([])
            for button in row:
                buttons[-1].append(await to_telethon(button,
                                                     client=client,
                                                     markup=o))
            # end for
        # end for
        return buttons
    if isinstance(o, InlineKeyboardMarkupModel):
        buttons = []
        for row in o.inline_keyboard:
            buttons.append([])
            for button in row:
                if isinstance(button, dict):
                    button = InlineKeyboardButtonModel.parse_obj(button)
                # end if
                buttons[-1].append(await to_telethon(button, client=client))
            # end for
        # end for
        return buttons
    if isinstance(o, KeyboardButtonModel):
        assert o.text
        assert markup
        if o.request_poll:
            assert isinstance(o.request_poll, KeyboardButtonPollTypeModel)
            return Button.request_poll(
                text=o.text,
                force_quiz=o.request_poll.type == 'quiz',
                resize=markup.resize_keyboard,
                single_use=markup.one_time_keyboard,
                selective=markup.selective,
            )
        # end if
        if o.request_contact:
            assert o.text
            assert markup
            return Button.request_phone(
                o.text,
                resize=markup.resize_keyboard,
                single_use=markup.one_time_keyboard,
                selective=markup.selective,
            )
        # end if
        if o.request_location:
            assert o.text
            assert markup
            return Button.request_location(
                o.text,
                resize=markup.resize_keyboard,
                single_use=markup.one_time_keyboard,
                selective=markup.selective,
            )
        # end if
        raise TypeError(
            f'KeyboardButtonModel not handled: {type(o)} with value {o!r}: {o!s}'
        )
    if isinstance(o, InlineKeyboardButtonModel):
        if o.url:
            if o.text:
                return Button.url(text=o.text, url=o.url)
            # end if
            return Button.url(text=o.url, url=o.url)
        if o.login_url:
            assert isinstance(o.login_url, LoginUrlModel)
            return Button.auth(
                text=o.text,
                bot=o.login_url.bot_username,
                write_access=o.login_url.request_write_access,
                fwd_text=o.login_url.forward_text,
            )
        if o.callback_data:
            if o.text:
                return Button.inline(text=o.text, data=o.callback_data)
            # end if
            return Button.inline(text=o.callback_data, data=o.callback_data)
        if o.switch_inline_query:
            return Button.switch_inline(query=o.switch_inline_query,
                                        same_peer=False)
        if o.switch_inline_query_current_chat:
            return Button.switch_inline(query=o.switch_inline_query,
                                        same_peer=True)
        if o.callback_game:
            raise NotImplementedError('later, alligator')
        if o.pay:
            raise NotImplementedError('later, alligator')
    if o is None:
        return None
    raise TypeError(f'Type not handled: {type(o)} with value {o!r}: {o!s}')