Bläddra i källkod

Added github search inline

TheHamkerCat 5 år sedan
förälder
incheckning
e71a5ba98b
6 ändrade filer med 124 tillägg och 71 borttagningar
  1. 1 1
      sample_config.py
  2. 0 50
      wbb/modules/github.py
  3. 37 15
      wbb/modules/inline.py
  4. 5 1
      wbb/modules/sudoers.py
  5. 3 2
      wbb/modules/userbot.py
  6. 78 2
      wbb/utils/inlinefuncs.py

+ 1 - 1
sample_config.py

@@ -6,7 +6,7 @@ MAIN_CHATS = [-1001485393652]  # NOTE These are the chats where main functions o
 SUDO_USERS_ID = [51635132416, 1342121354245, 23452465243] # Sudo users have full access to everythin, don't trust anyone
 LOG_GROUP_ID = -1001337393587
 GBAN_LOG_GROUP_ID = -1001401678112
-FERNET_ENCRYPTION_KEY = "iKMq0WZMnJKjMQxZWKtv-cplMuF_LoyshXj0XbTGGWM="
+FERNET_ENCRYPTION_KEY = "iKMq0WZMnJKjMQxZWKtv-cplMuF_LoyshXj0XbTGGWM=" # Leave this as it is
 WELCOME_DELAY_KICK_SEC = 300
 MONGO_DB_URI = "mongodb+srv://username:password@cluster0.ksiis.mongodb.net/YourDataBaseName?retryWrites=true&w=majority"
 

+ 0 - 50
wbb/modules/github.py

@@ -1,50 +0,0 @@
-import aiohttp
-from pyrogram import filters
-from wbb import app
-from wbb.utils.errors import capture_err
-
-__MODULE__ = 'Github'
-__HELP__ = "Get information about a GitHub user.\n /github [username]"
-
-
-@app.on_message(filters.command('github'))
-@capture_err
-async def github(_, message):
-    if len(message.command) != 2:
-        await message.reply_text("/git Username")
-        return
-    username = message.text.split(None, 1)[1]
-    URL = f'https://api.github.com/users/{username}'
-    async with aiohttp.ClientSession() as session:
-        async with session.get(URL) as request:
-            if request.status == 404:
-                return await message.reply_text("404")
-
-            result = await request.json()
-            try:
-                url = result['html_url']
-                name = result['name']
-                company = result['company']
-                bio = result['bio']
-                created_at = result['created_at']
-                avatar_url = result['avatar_url']
-                blog = result['blog']
-                location = result['location']
-                repositories = result['public_repos']
-                followers = result['followers']
-                following = result['following']
-                caption = f"""**Info Of {name}**
-**Username:** `{username}`
-**Bio:** `{bio}`
-**Profile Link:** [Here]({url})
-**Company:** `{company}`
-**Created On:** `{created_at}`
-**Repositories:** `{repositories}`
-**Blog:** `{blog}`
-**Location:** `{location}`
-**Followers:** `{followers}`
-**Following:** `{following}`"""
-            except Exception as e:
-                print(str(e))
-                pass
-    await message.reply_photo(photo=avatar_url, caption=caption)

+ 37 - 15
wbb/modules/inline.py

@@ -4,9 +4,11 @@ from wbb.utils.inlinefuncs import (
     alive_function, webss, shortify, wall_func,
     saavn_func, deezer_func, inline_help_func,
     torrent_func, youtube_func, lyrics_func,
-    paste_func, eval_func
+    paste_func, eval_func, github_user_func,
+    github_repo_func
 )
 from pyrogram import filters
+from pyrogram.errors.exceptions.bad_request_400 import QueryIdInvalid
 
 __MODULE__ = "Inline"
 __HELP__ = '''
@@ -24,6 +26,8 @@ __HELP__ = '''
 - lyrics [QUERY] - Lyrics Search.
 - eval [CODE] - Execute Python Code.
 - paste [TEXT] - Paste Text On Pastebin. <=500
