Ver código fonte

Added inline wiki search

TheHamkerCat 5 anos atrás
pai
commit
fbfaa240ca
2 arquivos alterados com 42 adições e 2 exclusões
  1. 20 2
      wbb/modules/inline.py
  2. 22 0
      wbb/utils/inlinefuncs.py

+ 20 - 2
wbb/modules/inline.py

@@ -19,9 +19,10 @@ __HELP__ = '''```
 - yt [Query] - Youtube Search.
 - torrent [QUERY] - Torrent Search.
 - lyrics [QUERY] - Lyrics Search.
+- wiki [QUERY] - Wikipedia Search.
 - eval [CODE] - Execute Python Code.
-- gh_user [USERNAME] - Search A Github User.
-- gh_repo [USERNAME/REPO] - Search A Github Repo.
+- gh_user [USERNAME | PROFILE_LINK] - Search A Github User.
+- gh_repo [REPO_LINK] - Search A Github Repo.
 - search [QUERY] - Search For A Message Globally.
 ```'''
 
@@ -313,6 +314,23 @@ async def inline_query_handler(client, query):
                 cache_time=2
             )
 
+
+        elif text.split()[0] == "wiki":
+            if len(text.split()) < 2:
+                await client.answer_inline_query(
+                    query.id,
+                    results=answers,
+                    switch_pm_text='Search Wikipedia.',
+                    switch_pm_parameter='inline',
+                )
+                return
+            tex = text.split(None, 1)[1].strip()
+            answerss = await wiki_func(answers, tex)
+            await client.answer_inline_query(
+                query.id,
+                results=answerss,
+                cache_time=2
+            )
     except Exception as e:
         print(str(e) + "InLine")
         return

+ 22 - 0
wbb/utils/inlinefuncs.py

@@ -470,6 +470,10 @@ async def github_user_func(answers, text):
 
 
 async def github_repo_func(answers, text):
+    text = text.replace("https://github.com/", "")
+    text = text.replace("http://github.com/", "")
+    if text[-1] == "/":
+        text = text[0:-1]
     URL = f"https://api.github.com/repos/{text}"
     URL2 = f"https://api.github.com/repos/{text}/contributors"
     results = await asyncio.gather(fetch(URL), fetch(URL2))
@@ -606,3 +610,21 @@ async def music_inline_func(answers, query):
             )
         )
     return answers
+
+
+async def wiki_func(answers, text):
+    data = await arq.wiki(text)
+    msg = f"""
+**QUERY:**
+{data['title']}
+
+**ANSWER:**
+__{data['answer']}__"""
+    answers.append(
+        InlineQueryResultArticle(
+            title=data['title'],
+            description=data['answer'],
+            input_message_content=InputTextMessageContent(msg)
+        )
+    )
+    return answers