示例#1
0
async def inline_query_handler(client, query):
	string = query.query.lower()
	answers = []

	if query.from_user.id != Owner:
		await client.answer_inline_query(query.id,
			results=answers,
			switch_pm_text="Sorry, this bot only for {}".format(OwnerName),
			switch_pm_parameter="createown"
		)
		return

	if string == "":
		await client.answer_inline_query(query.id,
			results=answers,
			switch_pm_text="Need help? Click here",
			switch_pm_parameter="help"
		)
		return

	if string.split()[0] == "#note":
		q = string.split(None, 1)
		notetag = q[1]
		noteval = notes_db.get_selfnote(query.from_user.id, notetag)
		if not noteval:
			await client.answer_inline_query(query.id,
				results=answers,
				switch_pm_text="Note not found!",
				switch_pm_parameter="help"
			)
			return
		note, button = parse_button(noteval.get('value'))
		button = build_keyboard(button)
		answers.append(InlineQueryResultArticle(
						id=uuid4(),
						title="Note #{}".format(notetag),
						input_message_content=InputTextMessageContent(note),
						reply_markup=InlineKeyboardMarkup(button)))
		try:
			await client.answer_inline_query(query.id,
				results=answers,
				cache_time=5,
			)
		except errors.exceptions.bad_request_400.MessageEmpty:
			exc_type, exc_obj, exc_tb = sys.exc_info()
			log_errors = traceback.format_exception(etype=exc_type, value=exc_obj, tb=exc_tb)
			button = InlineKeyboardMarkup([[InlineKeyboardButton("🐞 Report bugs", callback_data="report_errors")]])
			text = "An error has accured!\n\n```{}```\n".format("".join(log_errors))
			await setbot.send_message(Owner, text, reply_markup=button)
			return

	await client.answer_inline_query(query.id,
		results=answers,
		switch_pm_text="Need help? Click here",
		switch_pm_parameter="help"
	)
示例#2
0
async def get_note(client, message):
    if not DB_AVAILABLE:
        await message.edit("Your database is not avaiable!")
        return
    if len(message.text.split()) >= 2:
        note = message.text.split()[1]
    else:
        await message.edit("Give me a note tag!")

    getnotes = db.get_selfnote(message.from_user.id, note)
    if not getnotes:
        await message.edit("This note does not exist!")
        return

    if getnotes["type"] == Types.TEXT:
        teks, button = parse_button(getnotes.get("value"))
        button = build_keyboard(button)
        button = InlineKeyboardMarkup(button) if button else None
        if button:
            try:
                inlineresult = await app.get_inline_bot_results(
                    f"@{BotUsername}", f"note {note}"
                )
            except errors.exceptions.bad_request_400.BotInlineDisabled:
                await message.edit(
                    "Your bot inline isn't available!"
                    "Check your bot for more information!"
                )
                await setbot.send_message(
                    Owner,
                    "Hello, your notes is look like include button,"
                    "but i can't do that "
                    "because **inline mode** is not enabled.",
                )
                return
            try:
                await message.delete()
                await client.send_inline_bot_result(
                    message.chat.id,
                    inlineresult.query_id,
                    inlineresult.results[0].id,
                    reply_to_message_id=ReplyCheck(message),
                )
            except IndexError:
                await message.edit(
                    "An error has accured!"
                    "Check your assistant for more information!"
                )
                return
        else:
            await message.edit(teks)
    elif getnotes["type"] in (
        Types.STICKER,
        Types.VOICE,
        Types.VIDEO_NOTE,
        Types.CONTACT,
        Types.ANIMATED_STICKER,
    ):
        await GET_FORMAT[getnotes["type"]](
            message.chat.id, getnotes["file"],
            reply_to_message_id=ReplyCheck(message)
        )
    else:
        if getnotes.get("value"):
            teks, button = parse_button(getnotes.get("value"))
            button = build_keyboard(button)
            button = InlineKeyboardMarkup(button) if button else None
        else:
            teks = None
            button = None
        if button:
            try:
                inlineresult = await app.get_inline_bot_results(
                    f"@{BotUsername}", f"note {note}"
                )
            except errors.exceptions.bad_request_400.BotInlineDisabled:
                await message.edit(
                    "Your bot inline isn't available!\n"
                    "Check your bot for more information!"
                )
                await setbot.send_message(
                    Owner,
                    "Hello, your notes is look like include button,"
                    "but i can't do that because "
                    "**inline mode** is not enabled."
                )
                return
            try:
                await message.delete()
                await client.send_inline_bot_result(
                    message.chat.id,
                    inlineresult.query_id,
                    inlineresult.results[0].id,
                    reply_to_message_id=ReplyCheck(message),
                )
            except IndexError:
                message.edit(
                    "An error has accured!"
                )
                return
        else:
            await GET_FORMAT[getnotes["type"]](
                message.chat.id,
                getnotes["file"],
                caption=teks,
                reply_to_message_id=ReplyCheck(message),
            )