+- gh_user [USERNAME] - Search A Github User.
+- gh_repo [USERNAME/REPO] - Search A Github Repo. 
 '''
 
 
@@ -54,28 +58,28 @@ async def inline_query_handler(client, query):
             )
         elif text.split()[0] == "tr":
             lang = text.split()[1]
-            tex = text.split(None, 2)[2]
+            tex = text.split(None, 2)[2].strip()
             answerss = await translate_func(answers, lang, tex)
             await client.answer_inline_query(
                 query.id,
                 results=answerss,
             )
         elif text.split()[0] == "ud":
-            tex = text.split(None, 1)[1]
+            tex = text.split(None, 1)[1].strip()
             answerss = await urban_func(answers, tex)
             await client.answer_inline_query(
                 query.id,
                 results=answerss,
             )
         elif text.split()[0] == "google":
-            tex = text.split(None, 1)[1]
+            tex = text.split(None, 1)[1].strip()
             answerss = await google_search_func(answers, tex)
             await client.answer_inline_query(
                 query.id,
                 results=answerss,
             )
         elif text.split()[0] == "webss":
-            tex = text.split(None, 1)[1]
+            tex = text.split(None, 1)[1].strip()
             answerss = await webss(tex)
             await client.answer_inline_query(
                 query.id,
@@ -83,7 +87,7 @@ async def inline_query_handler(client, query):
                 cache_time=2
             )
         elif text.split()[0] == "bitly":
-            tex = text.split(None, 1)[1]
+            tex = text.split(None, 1)[1].strip()
             answerss = await shortify(tex)
             await client.answer_inline_query(
                 query.id,
@@ -92,7 +96,7 @@ async def inline_query_handler(client, query):
             )
 
         elif text.split()[0] == "wall":
-            tex = text.split(None, 1)[1]
+            tex = text.split(None, 1)[1].strip()
             answerss = await wall_func(answers, tex)
             await client.answer_inline_query(
                 query.id,
@@ -100,7 +104,7 @@ async def inline_query_handler(client, query):
             )
 
         elif text.split()[0] == "saavn":
-            tex = text.split(None, 1)[1]
+            tex = text.split(None, 1)[1].strip()
             answerss = await saavn_func(answers, tex)
             await client.answer_inline_query(
                 query.id,
@@ -108,7 +112,7 @@ async def inline_query_handler(client, query):
             )
 
         elif text.split()[0] == "deezer":
-            tex = text.split(None, 1)[1]
+            tex = text.split(None, 1)[1].strip()
             answerss = await deezer_func(answers, tex)
             await client.answer_inline_query(
                 query.id,
@@ -116,7 +120,7 @@ async def inline_query_handler(client, query):
             )
 
         elif text.split()[0] == "torrent":
-            tex = text.split(None, 1)[1]
+            tex = text.split(None, 1)[1].strip()
             answerss = await torrent_func(answers, tex)
             await client.answer_inline_query(
                 query.id,
@@ -124,7 +128,7 @@ async def inline_query_handler(client, query):
             )
 
         elif text.split()[0] == "yt":
-            tex = text.split(None, 1)[1]
+            tex = text.split(None, 1)[1].strip()
             answerss = await youtube_func(answers, tex)
             await client.answer_inline_query(
                 query.id,
@@ -132,7 +136,7 @@ async def inline_query_handler(client, query):
             )
 
         elif text.split()[0] == "lyrics":
-            tex = text.split(None, 1)[1]
+            tex = text.split(None, 1)[1].strip()
             answerss = await lyrics_func(answers, tex)
             await client.answer_inline_query(
                 query.id,
@@ -140,7 +144,7 @@ async def inline_query_handler(client, query):
             )
 
         elif text.split()[0] == "paste":
-            tex = text.split(None, 1)[1]
+            tex = text.split(None, 1)[1].strip()
             answerss = await paste_func(answers, tex)
             await client.answer_inline_query(
                 query.id,
@@ -150,7 +154,7 @@ async def inline_query_handler(client, query):
 
         elif text.split()[0] == "eval":
             user_id = query.from_user.id
-            tex = text.split(None, 1)[1]
+            tex = text.split(None, 1)[1].strip()
             answerss = await eval_func(answers, tex, user_id)
             await client.answer_inline_query(
                 query.id,
@@ -158,5 +162,23 @@ async def inline_query_handler(client, query):
                 cache_time=2
             )
 
-    except (IndexError, TypeError, KeyError, ValueError):
+        elif text.split()[0] == "gh_user":
+            tex = text.split(None, 1)[1].strip()
+            answerss = await github_user_func(answers, tex)
+            await client.answer_inline_query(
+                query.id,
+                results=answerss,
+                cache_time=2
+            )
+
+        elif text.split()[0] == "gh_repo":
+            tex = text.split(None, 1)[1].strip()
+            answerss = await github_repo_func(answers, tex)
+            await client.answer_inline_query(
+                query.id,
+                results=answerss,
+                cache_time=2
+            )
+
+    except (IndexError, TypeError, KeyError, ValueError, QueryIdInvalid):
         return

+ 5 - 1
wbb/modules/sudoers.py

@@ -187,7 +187,11 @@ __**New Global Ban**__
 **Reason:** __{reason}__
 **Chats:** `{number_of_chats}`"""
             try:
-                await app.send_message(GBAN_LOG_GROUP_ID, text=ban_text)
+                await app.send_message(
+                        GBAN_LOG_GROUP_ID,
+                        text=ban_text,
+                        disable_web_page_preview=True
+                        )
             except Exception:
                 await message.reply_text("User Gbanned, But This Gban Wasn't Logged, Add Bot In GBAN_LOG_GROUP")
                 return

+ 3 - 2
wbb/modules/userbot.py

@@ -184,6 +184,7 @@ async def eval_executor_func(code):
         evaluation = stdout
     else:
         evaluation = "Success"
+    output = evaluation.strip()
     final_output = (
-        f"**INPUT:**\n```{code}```\n\n**OUTPUT**:\n```{evaluation.strip()}```")
-    return final_output
+        f"**INPUT:**\n```{code}```\n\n**OUTPUT**:\n```{output}```")
+    return [final_output, output]

+ 78 - 2
wbb/utils/inlinefuncs.py

@@ -22,6 +22,7 @@ from motor import version as mongover
 from pyrogram import __version__ as pyrover
 import aiohttp
 import json
+import asyncio
 
 
 async def inline_help_func(__HELP__):
@@ -421,12 +422,87 @@ async def eval_func(answers, text, user_id):
     text = text[0:-1]
     start_time = time()
     result = await eval_executor_func(text)
+    output = result[1]
+    result = result[0]
     msg = f"{result}"
     end_time = time()
     answers.append(
         InlineQueryResultArticle(
-            title="Success",
-            description=f"Executed In {round(end_time - start_time)} Seconds.",
+            title=f"Took {round(end_time - start_time)} Seconds.",
+            description=output,
             input_message_content=InputTextMessageContent(msg)
         ))
     return answers
+
+
+async def github_user_func(answers, text):
+    URL = f"https://api.github.com/users/{text}"
+    result = await fetch(URL)
+    buttons = InlineKeyboard(row_width=1)
+    buttons.add(InlineKeyboardButton(
+        text="Open On Github",
+        url=f"https://github.com/{text}"
+        ))
+    caption = f"""
+**Info Of {result['name']}**
+**Username:** `{text}`
+**Bio:** `{result['bio']}`
+**Profile Link:** [Here]({result['html_url']})
+**Company:** `{result['company']}`
+**Created On:** `{result['created_at']}`
+**Repositories:** `{result['public_repos']}`
+**Blog:** `{result['blog']}`
+**Location:** `{result['location']}`
+**Followers:** `{result['followers']}`
+**Following:** `{result['following']}`"""
+    answers.append(
+        InlineQueryResultPhoto(
+            photo_url=result['avatar_url'],
+            caption=caption,
+            reply_markup=buttons
+        ))
+    return answers
+
+
+async def github_repo_func(answers, text):
+    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))
+    r = results[0]
+    r1 = results[1]
+    commits = 0
+    for developer in r1:
+        commits += developer['contributions']
+    buttons = InlineKeyboard(row_width=1)
+    buttons.add(
+            InlineKeyboardButton(
+                'Open On Github',
+                url=f"https://github.com/{text}"
+            )
+        )
+    caption = f"""
+**Info Of {r['full_name']}**
+**Stars:** `{r['stargazers_count']}`
+**Watchers:** `{r['watchers_count']}`
+**Forks:** `{r['forks_count']}`
+**Commits:** `{commits}`
+**Is Fork:** `{r['fork']}`
+**Language:** `{r['language']}`
+**Contributors:** `{len(r1)}`
+**License:** `{r['license']['name']}`
+**Repo Owner:** [{r['owner']['login']}]({r['owner']['html_url']})
+**Created On:** `{r['created_at']}`
+**Homepage:** {r['homepage']}
+**Description:** __{r['description']}__"""
+    answers.append(
+        InlineQueryResultArticle(
+            title="Found Repo",
+            description=text,
+            reply_markup=buttons,
+            input_message_content=InputTextMessageContent(
+                caption,
+                disable_web_page_preview=True
+                )
+        ))
+    return answers
+