Ejemplo n.º 1
0
async def pmpermit_func(answers):
    button = InlineKeyboard(row_width=2)
    button.add(
        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',
        ),
    )
    answers.append(
        InlineQueryResultArticle(
            title='Engine pm',
            description='Filter pm',
            input_message_content=InputTextMessageContent(
                welc_txt, parse_mode='markdown',
            ),
            reply_markup=button,
        ),
    )
Ejemplo n.º 2
0
async def pmpermit_func(answers, user_id, victim):
    if user_id != USERBOT_ID:
        return
    caption = f"Hi, I'm {USERBOT_NAME}, What are you here for?, You'll be blocked if you send more than 5 messages."
    buttons = InlineKeyboard(row_width=2)
    buttons.add(
        InlineKeyboardButton(text="To Scam You",
                             callback_data="pmpermit to_scam_you a"),
        InlineKeyboardButton(
            text="For promotion",
            callback_data="pmpermit to_scam_you a",
        ),
        InlineKeyboardButton(text="Approve me",
                             callback_data="pmpermit approve_me a"),
        InlineKeyboardButton(text="Approve",
                             callback_data=f"pmpermit approve {victim}"),
        InlineKeyboardButton(
            text="Block & Delete",
            callback_data=f"pmpermit block {victim}",
        ),
    )
    answers.append(
        InlineQueryResultArticle(
            title="do_not_click_here",
            reply_markup=buttons,
            input_message_content=InputTextMessageContent(caption),
        ))
    return answers
Ejemplo n.º 3
0
async def yt_music_func(answers, url):
    if "http" not in url:
        url = (await arq.youtube(url)).result[0]
        url = f"https://youtube.com{url.url_suffix}"
    loop = asyncio.get_running_loop()
    music = await loop.run_in_executor(None, download_youtube_audio, url)
    if not music:
        msg = "**ERROR**\n__MUSIC TOO LONG__"
        answers.append(
            InlineQueryResultArticle(
                title="ERROR",
                description="MUSIC TOO LONG",
                input_message_content=InputTextMessageContent(msg),
            ))
        return answers
    (
        title,
        performer,
        duration,
        audio,
        thumbnail,
    ) = music
    m = await app.send_audio(
        MESSAGE_DUMP_CHAT,
        audio,
        title=title,
        duration=duration,
        performer=performer,
        thumb=thumbnail,
    )
    os.remove(audio)
    os.remove(thumbnail)
    answers.append(
        InlineQueryResultCachedDocument(title=title, file_id=m.audio.file_id))
    return answers
Ejemplo n.º 4
0
async def inline_query_handler(c: Client, iq: InlineQuery):
    q = iq.query
    q_res_data = await MegaFiles().get_file_by_name(q)
    me = await c.get_me()
    res = []
    if q_res_data is not None:
        for file in q_res_data:
            res.append(
                InlineQueryResultArticle(
                    title=file['file_name'],
                    description=f"{file['file_name']} - {file['file_type']}",
                    thumb_url=
                    "https://cdn3.iconfinder.com/data/icons/education-vol-1-34/512/15_File_files_office-256"
                    ".png",
                    input_message_content=InputTextMessageContent(
                        message_text=
                        f"{file['file_name']} - {file['file_type']}"),
                    reply_markup=InlineKeyboardMarkup([[
                        InlineKeyboardButton(
                            text=
                            f"{emoji.OPEN_MAILBOX_WITH_LOWERED_FLAG} Get this File",
                            url=
                            f"http://t.me/{me.username}?start=plf-{file['file_id']}"
                        )
                    ]])))

    if len(res) > 0:
        await iq.answer(results=res, cache_time=0, is_personal=False)
Ejemplo n.º 5
0
async def alive_func(answers):
    buttons = InlineKeyboard(row_width=1)
    try:
        me = await app.get_me()
    except ConnectionError:
        me = None
    skynoid_stats = 'stopped' if not me else 'alive'
    buttons.add(InlineKeyboardButton(
        '🏓',
        callback_data='alive_message',
    ), )
    answers.append(
        InlineQueryResultArticle(
            title='Alive',
            description='Skynoid Userbot',
            input_message_content=InputTextMessageContent(
                tld('alive_str').format(
                    skynoid_stats,
                    USERBOT_VERSION,
                    __version__,
                    python_version(),
                    DB_AVAILABLE,
                ),
                parse_mode='markdown',
                disable_web_page_preview=True,
            ),
            reply_markup=buttons,
        ), )