async def inline_query_handler(client, query):
    string = query.query.lower()
    answers = []

    if query.from_user.id not in AdminSettings:
        await client.answer_inline_query(
            query.id,
            results=answers,
            switch_pm_text="Sorry, this bot only for {}".format(OwnerName),
            switch_pm_parameter="createown")
        return

    if string == "":
        await client.answer_inline_query(
            query.id,
            results=answers,
            switch_pm_text="Need help? Click here",
            switch_pm_parameter="help_inline")
        return

    # Notes
    if string.split()[0] == "note":
        if not DB_AVAILABLE:
            await client.answer_inline_query(
                query.id,
                results=answers,
                switch_pm_text="Your database isn't avaiable!",
                switch_pm_parameter="help_inline")
            return
        if len(string.split()) == 1:
            allnotes = notes_db.get_all_selfnotes_inline(query.from_user.id)
            if not allnotes:
                await client.answer_inline_query(
                    query.id,
                    results=answers,
                    switch_pm_text="You dont have any notes!",
                    switch_pm_parameter="help_inline")
                return
            if len(list(allnotes)) >= 30:
                rng = 30
            else:
                rng = len(list(allnotes))
            for x in range(rng):
                note = allnotes[list(allnotes)[x]]
                noteval = note["value"]
                notetype = note["type"]
                # notefile = note["file"]
                if notetype != Types.TEXT:
                    continue
                note, button = parse_button(noteval)
                button = build_keyboard(button)
                answers.append(
                    InlineQueryResultArticle(
                        title="Note #{}".format(list(allnotes)[x]),
                        description=note,
                        input_message_content=InputTextMessageContent(note),
                        reply_markup=InlineKeyboardMarkup(button)))
            await client.answer_inline_query(query.id,
                                             results=answers,
                                             switch_pm_text="Yourself notes",
                                             switch_pm_parameter="help_inline")
            return
        q = string.split(None, 1)
        notetag = q[1]
        noteval = notes_db.get_selfnote(query.from_user.id, notetag)
        if not noteval:
            await client.answer_inline_query(query.id,
                                             results=answers,
                                             switch_pm_text="Note not found!",
                                             switch_pm_parameter="help_inline")
            return
        note, button = parse_button(noteval.get('value'))
        button = build_keyboard(button)
        answers.append(
            InlineQueryResultArticle(
                title="Note #{}".format(notetag),
                description=note,
                input_message_content=InputTextMessageContent(note),
                reply_markup=InlineKeyboardMarkup(button)))
        try:
            await client.answer_inline_query(query.id,
                                             results=answers,
                                             cache_time=5)
        except errors.exceptions.bad_request_400.MessageEmpty:
            exc_type, exc_obj, exc_tb = sys.exc_info()
            log_errors = traceback.format_exception(etype=exc_type,
                                                    value=exc_obj,
                                                    tb=exc_tb)
            button = InlineKeyboardMarkup([[
                InlineKeyboardButton("🐞 Report bugs",
                                     callback_data="report_errors")
            ]])
            text = "An error has accured!\n\n```{}```\n".format(
                "".join(log_errors))
            await setbot.send_message(Owner, text, reply_markup=button)
            return

    # Stylish converter

    elif string.split()[0] == "stylish":
        if len(string.split()) == 1:
            await client.answer_inline_query(
                query.id,
                results=answers,
                switch_pm_text="Insert any text to convert it!",
                switch_pm_parameter="help_inline")
            return
        text = string.split(None, 1)[1]
        upside = upsidedown_text_inline(text)
        answers.append(
            InlineQueryResultArticle(
                title=upside,
                description="Upside-down Text",
                input_message_content=InputTextMessageContent(upside)))
        over = text_style_generator(text, CHAR_OVER)
        answers.append(
            InlineQueryResultArticle(
                title=over,
                description="Overline Text",
                input_message_content=InputTextMessageContent(over)))
        under = text_style_generator(text, CHAR_UNDER)
        answers.append(
            InlineQueryResultArticle(
                title=under,
                description="Underline Text",
                input_message_content=InputTextMessageContent(under)))
        strike = text_style_generator(text, CHAR_STRIKE)
        answers.append(
            InlineQueryResultArticle(
                title=strike,
                description="Strike Text",
                input_message_content=InputTextMessageContent(strike)))
        points = text_style_generator(text, CHAR_POINTS)
        answers.append(
            InlineQueryResultArticle(
                title=points,
                description="Points Text",
                input_message_content=InputTextMessageContent(points)))
        smallcaps_conv = formatting_text_inline(text, smallcaps)
        answers.append(
            InlineQueryResultArticle(
                title=smallcaps_conv,
                description="Smallcaps Text",
                input_message_content=InputTextMessageContent(smallcaps_conv)))
        super_script = formatting_text_inline(text, superscript)
        answers.append(
            InlineQueryResultArticle(
                title=super_script,
                description="Superscript Text",
                input_message_content=InputTextMessageContent(super_script)))
        sub_script = formatting_text_inline(text, subscript)
        answers.append(
            InlineQueryResultArticle(
                title=sub_script,
                description="Subscript Text",
                input_message_content=InputTextMessageContent(sub_script)))
        wide_text = formatting_text_inline(text, wide)
        answers.append(
            InlineQueryResultArticle(
                title=wide_text,
                description="Wide Text",
                input_message_content=InputTextMessageContent(wide_text)))
        bubbles_text = formatting_text_inline(text, bubbles)
        answers.append(
            InlineQueryResultArticle(
                title=bubbles_text,
                description="Bubbles Text",
                input_message_content=InputTextMessageContent(bubbles_text)))
        bubblesblack_text = formatting_text_inline(text, bubblesblack)
        answers.append(
            InlineQueryResultArticle(
                title=bubblesblack_text,
                description="Bubbles Black Text",
                input_message_content=InputTextMessageContent(
                    bubblesblack_text)))
        smoth_text = formatting_text_inline(text, smothtext)
        answers.append(
            InlineQueryResultArticle(
                title=smoth_text,
                description="Smoth Text",
                input_message_content=InputTextMessageContent(smoth_text)))

        graffiti_text = formatting_text_inline(text, graffiti)
        answers.append(
            InlineQueryResultArticle(
                title=graffiti_text,
                description="Graffiti Text",
                input_message_content=InputTextMessageContent(graffiti_text)))
        graffitib_text = formatting_text_inline(text, graffitib)
        answers.append(
            InlineQueryResultArticle(
                title=graffitib_text,
                description="Graffiti Bold Text",
                input_message_content=InputTextMessageContent(graffitib_text)))
        handwriting_text = formatting_text_inline(text, handwriting)
        answers.append(
            InlineQueryResultArticle(
                title=handwriting_text,
                description="Handwriting Text",
                input_message_content=InputTextMessageContent(
                    handwriting_text)))
        handwritingb_text = formatting_text_inline(text, handwritingb)
        answers.append(
            InlineQueryResultArticle(
                title=handwritingb_text,
                description="Handwriting Bold Text",
                input_message_content=InputTextMessageContent(
                    handwritingb_text)))
        await client.answer_inline_query(
            query.id,
            results=answers,
            switch_pm_text="Converted to stylish text",
            switch_pm_parameter="help_inline")

    # PM_PERMIT
    elif string.split()[0] == "engine_pm":
        button = [[
            InlineKeyboardButton("Ask for Money",
                                 callback_data="engine_pm_block"),
            InlineKeyboardButton("Contact me", callback_data="engine_pm_nope")
        ],
                  [
                      InlineKeyboardButton("Report",
                                           callback_data="engine_pm_report"),
                      InlineKeyboardButton("Passing by",
                                           callback_data="engine_pm_none")
                  ]]
        random.shuffle(button)
        answers.append(
            InlineQueryResultArticle(
                title="Engine pm",
                description="Filter pm",
                input_message_content=InputTextMessageContent(
                    welc_txt, parse_mode="markdown"),
                reply_markup=InlineKeyboardMarkup(button)))
        await client.answer_inline_query(query.id,
                                         results=answers,
                                         cache_time=0)

    elif string.split()[0] == "speedtest":
        buttons = [[
            InlineKeyboardButton("Image", callback_data="speedtest_image"),
            InlineKeyboardButton("Text", callback_data="speedtest_text")
        ]]
        answers.append(
            InlineQueryResultArticle(
                title="Speed Test",
                description="test your speed",
                input_message_content=InputTextMessageContent(
                    "Select SpeedTest Mode", parse_mode="markdown"),
                reply_markup=InlineKeyboardMarkup(buttons)))
        await client.answer_inline_query(query.id,
                                         results=answers,
                                         cache_time=0)
    elif string.split()[0] == "alive":
        repo = git.Repo(os.getcwd())
        master = repo.head.reference
        commit_id = master.commit.hexsha
        commit_link = f"[{commit_id[:7]}](https://github.com/pokurt/Nana-Remix/commit/{commit_id})"
        try:
            me = await app.get_me()
        except ConnectionError:
            me = None
        if not me:
            nana_stats = 'stopped'
        else:
            nana_stats = 'alive'
        buttons = [[
            InlineKeyboardButton("stats", callback_data="alive_message")
        ]]
        answers.append(
            InlineQueryResultArticle(
                title="Alive",
                description="Nana Userbot",
                input_message_content=InputTextMessageContent(
                    tld("alive_str").format(commit_link, nana_stats,
                                            USERBOT_VERSION, __version__,
                                            python_version(), DB_AVAILABLE),
                    parse_mode="markdown",
                    disable_web_page_preview=True),
                reply_markup=InlineKeyboardMarkup(buttons)))
        await client.answer_inline_query(query.id,
                                         results=answers,
                                         cache_time=0)
    elif string.split()[0] == "anime":
        if len(string.split()) == 1:
            await client.answer_inline_query(query.id,
                                             results=answers,
                                             switch_pm_text="Search an Anime",
                                             switch_pm_parameter="help_inline")
            return
        json = (await
                anime_sauce(string.split(None,
                                         1)[1]))['data'].get('Media', None)
        if json:
            msg = f"**{json['title']['romaji']}** (`{json['title']['native']}`)\n**Type**: {json['format']}\n**Status**: {json['status']}\n**Episodes**: {json.get('episodes', 'N/A')}\n**Duration**: {json.get('duration', 'N/A')} Per Ep.\n**Score**: {json['averageScore']}\n**Genres**: `"
            for x in json['genres']:
                msg += f"{x}, "
            msg = msg[:-2] + '`\n'
            msg += "**Studios**: `"
            for x in json['studios']['nodes']:
                msg += f"{x['name']}, "
            msg = msg[:-2] + '`\n'
            info = json.get('siteUrl')
            trailer = json.get('trailer', None)
            if trailer:
                trailer_id = trailer.get('id', None)
                site = trailer.get('site', None)
                if site == "youtube":
                    trailer = 'https://youtu.be/' + trailer_id
            description = json.get('description',
                                   'N/A').replace('<i>', '').replace(
                                       '</i>', '').replace('<br>', '')
            msg += shorten(description, info)
            image = f'https://img.anili.st/media/{json["id"]}'
            if trailer:
                buttons = [
                    [
                        InlineKeyboardButton("More Info", url=info),
                        InlineKeyboardButton("Trailer 🎬", url=trailer)
                    ],
                    [
                        InlineKeyboardButton(
                            'Add to Watchlist',
                            callback_data=f'addfav_{json["title"]["romaji"]}')
                    ]
                ]
            else:
                buttons = [[
                    InlineKeyboardButton("More Info", url=info),
                    InlineKeyboardButton(
                        'Add to Watchlist',
                        callback_data=f'addfav_{json["title"]["romaji"]}')
                ]]
            if image:
                answers.append(
                    InlineQueryResultPhoto(
                        caption=msg,
                        photo_url=image,
                        parse_mode="markdown",
                        title=f"{json['title']['romaji']}",
                        description=f"{json['format']}",
                        reply_markup=InlineKeyboardMarkup(buttons)))
            else:
                answers.append(
                    InlineQueryResultArticle(
                        title=f"{json['title']['romaji']}",
                        description=f"{json['averageScore']}",
                        input_message_content=InputTextMessageContent(
                            msg,
                            parse_mode="markdown",
                            disable_web_page_preview=True),
                        reply_markup=InlineKeyboardMarkup(buttons)))
        await client.answer_inline_query(query.id,
                                         results=answers,
                                         cache_time=0)

    elif string.split()[0] == "favourite":
        fav = sql.get_fav(Owner)
        if fav:
            text = "**My watchlist:**\n"
            for title in fav:
                text += f" - {title.data}\n"
            keyb = [[
                InlineKeyboardButton(text="Watched ✅",
                                     callback_data=f"remfav_{Owner}")
            ]]
            answers.append(
                InlineQueryResultArticle(
                    title="Favourites",
                    description="Anime",
                    input_message_content=InputTextMessageContent(
                        text, parse_mode="markdown"),
                    reply_markup=InlineKeyboardMarkup(keyb)))
        else:
            answers.append(
                InlineQueryResultArticle(
                    title="Fabourites",
                    description="Anime",
                    input_message_content=InputTextMessageContent(
                        "**No favourites yet!**", parse_mode="markdown")))
        await client.answer_inline_query(query.id,
                                         results=answers,
                                         cache_time=0)
        return
