PagerMaid_Plugins_Pyro/google/main.py
Godlike 003dbd8bca
All checks were successful
Github commit to telegram / build (push) Successful in 15s
google Force Simplified Chinese Results for MagicGoogle Searches (#187)
2024-11-02 21:51:18 +08:00

37 lines
1.3 KiB
Python

from pagermaid.config import Config
from pagermaid.listener import listener
from pagermaid.enums import Message
from pagermaid.utils import lang, pip_install
from pagermaid.utils.bot_utils import log
pip_install("magic-google", alias="magic_google")
from magic_google import MagicGoogle
@listener(command="google", description=lang("google_des"), parameters="[query]")
async def google(message: Message):
"""Searches Google for a string."""
query = message.arguments
if not query:
if not message.reply_to_message:
return await message.edit(lang("arg_error"))
query = message.reply_to_message.text
mg = MagicGoogle()
query = query.replace(" ", "+")
if not Config.SILENT:
message = await message.edit(lang("google_processing"))
results = ""
for i in mg.search(query=query, num=5, language="zh-CN"):
try:
title = i["text"][:30] + "..."
link = i["url"]
results += f'\n<a href="{link}">{title}</a> \n'
except Exception:
return await message.edit(lang("google_connection_error"))
await message.edit(
f"<b>Google</b> |<code>{query}</code>| 🎙 🔍 \n{results}",
disable_web_page_preview=True,
)
await log(f"{lang('google_success')} `{query}`")