Ejemplo n.º 6
0
 async def pmpermit_inline_query_handler(_, query: InlineQuery):
     results = []
     owner = await userge.get_me()
     pm_inline_msg = await SAVED_SETTINGS.find_one({'_id': 'CUSTOM_INLINE_PM_MESSAGE'})
     if pm_inline_msg:
         text = pm_inline_msg.get('data')
     else:
         text = f"Hello, welcome to **{owner.first_name}** Dm.\n\nWhat you want to do ?"
     buttons = [[
         InlineKeyboardButton(
             "Contact Me", callback_data="pm_contact"),
         InlineKeyboardButton(
             "Spam here", callback_data="pm_spam")]]
     results.append(
         InlineQueryResultArticle(
             id=uuid4(),
             title="Pm Permit",
             input_message_content=InputTextMessageContent(text),
             description="Inline Pm Permit Handler",
             thumb_url="https://imgur.com/download/Inyeb1S",
             reply_markup=InlineKeyboardMarkup(buttons)
         )
     )
     await query.answer(
         results=results,
         cache_time=60
     )
     query.stop_propagation()
Ejemplo n.º 7
0
async def alive_function(answers):
    buttons = InlineKeyboard(row_width=2)
    bot_state = "Dead" if not await app.get_me() else "Alive"
    # ubot_state = 'Dead' if not await app2.get_me() else 'Alive'
    buttons.add(
        InlineKeyboardButton("Main Bot", url="https://t.me/Cutiepii_Robot"),
        InlineKeyboardButton("Go Inline!", switch_inline_query_current_chat=""),
    )

    msg = f"""
**[Cutiepii 💜](https://github.com/Awesome-RJ/CutiepiiRobot):**
**MainBot:** `{bot_state}`
**UserBot:** `Alive`
**Python:** `3.9`
**Pyrogram:** `{pyrover}`
**MongoDB:** `{mongover}`
**Platform:** `{sys.platform}`
**Profiles:** [BOT](t.me/{BOT_USERNAME}) | [UBOT](t.me/Awesome_Cutiepii)
"""
    answers.append(
        InlineQueryResultArticle(
            title="Alive",
            description="Check Bot's Stats",
            thumb_url="https://telegra.ph/file/0d42f41c08e511b557ecc.png",
            input_message_content=InputTextMessageContent(
                msg, disable_web_page_preview=True
            ),
            reply_markup=buttons,
        )
    )
    return answers
Ejemplo n.º 8
0
async def query(client, message):
    mt = parser.MeuTimao()
    news = mt.all_news()[:50]

    r = [
        InlineQueryResultArticle(
            title=new.title,
            description=new.summary,
            thumb_url=new.img_url,
            input_message_content=InputTextMessageContent(
                disable_web_page_preview=True,
                message_text=
                f"<b>{new.title}</b>\n\n{new.summary} <a href={new.url}>ler completo</a>"
            ),
            reply_markup=InlineKeyboardMarkup(
                [[InlineKeyboardButton("➕ noticias",
                                       switch_inline_query='')]]))
        for new in news if 'https://cdn.' in new.img_url
    ]

    await message.answer(
        r,
        cache_time=1,
        is_gallery=False,
    )
Ejemplo n.º 9
0
async def google_search_func(answers, text):
    gresults = await GoogleSearch().async_search(text)
    limit = 0
    for i in gresults:
        if limit > 48:
            break
        limit += 1

        try:
            msg = f"""
[{i['titles']}]({i['links']})
{i['descriptions']}"""

            answers.append(
                InlineQueryResultArticle(
                    title=i["titles"],
                    description=i["descriptions"],
                    input_message_content=InputTextMessageContent(
                        msg, disable_web_page_preview=True
                    ),
                )
            )
        except KeyError:
            pass
    return answers