示例#4
0
async def inline_query_handler(client, query):
    string = query.query.lower()
    answers = []

    if query.from_user.id not in AdminSettings:
        await client.answer_inline_query(
            query.id,
            results=answers,
            switch_pm_text="Sorry, this bot only for {}".format(OwnerName),
            switch_pm_parameter="createown")
        return

    if string == "":
        await client.answer_inline_query(
            query.id,
            results=answers,
            switch_pm_text="Need help? Click here",
            switch_pm_parameter="help_inline")
        return

    # Notes
    if string.split()[0] == "note":
        if not DB_AVAILABLE:
            await client.answer_inline_query(
                query.id,
                results=answers,
                switch_pm_text="Your database isn't avaiable!",
                switch_pm_parameter="help_inline")
            return
        if len(string.split()) == 1:
            allnotes = notes_db.get_all_selfnotes_inline(query.from_user.id)
            if not allnotes:
                await client.answer_inline_query(
                    query.id,
                    results=answers,
                    switch_pm_text="You dont have any notes!",
                    switch_pm_parameter="help_inline")
                return
            if len(list(allnotes)) >= 30:
                rng = 30
            else:
                rng = len(list(allnotes))
            for x in range(rng):
                note = allnotes[list(allnotes)[x]]
                noteval = note["value"]
                notetype = note["type"]
                # notefile = note["file"]
                if notetype != Types.TEXT:
                    continue
                note, button = parse_button(noteval)
                button = build_keyboard(button)
                answers.append(
                    InlineQueryResultArticle(
                        title="Note #{}".format(list(allnotes)[x]),
                        description=note,
                        input_message_content=InputTextMessageContent(note),
                        reply_markup=InlineKeyboardMarkup(button)))
            await client.answer_inline_query(query.id,
                                             results=answers,
                                             switch_pm_text="Yourself notes",
                                             switch_pm_parameter="help_inline")
            return
        q = string.split(None, 1)
        notetag = q[1]
        noteval = notes_db.get_selfnote(query.from_user.id, notetag)
        if not noteval:
            await client.answer_inline_query(query.id,
                                             results=answers,
                                             switch_pm_text="Note not found!",
                                             switch_pm_parameter="help_inline")
            return
        note, button = parse_button(noteval.get('value'))
        button = build_keyboard(button)
        answers.append(
            InlineQueryResultArticle(
                title="Note #{}".format(notetag),
                description=note,
                input_message_content=InputTextMessageContent(note),
                reply_markup=InlineKeyboardMarkup(button)))
        try:
            await client.answer_inline_query(query.id,
                                             results=answers,
                                             cache_time=5)
        except errors.exceptions.bad_request_400.MessageEmpty:
            exc_type, exc_obj, exc_tb = sys.exc_info()
            log_errors = traceback.format_exception(etype=exc_type,
                                                    value=exc_obj,
                                                    tb=exc_tb)
            button = InlineKeyboardMarkup([[
                InlineKeyboardButton("🐞 Report bugs",
                                     callback_data="report_errors")
            ]])
            text = "An error has accured!\n\n```{}```\n".format(
                "".join(log_errors))
            await setbot.send_message(Owner, text, reply_markup=button)
            return

    # Stylish converter

    elif string.split()[0] == "stylish":
        if len(string.split()) == 1:
            await client.answer_inline_query(
                query.id,
                results=answers,
                switch_pm_text="Insert any text to convert it!",
                switch_pm_parameter="help_inline")
            return
        text = string.split(None, 1)[1]
        upside = upsidedown_text_inline(text)
        answers.append(
            InlineQueryResultArticle(
                title=upside,
                description="Upside-down Text",
                input_message_content=InputTextMessageContent(upside)))
        over = text_style_generator(text, CHAR_OVER)
        answers.append(
            InlineQueryResultArticle(
                title=over,
                description="Overline Text",
                input_message_content=InputTextMessageContent(over)))
        under = text_style_generator(text, CHAR_UNDER)
        answers.append(
            InlineQueryResultArticle(
                title=under,
                description="Underline Text",
                input_message_content=InputTextMessageContent(under)))
        strike = text_style_generator(text, CHAR_STRIKE)
        answers.append(
            InlineQueryResultArticle(
                title=strike,
                description="Strike Text",
                input_message_content=InputTextMessageContent(strike)))
        points = text_style_generator(text, CHAR_POINTS)
        answers.append(
            InlineQueryResultArticle(
                title=points,
                description="Points Text",
                input_message_content=InputTextMessageContent(points)))
        smallcaps_conv = formatting_text_inline(text, smallcaps)
        answers.append(
            InlineQueryResultArticle(
                title=smallcaps_conv,
                description="Smallcaps Text",
                input_message_content=InputTextMessageContent(smallcaps_conv)))
        super_script = formatting_text_inline(text, superscript)
        answers.append(
            InlineQueryResultArticle(
                title=super_script,
                description="Superscript Text",
                input_message_content=InputTextMessageContent(super_script)))
        sub_script = formatting_text_inline(text, subscript)
        answers.append(
            InlineQueryResultArticle(
                title=sub_script,
                description="Subscript Text",
                input_message_content=InputTextMessageContent(sub_script)))
        wide_text = formatting_text_inline(text, wide)
        answers.append(
            InlineQueryResultArticle(
                title=wide_text,
                description="Wide Text",
                input_message_content=InputTextMessageContent(wide_text)))
        bubbles_text = formatting_text_inline(text, bubbles)
        answers.append(
            InlineQueryResultArticle(
                title=bubbles_text,
                description="Bubbles Text",
                input_message_content=InputTextMessageContent(bubbles_text)))
        bubblesblack_text = formatting_text_inline(text, bubblesblack)
        answers.append(
            InlineQueryResultArticle(
                title=bubblesblack_text,
                description="Bubbles Black Text",
                input_message_content=InputTextMessageContent(
                    bubblesblack_text)))
        smoth_text = formatting_text_inline(text, smothtext)
        answers.append(
            InlineQueryResultArticle(
                title=smoth_text,
                description="Smoth Text",
                input_message_content=InputTextMessageContent(smoth_text)))

        graffiti_text = formatting_text_inline(text, graffiti)
        answers.append(
            InlineQueryResultArticle(
                title=graffiti_text,
                description="Graffiti Text",
                input_message_content=InputTextMessageContent(graffiti_text)))
        graffitib_text = formatting_text_inline(text, graffitib)
        answers.append(
            InlineQueryResultArticle(
                title=graffitib_text,
                description="Graffiti Bold Text",
                input_message_content=InputTextMessageContent(graffitib_text)))
        handwriting_text = formatting_text_inline(text, handwriting)
        answers.append(
            InlineQueryResultArticle(
                title=handwriting_text,
                description="Handwriting Text",
                input_message_content=InputTextMessageContent(
                    handwriting_text)))
        handwritingb_text = formatting_text_inline(text, handwritingb)
        answers.append(
            InlineQueryResultArticle(
                title=handwritingb_text,
                description="Handwriting Bold Text",
                input_message_content=InputTextMessageContent(
                    handwritingb_text)))
        await client.answer_inline_query(
            query.id,
            results=answers,
            switch_pm_text="Converted to stylish text",
            switch_pm_parameter="help_inline")

    # PM_PERMIT
    elif string.split()[0] == "engine_pm":
        button = [[
            InlineKeyboardButton("Ask for Money",
                                 callback_data="engine_pm_block"),
            InlineKeyboardButton("Contact me", callback_data="engine_pm_nope")
        ],
                  [
                      InlineKeyboardButton("Report",
                                           callback_data="engine_pm_report"),
                      InlineKeyboardButton("Passing by",
                                           callback_data="engine_pm_none")
                  ]]
        random.shuffle(button)
        answers.append(
            InlineQueryResultArticle(
                title="Engine pm",
                description="Filter pm",
                input_message_content=InputTextMessageContent(
                    welc_txt, parse_mode="markdown"),
                reply_markup=InlineKeyboardMarkup(button)))
        await client.answer_inline_query(query.id,
                                         results=answers,
                                         cache_time=0)

    elif string.split()[0] == "speedtest":
        buttons = [[
            InlineKeyboardButton("Image", callback_data="speedtest_image"),
            InlineKeyboardButton("Text", callback_data="speedtest_text")
        ]]
        answers.append(
            InlineQueryResultArticle(
                title="Speed Test",
                description="test your speed",
                input_message_content=InputTextMessageContent(
                    "Select SpeedTest Mode", parse_mode="markdown"),
                reply_markup=InlineKeyboardMarkup(buttons)))
        await client.answer_inline_query(query.id,
                                         results=answers,
                                         cache_time=0)
    elif string.split()[0] == "alive":
        repo = git.Repo(os.getcwd())
        master = repo.head.reference
        commit_id = master.commit.hexsha
        commit_link = f"[{commit_id[:7]}](https://github.com/pokurt/Nana-Remix/commit/{commit_id})"
        try:
            me = await app.get_me()
        except ConnectionError:
            me = None
        if not me:
            nana_stats = 'stopped'
        else:
            nana_stats = 'alive'
        buttons = [[
            InlineKeyboardButton("stats", callback_data="alive_message")
        ]]
        answers.append(
            InlineQueryResultArticle(
                title="Alive",
                description="Nana Userbot",
                input_message_content=InputTextMessageContent(
                    tld("alive_str").format(commit_link, nana_stats,
                                            USERBOT_VERSION, __version__,
                                            python_version(), DB_AVAILABLE),
                    parse_mode="markdown",
                    disable_web_page_preview=True),
                reply_markup=InlineKeyboardMarkup(buttons)))
        await client.answer_inline_query(query.id,
                                         results=answers,
                                         cache_time=0)
    elif string.split()[0] == "anime":
        if len(string.split()) == 1:
            await client.answer_inline_query(query.id,
                                             results=answers,
                                             switch_pm_text="Search an Anime",
                                             switch_pm_parameter="help_inline")
            return
        search = string.split(None, 1)[1]
        variables = {'search': search}
        async with aiohttp.ClientSession() as session:
            async with session.post(url,
                                    json={
                                        'query': anime_query,
                                        'variables': variables
                                    }) as resp:
                r = await resp.json()
                json = r['data'].get('Media', None)
                if json:
                    msg = f"**{json['title']['romaji']}** (`{json['title']['native']}`)\n**Type**: {json['format']}\n**Status**: {json['status']}\n**Episodes**: {json.get('episodes', 'N/A')}\n**Duration**: {json.get('duration', 'N/A')} Per Ep.\n**Score**: {json['averageScore']}\n**Genres**: `"
                    for x in json['genres']:
                        msg += f"{x}, "
                    msg = msg[:-2] + '`\n'
                    msg += "**Studios**: `"
                    for x in json['studios']['nodes']:
                        msg += f"{x['name']}, "
                    msg = msg[:-2] + '`\n'
                    info = json.get('siteUrl')
                    trailer = json.get('trailer', None)
                    if trailer:
                        trailer_id = trailer.get('id', None)
                        site = trailer.get('site', None)
                        if site == "youtube":
                            trailer = 'https://youtu.be/' + trailer_id
                    description = json.get('description', 'N/A').replace(
                        '<i>', '').replace('</i>', '').replace('<br>', '')
                    msg += shorten(description, info)
                    image = json.get('bannerImage', None)
                    if trailer:
                        buttons = [[
                            InlineKeyboardButton("More Info", url=info),
                            InlineKeyboardButton("Trailer 🎬", url=trailer)
                        ],
                                   [
                                       InlineKeyboardButton(
                                           'Add to Watchlist',
                                           callback_data=
                                           f'addfav_{json["title"]["romaji"]}')
                                   ]]
                    else:
                        buttons = [[
                            InlineKeyboardButton("More Info", url=info),
                            InlineKeyboardButton(
                                'Add to Watchlist',
                                callback_data=
                                f'addfav_{json["title"]["romaji"]}')
                        ]]
                    if image:
                        answers.append(
                            InlineQueryResultPhoto(
                                caption=msg,
                                photo_url=image,
                                parse_mode="markdown",
                                title=f"{json['title']['romaji']}",
                                description=f"{json['format']}",
                                reply_markup=InlineKeyboardMarkup(buttons)))
                    else:
                        answers.append(
                            InlineQueryResultArticle(
                                title=f"{json['title']['romaji']}",
                                description=f"{json['averageScore']}",
                                input_message_content=InputTextMessageContent(
                                    msg,
                                    parse_mode="markdown",
                                    disable_web_page_preview=True),
                                reply_markup=InlineKeyboardMarkup(buttons)))
        await client.answer_inline_query(query.id,
                                         results=answers,
                                         cache_time=0)

    elif string.split()[0] == "favourite":
        fav = sql.get_fav(Owner)
        if fav:
            text = "**My watchlist:**\n"
            for title in fav:
                text += f" - {title.data}\n"
            keyb = [[
                InlineKeyboardButton(text="Watched ✅",
                                     callback_data=f"remfav_{Owner}")
            ]]
            answers.append(
                InlineQueryResultArticle(
                    title="Favourites",
                    description="Anime",
                    input_message_content=InputTextMessageContent(
                        text, parse_mode="markdown"),
                    reply_markup=InlineKeyboardMarkup(keyb)))
        else:
            answers.append(
                InlineQueryResultArticle(
                    title="Fabourites",
                    description="Anime",
                    input_message_content=InputTextMessageContent(
                        "**No favourites yet!**", parse_mode="markdown")))
        await client.answer_inline_query(query.id,
                                         results=answers,
                                         cache_time=0)

    elif string.split()[0] == "favourite":
        fav = sql.get_fav(Owner)
        if fav:
            text = "**My watchlist:**\n"
            for title in fav:
                text += f" - {title.data}\n"
            keyb = [[
                InlineKeyboardButton(text="Watched ✅",
                                     callback_data=f"remfav_{Owner}")
            ]]
            answers.append(
                InlineQueryResultArticle(
                    title="Favourites",
                    description="Anime",
                    input_message_content=InputTextMessageContent(
                        text, parse_mode="markdown"),
                    reply_markup=InlineKeyboardMarkup(keyb)))
        else:
            answers.append(
                InlineQueryResultArticle(
                    title="Fabourites",
                    description="Anime",
                    input_message_content=InputTextMessageContent(
                        "**No favourites yet!**", parse_mode="markdown")))
        await client.answer_inline_query(query.id,
                                         results=answers,
                                         cache_time=0)

    elif string.split()[0] == "cat":
        image = f"https://d2ph5fj80uercy.cloudfront.net/0{random.randint(1, 6)}/cat{random.randint(0,4999)}.jpg"
        buttons = [[
            InlineKeyboardButton("Source",
                                 url="https://thiscatdoesnotexist.com/"),
            InlineKeyboardButton("Refresh", callback_data='cat_pic')
        ]]
        answers.append(
            InlineQueryResultPhoto(caption='Hi I like you too >~<',
                                   photo_url=image,
                                   parse_mode="markdown",
                                   title="Cursed Cat",
                                   description="Cursed Cat",
                                   reply_markup=InlineKeyboardMarkup(buttons)))
        await client.answer_inline_query(query.id,
                                         results=answers,
                                         cache_time=0)

    if string.split()[0] == "lookup":
        if len(string.split()) == 1:
            await client.answer_inline_query(
                query.id,
                results=answers,
                switch_pm_text="Search in SpamProtection Database",
                switch_pm_parameter="help_inline")
            return
        get_user = string.split(None, 1)[1]
        try:
            user = await app.get_chat(get_user)
        except PeerIdInvalid:
            await client.answer_inline_query(
                query.id,
                results=answers,
                switch_pm_text="Can't Find the Chat in Database",
                switch_pm_parameter="help_inline")
            return
        api_url = f'https://api.intellivoid.net/spamprotection/v1/lookup?query={user.id}'
        a = await AioHttp().get_json(api_url)
        response = a['success']
        if response == True:
            date = a["results"]["last_updated"]
            stats = f'**◢ Intellivoid• SpamProtection Info**:\n'
            stats += f' - **Updated on**: `{datetime.fromtimestamp(date).strftime("%Y-%m-%d %I:%M:%S %p")}`\n'
            if a["results"]["attributes"]["is_potential_spammer"] == True:
                stats += f' - **User**: `USERxSPAM`\n'
            elif a["results"]["attributes"]["is_operator"] == True:
                stats += f' - **User**: `USERxOPERATOR`\n'
            elif a["results"]["attributes"]["is_agent"] == True:
                stats += f' - **User**: `USERxAGENT`\n'
            elif a["results"]["attributes"]["is_whitelisted"] == True:
                stats += f' - **User**: `USERxWHITELISTED`\n'

            stats += f' - **Type**: `{a["results"]["entity_type"]}`\n'
            stats += f' - **Language**: `{a["results"]["language_prediction"]["language"]}`\n'
            stats += f' - **Language Probability**: `{a["results"]["language_prediction"]["probability"]}`\n'
            stats += f'**Spam Prediction**:\n'
            stats += f' - **Ham Prediction**: `{a["results"]["spam_prediction"]["ham_prediction"]}`\n'
            stats += f' - **Spam Prediction**: `{a["results"]["spam_prediction"]["spam_prediction"]}`\n'
            stats += f'**Blacklisted**: `{a["results"]["attributes"]["is_blacklisted"]}`\n'
            if a["results"]["attributes"]["is_blacklisted"] == True:
                stats += f' - **Reason**: `{a["results"]["attributes"]["blacklist_reason"]}`\n'
                stats += f' - **Flag**: `{a["results"]["attributes"]["blacklist_flag"]}`\n'
            stats += f'**TELEGRAM HASH**:\n`{a["results"]["private_telegram_id"]}`\n'
        buttons = [[
            InlineKeyboardButton("Logs",
                                 url="https://t.me/SpamProtectionLogs"),
            InlineKeyboardButton(
                'Info', url=f't.me/SpamProtectionBot/?start=00_{user.id}')
        ]]
        answers.append(
            InlineQueryResultArticle(
                title=f'{a["results"]["entity_type"]}',
                description=f'{a["results"]["private_telegram_id"]}',
                input_message_content=InputTextMessageContent(
                    stats,
                    parse_mode="markdown",
                    disable_web_page_preview=True),
                reply_markup=InlineKeyboardMarkup(buttons)))
        await client.answer_inline_query(query.id,
                                         results=answers,
                                         cache_time=0)
        return
