From ca05287c51519ddde9c67a71ac30b4886934691d Mon Sep 17 00:00:00 2001 From: xtaodada Date: Tue, 2 Aug 2022 13:28:30 +0800 Subject: [PATCH] =?UTF-8?q?google=20=E8=B0=B7=E6=AD=8C=E6=90=9C=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- google/main.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 google/main.py diff --git a/google/main.py b/google/main.py new file mode 100644 index 0000000..9ae4d26 --- /dev/null +++ b/google/main.py @@ -0,0 +1,32 @@ +from pagermaid import Config, log +from pagermaid.listener import listener +from pagermaid.enums import Message +from pagermaid.utils import lang, pip_install + +pip_install("magic-google", alias="magic_google") + +from magic_google import MagicGoogle + + +@listener(command="google", + description=lang('google_des'), + parameters="") +async def google(message: Message): + """ Searches Google for a string. """ + query = message.arguments + if not query: + return await message.edit(lang('arg_error')) + 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): + try: + title = i['text'][:30] + '...' + link = i['url'] + results += f"\n{title} \n" + except Exception: + return await message.edit(lang('google_connection_error')) + await message.edit(f"Google |{query}| 🎙 🔍 \n{results}", disable_web_page_preview=True) + await log(f"{lang('google_success')} `{query}`")