Ejemplo n.º 10
0
async def yt_music_func(answers, url, user_id):
    if user_id not in SUDOERS:
        msg = "**ERROR**\n__THIS FEATURE IS ONLY FOR SUDO USERS__"
        answers.append(
            InlineQueryResultArticle(
                title="ERROR",
                description="THIS FEATURE IS ONLY FOR SUDO USERS",
                input_message_content=InputTextMessageContent(msg)
            ))
        return answers
    if "http" not in url:
        url = (await arq.youtube(url))[0]
        url = f"https://youtube.com{url.url_suffix}"
    title, performer, duration, audio, thumbnail = await download_youtube_audio(url)
    m = await app.send_audio(
        MESSAGE_DUMP_CHAT,
        audio,
        title=title,
        duration=duration,
        performer=performer,
        thumb=thumbnail
    )
    os.remove(audio)
    os.remove(thumbnail)
    answers.append(
        InlineQueryResultCachedDocument(
            title=title,
            file_id=m.audio.file_id
        )
    )
    return answers
Ejemplo n.º 11
0
async def shortify(url):
    if "." not in url:
        return
    header = {
        "Authorization": "Bearer ad39983fa42d0b19e4534f33671629a4940298dc",
        "Content-Type": "application/json",
    }
    payload = {"long_url": f"{url}"}
    payload = json.dumps(payload)
    async with aiohttpsession.post(
            "https://api-ssl.bitly.com/v4/shorten",
            headers=header,
            data=payload,
    ) as resp:
        data = await resp.json()
    msg = data["link"]
    a = []
    b = InlineQueryResultArticle(
        title="Link Shortened!",
        description=data["link"],
        input_message_content=InputTextMessageContent(
            msg, disable_web_page_preview=True),
    )
    a.append(b)
    return a
Ejemplo n.º 12
0
async def alive_function(answers):
    buttons = InlineKeyboard(row_width=2)
    bot_state = "Dead" if not await app.get_me() else "Alive"
    # ubot_state = 'Dead' if not await app2.get_me() else 'Alive'
    buttons.add(
        InlineKeyboardButton("Main Bot", url="https://t.me/DaisyXbot"),
        InlineKeyboardButton("Go Inline!",
                             switch_inline_query_current_chat=""),
    )

    msg = f"""
**[Yuno Gasai✨](https://futurediary.fandom.com/wiki/Yuno_Gasai):**
**MainBot:** `{bot_state}`
**UserBot:** `Alive`
**Python:** `3.9`
**Pyrogram:** `{pyrover}`
**MongoDB:** `{mongover}`
**Platform:** `{sys.platform}`
**Profiles:** [BOT](t.me/{BOT_USERNAME}) | [UBOT](https://t.me/Achubiju6c)
"""
    answers.append(
        InlineQueryResultArticle(
            title="Alive",
            description="Check Bot's Stats",
            thumb_url="https://telegra.ph/file/debc179305d2e1f140636.jpg",
            input_message_content=InputTextMessageContent(
                msg, disable_web_page_preview=True),
            reply_markup=buttons,
        ))
    return answers
Ejemplo n.º 13
0
async def search(client: Client, query: InlineQuery):
    answers = []
    search_query = query.query.lower().strip().rstrip()

    if search_query == "":
        await client.answer_inline_query(query.id,
                                         results=answers,
                                         switch_pm_text="SEARCH YT LINK",
                                         switch_pm_parameter="help",
                                         cache_time=0)
    else:
        videosSearch = VideosSearch(search_query, limit=50)

        for v in videosSearch.result()["result"]:
            answers.append(
                InlineQueryResultArticle(
                    title=v["title"],
                    description="{}, {} views.".format(
                        v["duration"], v["viewCount"]["short"]),
                    input_message_content=InputTextMessageContent(
                        "/play https://www.youtube.com/watch?v={}".format(
                            v["id"])),
                    thumb_url=v["thumbnails"][0]["url"]))

        try:
            await query.answer(results=answers, cache_time=0)
        except errors.QueryIdInvalid:
            await query.answer(
                results=answers,
                cache_time=0,
                switch_pm_text="ERROR TIME OUT",
                switch_pm_parameter="",
            )
Ejemplo n.º 14
0
def main(app, inline_query):
    if len(inline_query.query) < 3:
        inline_query.answer(results=[],
                            switch_pm_text="Help",
                            switch_pm_parameter="start",
                            cache_time=5)
        return
    matches = [
        pkmn for pkmn in pokemon_list
        if inline_query.query.lower() in pkmn.lower()
    ]
    results = []
    for pkmn in matches:
        pkmn_data = pk.get_pokemon(pkmn)
        species = pk.get_pokemon_species(pkmn)
        name = species.names[7].name
        thumb_url = pkmn_data.sprites.front_default.replace(
            "pokemon", "pokemon/other/official-artwork")
        markup = data_markup(name, expanded=0)
        typing = " / ".join([ty.type.name.title() for ty in pkmn_data.types])
        genus = species.genera[7].genus
        results.append(
            InlineQueryResultArticle(
                title=name,
                description=f"{genus}\nType: {typing}",
                input_message_content=InputTextMessageContent(f"🔄 Loading..."),
                thumb_url=thumb_url,
                reply_markup=markup))
    user_dict[inline_query.from_user.id] = {
        results[i].id: results[i].title
        for i in range(len(results))
    }
    inline_query.answer(results=results, cache_time=3)