示例#5
0
async def get_note(client, message):
    if not DB_AVAIABLE:
        await message.edit("Your database is not avaiable!")
        return
    is_hash = False
    if len(message.text.split()) >= 2:
        note = message.text.split()[1]
    else:
        await message.edit("Give me a note tag!")

    getnotes = db.get_selfnote(message.from_user.id, note)
    if not getnotes:
        await message.edit("This note does not exist!")
        return

    replyid = None  # message.message_id
    if message.reply_to_message:
        replyid = message.reply_to_message.message_id

    if getnotes['type'] == Types.TEXT:
        teks, button = parse_button(getnotes.get('value'))
        button = build_keyboard(button)
        if button:
            button = InlineKeyboardMarkup(button)
        else:
            button = None
        if button:
            await message.edit(
                "Inline button not supported in this userbot version :(\nSee @AyraSupport for more information"
            )
            return
        else:
            await message.edit(teks)
    elif getnotes['type'] in (Types.STICKER, Types.VOICE, Types.VIDEO_NOTE,
                              Types.CONTACT, Types.ANIMATED_STICKER):
        await message.delete()
        try:
            if replyid:
                await GET_FORMAT[getnotes['type']
                                 ](message.chat.id,
                                   getnotes['file'],
                                   file_ref=getnotes['file_ref'],
                                   reply_to_message_id=replyid)
            else:
                await GET_FORMAT[getnotes['type']
                                 ](message.chat.id,
                                   getnotes['file'],
                                   file_ref=getnotes['file_ref'])
        except errors.exceptions.bad_request_400.BadRequest:
            msg = await client.get_messages(Owner, getnotes['message_id'])
            note_name, text, data_type, content, file_ref = fetch_note_type(
                msg)
            db.save_selfnote(Owner, note, "", getnotes['type'], content,
                             file_ref, getnotes['message_id'])
            if replyid:
                await GET_FORMAT[getnotes['type']](message.chat.id,
                                                   content,
                                                   file_ref=file_ref,
                                                   reply_to_message_id=replyid)
            else:
                await GET_FORMAT[getnotes['type']](message.chat.id,
                                                   content,
                                                   file_ref=file_ref)
    else:
        await message.delete()
        if getnotes.get('value'):
            teks, button = parse_button(getnotes.get('value'))
            button = build_keyboard(button)
            if button:
                button = InlineKeyboardMarkup(button)
            else:
                button = None
        else:
            teks = None
            button = None
        if button:
            await message.edit(
                "Inline button not supported in this userbot version :(\nSee @AyraSupport for more information"
            )
            return
        else:
            try:
                if replyid:
                    await GET_FORMAT[getnotes['type']
                                     ](message.chat.id,
                                       getnotes['file'],
                                       file_ref=getnotes['file_ref'],
                                       caption=teks,
                                       reply_to_message_id=replyid)
                else:
                    await GET_FORMAT[getnotes['type']
                                     ](message.chat.id,
                                       getnotes['file'],
                                       file_ref=getnotes['file_ref'],
                                       caption=teks)
            except errors.exceptions.bad_request_400.BadRequest:
                msg = await client.get_messages(Owner, getnotes['message_id'])
                note_name, text, data_type, content, file_ref = fetch_note_type(
                    msg)
                db.save_selfnote(Owner, note, teks, getnotes['type'], content,
                                 file_ref, getnotes['message_id'])
                if replyid:
                    await GET_FORMAT[getnotes['type']
                                     ](message.chat.id,
                                       getnotes['file'],
                                       file_ref=getnotes['file_ref'],
                                       caption=teks,
                                       reply_to_message_id=replyid)
                else:
                    await GET_FORMAT[getnotes['type']
                                     ](message.chat.id,
                                       getnotes['file'],
                                       file_ref=getnotes['file_ref'],
                                       caption=teks)
