Example #1
0
async def kutt_it(e):
    reply_message = await e.get_reply_message()
    params = e.pattern_match.group(1) or ""
    args, params = parse_arguments(params, ["reuse"])

    urls = extract_urls(params)
    urls.extend(extract_urls(reply_message.text or ""))

    print(urls)

    if not urls:
        k = await e.edit("Need a URL to convert")
        await k.delete()
        await asyncio.sleep(3)
        return

    reuse = args.get("reuse", False)
    await e.edit("`Kutting...`")

    shortened = {}
    for url in urls:
        payload = {"target": url, "reuse": reuse}
        headers = {"X-API-Key": Config.KUTT_IT_API_KEY}
        resp = requests.post(API_ENDPOINT + "url/submit",
                             json=payload,
                             headers=headers)

        json = resp.json()
        shortened[url] = json["shortUrl"] if resp.status_code == 200 else None
    message = ""
    for item in shortened.items():
        message += f"Original URL: {item[0]} \nShortened URL: {item[1]} \n"

    await e.edit(message, link_preview=False)
Example #2
0
async def chat_info(e):
    params = e.pattern_match.group(1) or ""
    args, chat = parse_arguments(params,
                                 ['id', 'general', 'admins', 'bots', 'all'])
    args['chat'] = chat

    if isinstance(e.chat, User):
        from .userinfo import fetch_info as fetch_user_info
        replied_user = await e.client(GetFullUserRequest(e.chat.id))
        response = await fetch_user_info(replied_user, **args)
    else:
        full_chat: ChatFull = await get_chat_from_event(e, **args)

        await e.edit("`Fetching chat info...`")
        response = await fetch_info(e, full_chat, **args)

    await e.edit(str(response))
Example #3
0
async def doc_search(e):
    params = e.pattern_match.group(1)
    args, lib = parse_arguments(params, ['version'])
    lib = lib.strip()

    version = int(args.get('version', 3))
    python_url = f"https://docs.python.org/{version}/library/{lib}.html"
    pip_url = f"https://pypi.org/project/{lib}/"

    await e.edit(f"Searching Docs For `{lib}`...")
    if requests.get(python_url).status_code == 200:
        response = f"[Python {version} Documentation for {lib}]({python_url})"
        await e.edit(response)
    elif requests.get(pip_url).status_code == 200:
        readthedocs_url = f"https://readthedocs.org/projects/{lib}/"
        if requests.get(readthedocs_url).status_code == 200:
            response = f"[Documentation for {lib} on Read The Docs]({readthedocs_url})"
            await e.edit(response)
    else:
        fak = await e.edit(f"No Docs Found for `{lib}`...")
        await asyncio.sleep(3)
        await fak.delete()