Ejemplo n.º 15
0
async def youtube_func(answers, text):
    results = await arq.youtube(text)
    limit = 0
    for i in results:
        if limit > 48:
            break
        limit += 1
        buttons = InlineKeyboard(row_width=1)
        video_url = f"https://youtube.com{results[i].url_suffix}"
        buttons.add(InlineKeyboardButton('Watch', url=video_url))
        caption = f"""
**Title:** {results[i].title}
**Views:** {results[i].views}
**Channel:** {results[i].channel}
**Duration:** {results[i].duration}
**Uploaded:** {results[i].publish_time}
**Description:** {results[i].long_desc}"""
        description = f"{results[i].views} | {results[i].channel} | " \
            + f"{results[i].duration} | {results[i].publish_time}"
        try:
            answers.append(
                InlineQueryResultArticle(
                    title=results[i].title,
                    thumb_url=results[i].thumbnails[0],
                    description=description,
                    input_message_content=InputTextMessageContent(
                        caption, disable_web_page_preview=True),
                    reply_markup=buttons))
        except (KeyError, ValueError):
            pass
    return answers
Ejemplo n.º 16
0
async def wall_func(answers, text):
    results = await arq.wall(text)
    if not results.ok:
        answers.append(
            InlineQueryResultArticle(
                title="Error",
                description=results.result,
                input_message_content=InputTextMessageContent(results.result),
            )
        )
        return answers
    limit = 0
    results = results.result
    for i in results:
        if limit > 48:
            break
        limit += 1
        answers.append(
            InlineQueryResultPhoto(
                photo_url=i.url_image,
                thumb_url=i.url_thumb,
                caption=f"[Source]({i.url_image})",
            )
        )
    return answers
Ejemplo n.º 17
0
async def github_repo_func(answers, text):
    URL = f"https://api.github.com/repos/{text}"
    URL2 = f"https://api.github.com/repos/{text}/contributors"
    results = await asyncio.gather(fetch(URL), fetch(URL2))
    r = results[0]
    r1 = results[1]
    commits = 0
    for developer in r1:
        commits += developer['contributions']
    buttons = InlineKeyboard(row_width=1)
    buttons.add(
        InlineKeyboardButton('Open On Github',
                             url=f"https://github.com/{text}"))
    caption = f"""
**Info Of {r['full_name']}**
**Stars:** `{r['stargazers_count']}`
**Watchers:** `{r['watchers_count']}`
**Forks:** `{r['forks_count']}`
**Commits:** `{commits}`
**Is Fork:** `{r['fork']}`
**Language:** `{r['language']}`
**Contributors:** `{len(r1)}`
**License:** `{r['license']['name']}`
**Repo Owner:** [{r['owner']['login']}]({r['owner']['html_url']})
**Created On:** `{r['created_at']}`
**Homepage:** {r['homepage']}
**Description:** __{r['description']}__"""
    answers.append(
        InlineQueryResultArticle(title="Found Repo",
                                 description=text,
                                 reply_markup=buttons,
                                 input_message_content=InputTextMessageContent(
                                     caption, disable_web_page_preview=True)))
    return answers
Ejemplo n.º 18
0
async def image_func(answers, query):
    results = await arq.image(query)
    if not results.ok:
        answers.append(
            InlineQueryResultArticle(
                title="Error",
                description=results.result,
                input_message_content=InputTextMessageContent(results.result),
            ))
        return answers
    results = results.result[:49]
    buttons = InlineKeyboard(row_width=2)
    buttons.add(
        InlineKeyboardButton(
            text="Search again",
            switch_inline_query_current_chat="image",
        ), )
    for i in results:
        answers.append(
            InlineQueryResultPhoto(
                title=i.title,
                photo_url=i.url,
                thumb_url=i.url,
                reply_markup=buttons,
            ))
    return answers