示例#6
0
async def inline_query_handler(client, query):
    string = query.query.lower()
    answers = []

    if query.from_user.id != Owner:
        await client.answer_inline_query(
            query.id,
            results=answers,
            switch_pm_text="Sorry, this bot only for {}".format(OwnerName),
            switch_pm_parameter="createown")
        return

    if string == "":
        await client.answer_inline_query(
            query.id,
            results=answers,
            switch_pm_text="Need help? Click here",
            switch_pm_parameter="help_inline")
        return

    # Notes
    if string.split()[0] == "#note":
        if not DB_AVAIABLE:
            await client.answer_inline_query(
                query.id,
                results=answers,
                switch_pm_text="Your database isn't avaiable!",
                switch_pm_parameter="help_inline")
            return
        if len(string.split()) == 1:
            allnotes = notes_db.get_all_selfnotes_inline(query.from_user.id)
            if not allnotes:
                await client.answer_inline_query(
                    query.id,
                    results=answers,
                    switch_pm_text="You dont have any notes!",
                    switch_pm_parameter="help_inline")
                return
            if len(list(allnotes)) >= 30:
                rng = 30
            else:
                rng = len(list(allnotes))
            for x in range(rng):
                note = allnotes[list(allnotes)[x]]
                noteval = note["value"]
                notetype = note["type"]
                # notefile = note["file"]
                if notetype != Types.TEXT:
                    continue
                note, button = parse_button(noteval)
                button = build_keyboard(button)
                answers.append(
                    InlineQueryResultArticle(
                        title="Note #{}".format(list(allnotes)[x]),
                        description=note,
                        input_message_content=InputTextMessageContent(note),
                        reply_markup=InlineKeyboardMarkup(button)))
            await client.answer_inline_query(query.id,
                                             results=answers,
                                             switch_pm_text="Yourself notes",
                                             switch_pm_parameter="help_inline")
            return
        q = string.split(None, 1)
        notetag = q[1]
        noteval = notes_db.get_selfnote(query.from_user.id, notetag)
        if not noteval:
            await client.answer_inline_query(query.id,
                                             results=answers,
                                             switch_pm_text="Note not found!",
                                             switch_pm_parameter="help_inline")
            return
        note, button = parse_button(noteval.get('value'))
        button = build_keyboard(button)
        answers.append(
            InlineQueryResultArticle(
                title="Note #{}".format(notetag),
                description=note,
                input_message_content=InputTextMessageContent(note),
                reply_markup=InlineKeyboardMarkup(button)))
        try:
            await client.answer_inline_query(
                query.id,
                results=answers,
                cache_time=5,
            )
        except errors.exceptions.bad_request_400.MessageEmpty:
            exc_type, exc_obj, exc_tb = sys.exc_info()
            log_errors = traceback.format_exception(etype=exc_type,
                                                    value=exc_obj,
                                                    tb=exc_tb)
            button = InlineKeyboardMarkup([[
                InlineKeyboardButton("🐞 Report bugs",
                                     callback_data="report_errors")
            ]])
            text = "An error has accured!\n\n```{}```\n".format(
                "".join(log_errors))
            await setbot.send_message(Owner, text, reply_markup=button)
            return

    # Stylish converter

    elif string.split()[0] == "#stylish":
        if len(string.split()) == 1:
            await client.answer_inline_query(
                query.id,
                results=answers,
                switch_pm_text="Insert any text to convert it!",
                switch_pm_parameter="help_inline")
            return
        text = string.split(None, 1)[1]
        upside = upsidedown_text_inline(text)
        answers.append(
            InlineQueryResultArticle(
                title=upside,
                description="Upside-down Text",
                input_message_content=InputTextMessageContent(upside)))
        over = text_style_generator(text, CHAR_OVER)
        answers.append(
            InlineQueryResultArticle(
                title=over,
                description="Overline Text",
                input_message_content=InputTextMessageContent(over)))
        under = text_style_generator(text, CHAR_UNDER)
        answers.append(
            InlineQueryResultArticle(
                title=under,
                description="Underline Text",
                input_message_content=InputTextMessageContent(under)))
        strike = text_style_generator(text, CHAR_STRIKE)
        answers.append(
            InlineQueryResultArticle(
                title=strike,
                description="Strike Text",
                input_message_content=InputTextMessageContent(strike)))
        points = text_style_generator(text, CHAR_POINTS)
        answers.append(
            InlineQueryResultArticle(
                title=points,
                description="Points Text",
                input_message_content=InputTextMessageContent(points)))
        smallcaps_conv = formatting_text_inline(text, smallcaps)
        answers.append(
            InlineQueryResultArticle(
                title=smallcaps_conv,
                description="Smallcaps Text",
                input_message_content=InputTextMessageContent(smallcaps_conv)))
        super_script = formatting_text_inline(text, superscript)
        answers.append(
            InlineQueryResultArticle(
                title=super_script,
                description="Superscript Text",
                input_message_content=InputTextMessageContent(super_script)))
        sub_script = formatting_text_inline(text, subscript)
        answers.append(
            InlineQueryResultArticle(
                title=sub_script,
                description="Subscript Text",
                input_message_content=InputTextMessageContent(sub_script)))
        wide_text = formatting_text_inline(text, wide)
        answers.append(
            InlineQueryResultArticle(
                title=wide_text,
                description="Wide Text",
                input_message_content=InputTextMessageContent(wide_text)))
        bubbles_text = formatting_text_inline(text, bubbles)
        answers.append(
            InlineQueryResultArticle(
                title=bubbles_text,
                description="Bubbles Text",
                input_message_content=InputTextMessageContent(bubbles_text)))
        bubblesblack_text = formatting_text_inline(text, bubblesblack)
        answers.append(
            InlineQueryResultArticle(
                title=bubblesblack_text,
                description="Bubbles Black Text",
                input_message_content=InputTextMessageContent(
                    bubblesblack_text)))
        smoth_text = formatting_text_inline(text, smothtext)
        answers.append(
            InlineQueryResultArticle(
                title=smoth_text,
                description="Smoth Text",
                input_message_content=InputTextMessageContent(smoth_text)))
        await client.answer_inline_query(
            query.id,
            results=answers,
            switch_pm_text="Converted to stylish text",
            switch_pm_parameter="help_inline")
        return

    await client.answer_inline_query(query.id,
                                     results=answers,
                                     switch_pm_text="Need help? Click here",
                                     switch_pm_parameter="help_inline")
