Example #1
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()
Example #2
0
def search(client: Client, query: InlineQuery):
    answers = []
    string = query.query.lower().strip().rstrip()

    if string == "":
        client.answer_inline_query(query.id,
                                   results=answers,
                                   switch_pm_text=_("inline_1"),
                                   switch_pm_parameter="help",
                                   cache_time=0)
        return
    else:
        videosSearch = VideosSearch(string.lower(), limit=50)
        for v in videosSearch.result()["result"]:
            answers.append(
                InlineQueryResultArticle(
                    title=v["title"],
                    description=_("inline_2").format(v["duration"],
                                                     v["viewCount"]["short"]),
                    input_message_content=InputTextMessageContent(
                        "https://www.youtube.com/watch?v={}".format(v["id"])),
                    thumb_url=v["thumbnails"][0]["url"]))
        try:
            query.answer(results=answers, cache_time=0)
        except errors.QueryIdInvalid:
            query.answer(
                results=answers,
                cache_time=0,
                switch_pm_text=_("inline_3"),
                switch_pm_parameter="",
            )
Example #3
0
 async def inline_fn(_, inline_query: InlineQuery):
     query = inline_query.query.split("ud ")[1].strip()
     try:
         riqa = await wpraip(query)
         switch_pm_text = f"Found {len(riqa)} results for {query}"
     except JSONDecodeError:
         riqa = []
     if not riqa:
         switch_pm_text = f"Sorry, couldn't find any results for: {query}"
     await inline_query.answer(results=riqa[:49],
                               cache_time=300,
                               is_gallery=False,
                               is_personal=False,
                               next_offset="",
                               switch_pm_text=switch_pm_text,
                               switch_pm_parameter="ud")
     inline_query.stop_propagation()
Example #4
0
async def stop_user_from_doing_anything_inline(_, iq: InlineQuery):
    allowed_users = Common().allowed_users
    if allowed_users and iq.from_user:
        if iq.from_user.id not in allowed_users:
            iq.stop_propagation()
        else:
            iq.continue_propagation()
    else:
        if iq.from_user:
            iq.continue_propagation()
        else:
            iq.stop_propagation()
Example #5
0
 async def inline_fn(_, inline_query: InlineQuery):
     movie_name = inline_query.query.split("imdb ")[1].strip()
     search_results = await _get(
         imdb.API_ONE_URL.format(theuserge=movie_name))
     srch_results = json.loads(search_results.text)
     asroe = srch_results.get("d")
     oorse = []
     for sraeo in asroe:
         title = sraeo.get("l", "")
         description = sraeo.get("q", "")
         stars = sraeo.get("s", "")
         imdb_url = f"https://imdb.com/title/{sraeo.get('id')}"
         year = sraeo.get("yr", "").rstrip('-')
         image_url = sraeo.get("i").get("imageUrl")
         message_text = f"<a href='{image_url}'>🎬</a>"
         message_text += f"<a href='{imdb_url}'>{title} {year}</a>"
         oorse.append(
             InlineQueryResultArticle(
                 title=f" {title} {year}",
                 input_message_content=InputTextMessageContent(
                     message_text=message_text,
                     parse_mode="html",
                     disable_web_page_preview=False),
                 url=imdb_url,
                 description=f" {description} | {stars}",
                 thumb_url=image_url,
                 reply_markup=InlineKeyboardMarkup([[
                     InlineKeyboardButton(
                         text="Get IMDB details",
                         callback_data=f"imdb({sraeo.get('id')})")
                 ]])))
     resfo = srch_results.get("q")
     await inline_query.answer(
         results=oorse,
         cache_time=300,
         is_gallery=False,
         is_personal=False,
         next_offset="",
         switch_pm_text=f"Found {len(oorse)} results for {resfo}",
         switch_pm_parameter="imdb")
     inline_query.stop_propagation()
Example #6
0
def inline_query_handler(_, query: InlineQuery):
    query.answer(results=[
        InlineQueryResultArticle(
            title="Tic-Tac-Toe",
            input_message_content=InputTextMessageContent(
                f"**{query.from_user.first_name}** challenged you in XO!"),
            description="Tap here to challenge your friends in XO!",
            thumb_url=
            "https://upload.wikimedia.org/wikipedia/commons/thumb/3/32/Tic_tac_toe.svg/1200px-Tic_tac_toe"
            ".svg.png",
            reply_markup=InlineKeyboardMarkup([[
                InlineKeyboardButton(
                    emojis.swords + " Accept",
                    json.dumps({
                        "type": "P",
                        "id": query.from_user.id,
                        "name": query.from_user.first_name
                    }))
            ]]))
    ],
                 cache_time=1)