Ejemplo n.º 19
0
def search(client, query):
    answers = []
    string = query.query.lower().strip().rstrip()

    if string == "":
        client.answer_inline_query(query.id,
                                   results=answers,
                                   switch_pm_text=_("inline_1"),
                                   switch_pm_parameter="help",
                                   cache_time=0)
        return
    else:
        videosSearch = VideosSearch(string.lower(), limit=50)
        for v in videosSearch.result()["result"]:
            answers.append(
                InlineQueryResultArticle(
                    title=v["title"],
                    description=_("inline_2").format(v["duration"],
                                                     v["viewCount"]["short"]),
                    input_message_content=InputTextMessageContent(
                        "https://www.youtube.com/watch?v={}".format(v["id"])),
                    thumb_url=v["thumbnails"][0]["url"]))
        try:
            query.answer(results=answers, cache_time=0)
        except errors.QueryIdInvalid:
            query.answer(
                results=answers,
                cache_time=0,
                switch_pm_text=_("inline_3"),
                switch_pm_parameter="",
            )
Ejemplo n.º 20
0
async def torrent_func(answers, text):
    results = await arq.torrent(text)
    limit = 0
    for i in results:
        if limit > 48:
            break
        title = results[i].name
        size = results[i].size
        seeds = results[i].seeds
        leechs = results[i].leechs
        upload_date = results[i].uploaded + " Ago"
        magnet = results[i].magnet
        caption = f"""
**Title:** __{title}__
**Size:** __{size}__
**Seeds:** __{seeds}__
**Leechs:** __{leechs}__
**Uploaded:** __{upload_date}__
**Magnet:** __{magnet}__"""

        description = f"{size} | {upload_date} | Seeds: {seeds}"
        try:
            answers.append(
                InlineQueryResultArticle(
                    title=title,
                    description=description,
                    input_message_content=InputTextMessageContent(
                        caption, disable_web_page_preview=True),
                ))
            limit += 1
        except (KeyError, ValueError):
            pass
    return answers
Ejemplo n.º 21
0
async def deezer_func(answers, text):
    buttons_list = []
    results = await arq.deezer(text, 5)
    for i in results:
        buttons = InlineKeyboard(row_width=1)
        buttons.add(InlineKeyboardButton("Download | Play",
                                         url=results[i].url))
        buttons_list.append(buttons)
        duration = await time_convert(results[i].duration)
        caption = f"""
**Title:** {results[i].title}
**Artist:** {results[i].artist}
**Duration:** {duration}
**Source:** [Deezer]({results[i].source})"""
        description = f"{results[i].artist} | {duration}"
        try:
            answers.append(
                InlineQueryResultArticle(
                    title=results[i].title,
                    thumb_url=results[i].thumbnail,
                    description=description,
                    input_message_content=InputTextMessageContent(
                        caption, disable_web_page_preview=True),
                    reply_markup=buttons_list[i],
                ))
        except (KeyError, ValueError):
            pass
    return answers
Ejemplo n.º 22
0
async def saavn_func(answers, text):
    buttons_list = []
    results = await arq.saavn(text)
    for i in results:
        buttons = InlineKeyboard(row_width=1)
        buttons.add(
            InlineKeyboardButton("Download | Play", url=results[i].media_url))
        buttons_list.append(buttons)
        duration = await time_convert(results[i].duration)
        caption = f"""
**Title:** {results[i].song}
**Album:** {results[i].album}
**Duration:** {duration}
**Release:** {results[i].year}
**Singers:** {results[i].singers}"""
        description = (f"{results[i].album} | {duration} " +
                       f"| {results[i].singers} ({results[i].year})")
        try:
            answers.append(
                InlineQueryResultArticle(
                    title=results[i].song,
                    input_message_content=InputTextMessageContent(
                        caption, disable_web_page_preview=True),
                    description=description,
                    thumb_url=results[i].image,
                    reply_markup=buttons_list[i],
                ))
        except (KeyError, ValueError):
            pass
    return answers