示例#7
0
async def get_note(client, message):
    if not DB_AVAIABLE:
        await message.edit("Your database is not avaiable!")
        return
    if len(message.text.split()) >= 2:
        note = message.text.split()[1]
    else:
        await message.edit("Give me a note tag!")

    getnotes = db.get_selfnote(message.from_user.id, note)
    if not getnotes:
        await message.edit("This note does not exist!")
        return

    replyid = message.message_id
    if message.reply_to_message:
        replyid = message.reply_to_message.message_id

    if getnotes['type'] == Types.TEXT:
        teks, button = parse_button(getnotes.get('value'))
        button = build_keyboard(button)
        if button:
            button = InlineKeyboardMarkup(button)
        else:
            button = None
        if button:
            try:
                inlineresult = await app.get_inline_bot_results(
                    "@{}".format(BotUsername), "#note {}".format(note))
            except errors.exceptions.bad_request_400.BotInlineDisabled:
                await message.edit(
                    "Your bot inline isn't available!\nCheck your bot for more information!"
                )
                await setbot.send_message(
                    Owner,
                    "Hello, your notes is look like include button, but i can't do that "
                    "because **inline mode** is not enabled.\n\n**To enable inline "
                    "mode:**\n1. Go to @BotFather and type `/mybots`\n2. Select your bot, "
                    "then click **Bot Settings**, click **Inline Mode**, then click "
                    "**Turn on**.\nOther option is optional, you can edit inline "
                    "placeholder as you like!\n\nAfter that, you can try again to get "
                    "that note!")
                return
            try:
                await client.send_inline_bot_result(
                    message.chat.id,
                    inlineresult.query_id,
                    inlineresult.results[0].id,
                    reply_to_message_id=replyid)
            except IndexError:
                await message.edit(
                    "An error has accured! Check your assistant for more information!"
                )
                return
        else:
            await message.edit(teks)
    elif getnotes['type'] in (Types.STICKER, Types.VOICE, Types.VIDEO_NOTE,
                              Types.CONTACT, Types.ANIMATED_STICKER):
        await GET_FORMAT[getnotes['type']](message.chat.id,
                                           getnotes['file'],
                                           reply_to_message_id=replyid)
    else:
        if getnotes.get('value'):
            teks, button = parse_button(getnotes.get('value'))
            button = build_keyboard(button)
            if button:
                button = InlineKeyboardMarkup(button)
            else:
                button = None
        else:
            teks = None
            button = None
        if button:
            try:
                inlineresult = await app.get_inline_bot_results(
                    "@{}".format(BotUsername), "#note {}".format(note))
            except errors.exceptions.bad_request_400.BotInlineDisabled:
                await message.edit(
                    "Your bot inline isn't available!\nCheck your bot for more information!"
                )
                await setbot.send_message(
                    Owner,
                    "Hello, your notes is look like include button, but i can't do that because "
                    "**inline mode** is not enabled.\n\n**To enable inline mode:**\n1. Go to "
                    "@BotFather and type `/mybots`\n2. Select your bot, then click **Bot "
                    "Settings**, click **Inline Mode**, then click **Turn on**.\nOther option is "
                    "optional, you can edit inline placeholder as you like!\n\nAfter that, "
                    "you can try again to get that note!")
                return
            try:
                await client.send_inline_bot_result(
                    message.chat.id,
                    inlineresult.query_id,
                    inlineresult.results[0].id,
                    reply_to_message_id=replyid)
            except IndexError:
                message.edit(
                    "An error has accured! Check your assistant for more information!"
                )
                return
        else:
            await GET_FORMAT[getnotes['type']](message.chat.id,
                                               getnotes['file'],
                                               caption=teks,
                                               reply_to_message_id=replyid)
