Example #1
0
def google(client: Client, message: Message) -> None:
    query = " ".join(message.command[1:])
    command = message.command[0]

    with GoogleAPI() as g_client:
        if command == "g":
            response: GoogleResponse = g_client.search(
                query, search_type=SEARCH_TYPE.TEXT)
            if response:
                client.send_chat_action(message.chat.id, "typing")
                client.send_message(
                    message.chat.id,
                    f"<b>{response.title}</b>\n\n{response.snippet}\n\n{response.url}",
                    parse_mode="HTML",
                )
            else:
                Common.send_not_found_message(message)

        if command == "gi" or command == "p":
            response: GoogleImageResponse = g_client.search(
                query, search_type=SEARCH_TYPE.IMAGE)

            if response:
                client.send_chat_action(message.chat.id, "upload_photo")
                client.send_photo(
                    message.chat.id,
                    response.url,
                    caption=
                    f"<i>{response.snippet}</i>\n\n{response.source_url}",
                    parse_mode="HTML",
                )
            else:
                Common.send_not_found_message(message)
Example #2
0
def youtube(client: Client, message: Message) -> None:
    query = " ".join(message.command[1:])

    with YouTubeAPI() as y_client:
        response = y_client.search(query)

        if response:
            client.send_chat_action(message.chat.id, "typing")
            result = f'<b><a href="{response.url}">{response.title}</a></b>'
            client.send_message(message.chat.id, result, parse_mode="HTML")
        else:
            Common.send_not_found_message(message)
Example #3
0
def steamstats(client: Client, message: Message):
    query = " ".join(message.command[1:]) if len(message.command) > 1 else None

    with SteamStatsAPI() as steam_client:
        if query:
            result = steam_client.get_online_status(query)
        else:
            result = steam_client.get_online_status()

        if result:
            return client.send_message(
                message.chat.id,
                f"<b>{result.service}</b>: <code>{result.status}</code>",
                parse_mode="HTML",
            )

    return Common.send_not_found_message(message)