Ejemplo n.º 23
0
async def inline(client: Client, query: InlineQuery):
    answers = []
    search_query = query.query.lower().strip().rstrip()

    if search_query == "":
        await client.answer_inline_query(
            query.id,
            results=answers,
            switch_pm_text="Type a YouTube video name. Music ++",
            switch_pm_parameter="help",
            cache_time=0)
    else:
        search = VideosSearch(search_query, limit=50)

        for result in search.result()["result"]:
            answers.append(
                InlineQueryResultArticle(
                    title=result["title"],
                    description="{}, {} views.".format(
                        result["duration"], result["viewCount"]["short"]),
                    input_message_content=InputTextMessageContent(
                        "https://www.youtube.com/watch?v={}".format(
                            result["id"])),
                    thumb_url=result["thumbnails"][0]["url"]))

        try:
            await query.answer(results=answers, cache_time=0)
        except errors.QueryIdInvalid:
            await query.answer(
                results=answers,
                cache_time=0,
                switch_pm_text="Error: Search timed out",
                switch_pm_parameter="",
            )
Ejemplo n.º 24
0
async def alive_function(answers):
    buttons = InlineKeyboard(row_width=2)
    bot_state = "Dead" if not await app.get_me() else "Alive"
    # ubot_state = 'Dead' if not await app2.get_me() else 'Alive'
    buttons.add(
        InlineKeyboardButton("Stats", callback_data="stats_callback"),
        InlineKeyboardButton("Go Inline!",
                             switch_inline_query_current_chat=""),
    )

    msg = f"""
**[DaisyX✨](https://github.com/TeamDaisyX):**
**MainBot:** `{bot_state}`
**UserBot:** `Alive`
**Python:** `3.9`
**Pyrogram:** `{pyrover}`
**MongoDB:** `{mongover}`
**Platform:** `{sys.platform}`
**Profiles:** [BOT](t.me/{BOT_USERNAME}) | [UBOT](t.me/daisyxhelper)
"""
    answers.append(
        InlineQueryResultArticle(
            title="Alive",
            description="Check Bot's Stats",
            thumb_url=
            "https://static2.aniimg.com/upload/20170515/414/c/d/7/cd7EEF.jpg",
            input_message_content=InputTextMessageContent(
                msg, disable_web_page_preview=True),
            reply_markup=buttons,
        ))
    return answers
Ejemplo n.º 25
0
async def _andshow(client, query):
    res = InlineQueryResultArticle(title="❌ Un-Authorised User",
        description="© New-dev0",
        url=REPO,
        input_message_content=InputTextMessageContent("You are not Authorized To Use Me!"), 
        reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton(text="Deploy Your own",url=REPO)]]))
    await query.answer([res], switch_pm_text="🤖 TgTwitterBot!",
                       switch_pm_parameter="start")
    def get_item(
        cls,
        db_playlist: graph_models.vertices.Playlist,
        db_from_user: graph_models.vertices.User,
        inline_query: pyrogram.types.InlineQuery,
    ) -> Optional['pyrogram.types.InlineQueryResult']:
        if db_playlist is None or db_from_user is None:
            return None
        from ..inline_buttons import InlineButton

        data = PlaylistData(
            title=db_playlist.title,
            description=db_playlist.description,
            lang_code=db_from_user.chosen_language_code,
        )
        markup = [
            [
                InlineButton.get_button('home').get_inline_keyboard_button(
                    db_from_user.chosen_language_code),
                InlineButton.get_button(
                    'back_to_playlists').get_inline_keyboard_button(
                        db_from_user.chosen_language_code),
            ],
            [
                InlineButton.get_button(
                    'get_playlist_audios').get_inline_keyboard_button(
                        db_from_user.chosen_language_code,
                        db_playlist.key,
                    ),
                # todo: add a button to get the top 10 audios from this playlist as a message
            ],
            [
                InlineButton.get_button(
                    'edit_playlist').get_inline_keyboard_button(
                        db_from_user.chosen_language_code,
                        db_playlist.key,
                    ),
                InlineButton.get_button(
                    'delete_playlist').get_inline_keyboard_button(
                        db_from_user.chosen_language_code,
                        db_playlist.key,
                    ),
            ],
        ]

        markup = InlineKeyboardMarkup(markup)
        item = InlineQueryResultArticle(
            title=db_playlist.title,
            description=f"{db_playlist.description}",
            id=f'{inline_query.id}->{db_playlist.key}',
            thumb_url="https://telegra.ph/file/ac2d210b9b0e5741470a1.jpg",
            input_message_content=InputTextMessageContent(
                message_text=BaseTemplate.registry.playlist_template.render(
                    data), ),
            reply_markup=markup,
        )

        return item