Example #7
0
async def inline_answer(_, inline_query: InlineQuery):
    data = inline_query.query.split('-', maxsplit=1)
    _id = data[0].strip()
    msg = data[1].strip()

    if not (msg and msg.endswith(':')):
        inline_query.stop_propagation()

    try:
        user = await userge.get_users(_id.strip())
    except Exception:  # pylint: disable=broad-except
        inline_query.stop_propagation()
        return

    c_m_e = MEDIA_FID_S.get(msg[:-1])
    if not c_m_e:
        PRVT_MSGS[inline_query.id] = (user.id, user.first_name,
                                      msg.strip(': '))
    else:
        PRVT_MSGS[inline_query.id] = (user.id, user.first_name, c_m_e)

    prvte_msg = [[
        InlineKeyboardButton("Show Message 🔐",
                             callback_data=f"prvtmsg({inline_query.id})")
    ]]

    msg_c = f"🔒 A **private message** to {'@' + user.username}, "
    msg_c += "Only he/she can open it."

    results = [
        InlineQueryResultArticle(
            id=uuid4(),
            title=f"A Private Msg to {user.first_name}",
            input_message_content=InputTextMessageContent(msg_c),
            description="Only he/she can open it",
            thumb_url="https://te.legra.ph/file/16133ab3297b3f73c8da5.png",
            reply_markup=InlineKeyboardMarkup(prvte_msg))
    ]

    await inline_query.answer(results=results, cache_time=3)
Example #8
0
async def set_language_inline_query(bot: Amime, inline_query: InlineQuery):
    user = inline_query.from_user
    if not user:
        return
    lang = inline_query._lang
    code: str = ""
    user_code = user.language_code or "en"
    if "." in user_code:
        user_code = user_code.split(".")[0]
    if user_code not in lang.strings.keys():
        user_code = "en"

    code = (await Users.get_or_create(
        {
            "name": user.first_name,
            "username": user.username or "",
            "language_bot": user_code,
            "language_anime": user_code,
            "is_collaborator": False,
        },
        id=user.id,
    ))[0].language_bot
    inline_query._lang = lang.get_language(code)
Example #9
0
async def anime_inline(bot: Amime, inline_query: InlineQuery):
    query = inline_query.matches[0]["query"].strip()
    lang = inline_query._lang

    if query.startswith("!"):
        inline_query.continue_propagation()

    results: List[InlineQueryResultPhoto] = []

    async with anilist.AsyncClient() as client:
        search_results = await client.search(query, "anime", 15)
        while search_results is None:
            search_results = await client.search(query, "anime", 10)
            await asyncio.sleep(5)

        for result in search_results:
            anime = await client.get(result.id, "anime")

            if anime is None:
                continue

            photo: str = ""
            if hasattr(anime, "banner"):
                photo = anime.banner
            elif hasattr(anime, "cover"):
                if hasattr(anime.cover, "extra_large"):
                    photo = anime.cover.extra_large
                elif hasattr(anime.cover, "large"):
                    photo = anime.cover.large
                elif hasattr(anime.cover, "medium"):
                    photo = anime.cover.medium

            description: str = ""
            if hasattr(anime, "description"):
                description = anime.description
                description = re.sub(re.compile(r"<.*?>"), "", description)
                description = description[0:260] + "..."

            text = f"<b>{anime.title.romaji}</b>"
            if hasattr(anime.title, "native"):
                text += f" (<code>{anime.title.native}</code>)"
            text += f"\n\n<b>ID</b>: <code>{anime.id}</code> (<b>ANIME</b>)"
            if hasattr(anime, "score"):
                if hasattr(anime.score, "average"):
                    text += f"\n<b>{lang.score}</b>: <code>{anime.score.average}</code>"
            text += f"\n<b>{lang.status}</b>: <code>{anime.status}</code>"
            if hasattr(anime, "genres"):
                text += (
                    f"\n<b>{lang.genres}</b>: <code>{', '.join(anime.genres)}</code>"
                )
            if hasattr(anime, "studios"):
                text += (
                    f"\n<b>{lang.studios}</b>: <code>{', '.join(anime.studios)}</code>"
                )
            if hasattr(anime, "format"):
                text += f"\n<b>{lang.format}</b>: <code>{anime.format}</code>"
            if not anime.status.lower() == "not_yet_released":
                text += f"\n<b>{lang.start_date}</b>: <code>{anime.start_date.day if hasattr(anime.start_date, 'day') else 0}/{anime.start_date.month if hasattr(anime.start_date, 'month') else 0}/{anime.start_date.year if hasattr(anime.start_date, 'year') else 0}</code>"
            if not anime.status.lower() in ["not_yet_released", "releasing"]:
                text += f"\n<b>{lang.end_date}</b>: <code>{anime.end_date.day if hasattr(anime.end_date, 'day') else 0}/{anime.end_date.month if hasattr(anime.end_date, 'month') else 0}/{anime.end_date.year if hasattr(anime.end_date, 'year') else 0}</code>"

            text += f"\n\n<b>{lang.short_description}</b>: <i>{description}</i>"

            keyboard = [
                [(
                    lang.view_more_button,
                    f"https://t.me/{bot.me.username}/?start=anime_{anime.id}",
                    "url",
                )],
            ]

            results.append(
                InlineQueryResultPhoto(
                    photo_url=photo,
                    title=f"{anime.title.romaji} | {anime.format}",
                    description=description,
                    caption=text,
                    reply_markup=ikb(keyboard),
                ))

    if len(results) > 0:
        try:
            await inline_query.answer(
                results=results,
                is_gallery=False,
                cache_time=3,
            )
        except QueryIdInvalid:
            pass
Example #10
0
async def deflang(c: Client, iq: InlineQuery):
    iq._lang = langs.get_language(os.getenv("LANGUAGE"))