示例#8
0
async def inline_query_handler(client, query):
    string = query.query.lower()
    answers = []

    if query.from_user.id != Owner:
        await client.answer_inline_query(query.id,
                                         results=answers,
                                         switch_pm_text="Sorry, this bot only for {}".format(OwnerName),
                                         switch_pm_parameter="createown"
                                         )
        return

    if string == "":
        await client.answer_inline_query(query.id,
                                         results=answers,
                                         switch_pm_text="Need help? Click here",
                                         switch_pm_parameter="help_inline"
                                         )
        return

    # Notes
    if string.split()[0] == "note":
        if not DB_AVAILABLE:
            await client.answer_inline_query(query.id,
                                             results=answers,
                                             switch_pm_text="Your database isn't avaiable!",
                                             switch_pm_parameter="help_inline"
                                             )
            return
        if len(string.split()) == 1:
            allnotes = notes_db.get_all_selfnotes_inline(query.from_user.id)
            if not allnotes:
                await client.answer_inline_query(query.id,
                                                 results=answers,
                                                 switch_pm_text="You dont have any notes!",
                                                 switch_pm_parameter="help_inline"
                                                 )
                return
            if len(list(allnotes)) >= 30:
                rng = 30
            else:
                rng = len(list(allnotes))
            for x in range(rng):
                note = allnotes[list(allnotes)[x]]
                noteval = note["value"]
                notetype = note["type"]
                # notefile = note["file"]
                if notetype != Types.TEXT:
                    continue
                note, button = parse_button(noteval)
                button = build_keyboard(button)
                answers.append(InlineQueryResultArticle(
                    title="Note #{}".format(list(allnotes)[x]),
                    description=note,
                    input_message_content=InputTextMessageContent(note),
                    reply_markup=InlineKeyboardMarkup(button)))
            await client.answer_inline_query(query.id,
                                             results=answers,
                                             switch_pm_text="Yourself notes",
                                             switch_pm_parameter="help_inline"
                                             )
            return
        q = string.split(None, 1)
        notetag = q[1]
        noteval = notes_db.get_selfnote(query.from_user.id, notetag)
        if not noteval:
            await client.answer_inline_query(query.id,
                                             results=answers,
                                             switch_pm_text="Note not found!",
                                             switch_pm_parameter="help_inline"
                                             )
            return
        note, button = parse_button(noteval.get('value'))
        button = build_keyboard(button)
        answers.append(InlineQueryResultArticle(
            title="Note #{}".format(notetag),
            description=note,
            input_message_content=InputTextMessageContent(note),
            reply_markup=InlineKeyboardMarkup(button)))
        try:
            await client.answer_inline_query(query.id,
                                             results=answers,
                                             cache_time=5
                                             )
        except errors.exceptions.bad_request_400.MessageEmpty:
            exc_type, exc_obj, exc_tb = sys.exc_info()
            log_errors = traceback.format_exception(etype=exc_type, value=exc_obj, tb=exc_tb)
            button = InlineKeyboardMarkup([[InlineKeyboardButton("🐞 Report bugs", callback_data="report_errors")]])
            text = "An error has accured!\n\n```{}```\n".format("".join(log_errors))
            await setbot.send_message(Owner, text, reply_markup=button)
            return

    # Stylish converter

    elif string.split()[0] == "stylish":
        if len(string.split()) == 1:
            await client.answer_inline_query(query.id,
                                             results=answers,
                                             switch_pm_text="Insert any text to convert it!",
                                             switch_pm_parameter="help_inline"
                                             )
            return
        text = string.split(None, 1)[1]
        upside = upsidedown_text_inline(text)
        answers.append(InlineQueryResultArticle(
            title=upside,
            description="Upside-down Text",
            input_message_content=InputTextMessageContent(upside)))
        over = text_style_generator(text, CHAR_OVER)
        answers.append(InlineQueryResultArticle(
            title=over,
            description="Overline Text",
            input_message_content=InputTextMessageContent(over)))
        under = text_style_generator(text, CHAR_UNDER)
        answers.append(InlineQueryResultArticle(
            title=under,
            description="Underline Text",
            input_message_content=InputTextMessageContent(under)))
        strike = text_style_generator(text, CHAR_STRIKE)
        answers.append(InlineQueryResultArticle(
            title=strike,
            description="Strike Text",
            input_message_content=InputTextMessageContent(strike)))
        points = text_style_generator(text, CHAR_POINTS)
        answers.append(InlineQueryResultArticle(
            title=points,
            description="Points Text",
            input_message_content=InputTextMessageContent(points)))
        smallcaps_conv = formatting_text_inline(text, smallcaps)
        answers.append(InlineQueryResultArticle(
            title=smallcaps_conv,
            description="Smallcaps Text",
            input_message_content=InputTextMessageContent(smallcaps_conv)))
        super_script = formatting_text_inline(text, superscript)
        answers.append(InlineQueryResultArticle(
            title=super_script,
            description="Superscript Text",
            input_message_content=InputTextMessageContent(super_script)))
        sub_script = formatting_text_inline(text, subscript)
        answers.append(InlineQueryResultArticle(
            title=sub_script,
            description="Subscript Text",
            input_message_content=InputTextMessageContent(sub_script)))
        wide_text = formatting_text_inline(text, wide)
        answers.append(InlineQueryResultArticle(
            title=wide_text,
            description="Wide Text",
            input_message_content=InputTextMessageContent(wide_text)))
        bubbles_text = formatting_text_inline(text, bubbles)
        answers.append(InlineQueryResultArticle(
            title=bubbles_text,
            description="Bubbles Text",
            input_message_content=InputTextMessageContent(bubbles_text)))
        bubblesblack_text = formatting_text_inline(text, bubblesblack)
        answers.append(InlineQueryResultArticle(
            title=bubblesblack_text,
            description="Bubbles Black Text",
            input_message_content=InputTextMessageContent(bubblesblack_text)))
        smoth_text = formatting_text_inline(text, smothtext)
        answers.append(InlineQueryResultArticle(
            title=smoth_text,
            description="Smoth Text",
            input_message_content=InputTextMessageContent(smoth_text)))

        graffiti_text = formatting_text_inline(text, graffiti)
        answers.append(InlineQueryResultArticle(
            title=graffiti_text,
            description="Graffiti Text",
            input_message_content=InputTextMessageContent(graffiti_text)))
        graffitib_text = formatting_text_inline(text, graffitib)
        answers.append(InlineQueryResultArticle(
            title=graffitib_text,
            description="Graffiti Bold Text",
            input_message_content=InputTextMessageContent(graffitib_text)))
        handwriting_text = formatting_text_inline(text, handwriting)
        answers.append(InlineQueryResultArticle(
            title=handwriting_text,
            description="Handwriting Text",
            input_message_content=InputTextMessageContent(handwriting_text)))
        handwritingb_text = formatting_text_inline(text, handwritingb)
        answers.append(InlineQueryResultArticle(
            title=handwritingb_text,
            description="Handwriting Bold Text",
            input_message_content=InputTextMessageContent(handwritingb_text)))
        await client.answer_inline_query(query.id,
                                         results=answers,
                                         switch_pm_text="Converted to stylish text",
                                         switch_pm_parameter="help_inline"
                                         )

    # PM_PERMIT
    elif string.split()[0] == "engine_pm":
        button = [[InlineKeyboardButton("Ask for Money", callback_data="engine_pm_block"),
                   InlineKeyboardButton("Contact me", callback_data="engine_pm_nope")],
                  [InlineKeyboardButton("Report", callback_data="engine_pm_report"),
                   InlineKeyboardButton("Passing by", callback_data="engine_pm_none")]]
        random.shuffle(button)
        answers.append(InlineQueryResultArticle(
            id=uuid4(),
            title="Engine pm",
            description="Filter pm",
            input_message_content=InputTextMessageContent(welc_txt, parse_mode="markdown"),
            reply_markup=InlineKeyboardMarkup(button)))
        await client.answer_inline_query(query.id,
                                         results=answers,
                                         cache_time=0
                                         )

    elif string.split()[0] == "speedtest":
        buttons = [[InlineKeyboardButton("Image",
                                        callback_data="speedtest_image"),
                    InlineKeyboardButton("Text",
                                        callback_data="speedtest_text")]]
        answers.append(InlineQueryResultArticle(
            id=uuid4(),
            title="Speed Test",
            description="test your speed",
            input_message_content=InputTextMessageContent("Select SpeedTest Mode", parse_mode="markdown"),
            reply_markup=InlineKeyboardMarkup(buttons)))
        await client.answer_inline_query(query.id,
                                         results=answers,
                                         cache_time=0
                                         )
    elif string.split()[0] == "alive":
        repo = git.Repo(os.getcwd())
        master = repo.head.reference
        commit_id = master.commit.hexsha
        commit_link = f"[{commit_id[:7]}](https://github.com/pokurt/Nana-Remix/commit/{commit_id})"
        try:
            me = await app.get_me()
        except ConnectionError:
            me = None
        text = f"**[Nana-Remix](https://github.com/pokurt/Nana-Remix) Running on {commit_link}:**\n"
        if not me:
            text += f" - **Bot**: `stopped (v{USERBOT_VERSION})`\n"
        else:
            text += f" - **Bot**: `alive (v{USERBOT_VERSION})`\n"
        text += f" - **Pyrogram**: `{__version__}`\n"
        text += f" - **Python**: `{python_version()}`\n"
        text += f" - **Database**: `{DB_AVAILABLE}`\n"
        buttons = [[InlineKeyboardButton("stats", callback_data="alive_message")]]
        answers.append(InlineQueryResultArticle(
            id=uuid4(),
            title="Alive",
            description="Nana Userbot",
            input_message_content=InputTextMessageContent(text, parse_mode="markdown", disable_web_page_preview=True),
            reply_markup=InlineKeyboardMarkup(buttons)))
        await client.answer_inline_query(query.id,
                                         results=answers,
                                         cache_time=0
                                         )

        return