Ejemplo n.º 27
0
async def tg_search_func(answers, text, user_id):
    if user_id not in SUDOERS:
        msg = "**ERROR**\n__THIS FEATURE IS ONLY FOR SUDO USERS__"
        answers.append(
            InlineQueryResultArticle(
                title="ERROR",
                description="THIS FEATURE IS ONLY FOR SUDO USERS",
                input_message_content=InputTextMessageContent(msg)))
        return answers
    if str(text)[-1] != ":":
        msg = "**ERROR**\n__Put A ':' After The Text To Search__"
        answers.append(
            InlineQueryResultArticle(
                title="ERROR",
                description="Put A ':' After The Text To Search",
                input_message_content=InputTextMessageContent(msg)))

        return answers
    text = text[0:-1]
    async for message in app2.search_global(text, limit=49):
        buttons = InlineKeyboard(row_width=2)
        buttons.add(
            InlineKeyboardButton(
                text="Origin",
                url=message.link if message.link else "https://t.me/telegram"),
            InlineKeyboardButton(text="Search again",
                                 switch_inline_query_current_chat="search"))
        name = message.from_user.first_name if message.from_user.first_name else "NO NAME"
        caption = f"""
**Query:** {text}
**Name:** {str(name)} [`{message.from_user.id}`]
**Chat:** {str(message.chat.title)} [`{message.chat.id}`]
**Date:** {ctime(message.date)}
**Text:** >>

{message.text.markdown if message.text else message.caption if message.caption else '[NO_TEXT]'}
"""
        result = InlineQueryResultArticle(
            title=name,
            description=message.text if message.text else "[NO_TEXT]",
            reply_markup=buttons,
            input_message_content=InputTextMessageContent(
                caption, disable_web_page_preview=True))
        answers.append(result)
    return answers
Ejemplo n.º 28
0
async def wikipedia(client, inline_query):
    if inline_query.from_user.id not in app_user_ids:
        await inline_query.answer([
            InlineQueryResultArticle('...no', InputTextMessageContent('...no'))
        ],
                                  cache_time=3600,
                                  is_personal=True)
        return
    query = inline_query.matches[0].group(1).strip().lower()
    async with results_lock:
        if query not in all_results:
            async with session.get(
                    f'https://en.wikipedia.org/w/api.php?action=query&format=json&list=search&formatversion=2&srlimit=10&srprop=snippet&srenablerewrites=1&srsearch={urlencode(query)}'
            ) as resp:
                all_results[query] = (await resp.json())['query']['search']
    results = all_results[query]
    answers = []
    parser = pyrogram_html(client)
    for a, result in enumerate(results):
        full_snippet = None
        text = f'<a href="https://en.wikipedia.org/wiki/{urlencode(result["title"])}">{result["title"]}</a>\n\n'
        if result['snippet']:
            full_snippet = snippet = (await parser.parse(result['snippet']
                                                         ))['message']
            total_length = len((await parser.parse(text))['message'])
            if len(snippet) > 1022 - total_length:
                snippet = snippet[:1021 - total_length] + '…'
            text += snippet
        buttons = [
            InlineKeyboardButton('Back', 'wikipedia_back'),
            InlineKeyboardButton(f'{a + 1}/{len(results)}', 'wikipedia_nop'),
            InlineKeyboardButton('Next', 'wikipedia_next')
        ]
        if not a:
            buttons.pop(0)
        if len(results) == a + 1:
            buttons.pop()
        answers.append(
            InlineQueryResultArticle(
                result['title'],
                InputTextMessageContent(text, disable_web_page_preview=True),
                reply_markup=InlineKeyboardMarkup([buttons]),
                id=f'wikipedia{a}-{time.time()}',
                description=full_snippet))
    await inline_query.answer(answers, is_personal=True)
Ejemplo n.º 29
0
async def chat_info_inline_func(answers, chat):
    caption, photo_id = await get_chat_info(chat)
    answers.append(
        InlineQueryResultArticle(
            title="Found Chat.",
            input_message_content=InputTextMessageContent(
                caption, disable_web_page_preview=True),
        ))
    return answers
Ejemplo n.º 30
0
def handle_inline_query(bot: app, query: InlineQuery):
    if not query.query:
        return
    results = [
        InlineQueryResultArticle(f'Like version of {query.query}',
                                 InputTextMessageContent(query.query),
                                 reply_markup=IKM([('❤ (0)️', 'like')]))
    ]
    bot.answer_inline_query(query.id, results)