Jelajahi Sumber

Inline Help

TheHamkerCat 5 tahun lalu
induk
melakukan
e0b93578a2
3 mengubah file dengan 141 tambahan dan 7 penghapusan
  1. 122 3
      wbb/modules/inline.py
  2. 18 3
      wbb/utils/inlinefuncs.py
  3. 1 1
      wbb/utils/pastebin.py

+ 122 - 3
wbb/modules/inline.py

@@ -24,11 +24,10 @@ __HELP__ = '''```
 - yt [Query] - Youtube Search.
 - torrent [QUERY] - Torrent Search.
 - lyrics [QUERY] - Lyrics Search.
-- calendar - Get Current Month Calendar.
 - 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. 
+- gh_repo [USERNAME/REPO] - Search A Github Repo.
+- search [QUERY] - Search For A Message Globally.
 ```'''
 
 
@@ -58,6 +57,14 @@ async def inline_query_handler(client, query):
                 cache_time=10
             )
         elif text.split()[0] == "tr":
+            if len(text.split()) < 3:
+                await client.answer_inline_query(
+                    query.id,
+                    results=answers,
+                    switch_pm_text='Translate Text.',
+                    switch_pm_parameter='inline',
+                )
+                return
             lang = text.split()[1]
             tex = text.split(None, 2)[2].strip()
             answerss = await translate_func(answers, lang, tex)
@@ -66,6 +73,14 @@ async def inline_query_handler(client, query):
                 results=answerss,
             )
         elif text.split()[0] == "ud":
+            if len(text.split()) < 2:
+                await client.answer_inline_query(
+                    query.id,
+                    results=answers,
+                    switch_pm_text='Search Urban Dictionary.',
+                    switch_pm_parameter='inline',
+                )
+                return
             tex = text.split(None, 1)[1].strip()
             answerss = await urban_func(answers, tex)
             await client.answer_inline_query(
@@ -73,6 +88,14 @@ async def inline_query_handler(client, query):
                 results=answerss,
             )
         elif text.split()[0] == "google":
+            if len(text.split()) < 2:
+                await client.answer_inline_query(
+                    query.id,
+                    results=answers,
+                    switch_pm_text='Search Google.',
+                    switch_pm_parameter='inline',
+                )
+                return
             tex = text.split(None, 1)[1].strip()
             answerss = await google_search_func(answers, tex)
             await client.answer_inline_query(
@@ -80,6 +103,14 @@ async def inline_query_handler(client, query):
                 results=answerss,
             )
         elif text.split()[0] == "webss":
+            if len(text.split()) < 2:
+                await client.answer_inline_query(
+                    query.id,
+                    results=answers,
+                    switch_pm_text='Take Screenshot Of A Website.',
+                    switch_pm_parameter='inline',
+                )
+                return
             tex = text.split(None, 1)[1].strip()
             answerss = await webss(tex)
             await client.answer_inline_query(
@@ -88,6 +119,14 @@ async def inline_query_handler(client, query):
                 cache_time=2
             )
         elif text.split()[0] == "bitly":
+            if len(text.split()) < 2:
+                await client.answer_inline_query(
+                    query.id,
+                    results=answers,
+                    switch_pm_text='Shorten A Link.',
+                    switch_pm_parameter='inline',
+                )
+                return
             tex = text.split(None, 1)[1].strip()
             answerss = await shortify(tex)
             await client.answer_inline_query(
@@ -97,6 +136,14 @@ async def inline_query_handler(client, query):
             )
 
         elif text.split()[0] == "wall":
+            if len(text.split()) < 2:
+                await client.answer_inline_query(
+                    query.id,
+                    results=answers,
+                    switch_pm_text='Search Wallpapers.',
+                    switch_pm_parameter='inline',
+                )
+                return
             tex = text.split(None, 1)[1].strip()
             answerss = await wall_func(answers, tex)
             await client.answer_inline_query(
@@ -105,6 +152,14 @@ async def inline_query_handler(client, query):
             )
 
         elif text.split()[0] == "saavn":
+            if len(text.split()) < 2:
+                await client.answer_inline_query(
+                    query.id,
+                    results=answers,
+                    switch_pm_text='Search Songs On JioSaavn.',
+                    switch_pm_parameter='inline',
+                )
+                return
             tex = text.split(None, 1)[1].strip()
             answerss = await saavn_func(answers, tex)
             await client.answer_inline_query(
@@ -113,6 +168,14 @@ async def inline_query_handler(client, query):
             )
 
         elif text.split()[0] == "deezer":
+            if len(text.split()) < 2:
+                await client.answer_inline_query(
+                    query.id,
+                    results=answers,
+                    switch_pm_text='Search Songs On Deezer.',
+                    switch_pm_parameter='inline',
+                )
+                return
             tex = text.split(None, 1)[1].strip()
             answerss = await deezer_func(answers, tex)
             await client.answer_inline_query(
@@ -121,6 +184,14 @@ async def inline_query_handler(client, query):
             )
 
         elif text.split()[0] == "torrent":
+            if len(text.split()) < 2:
+                await client.answer_inline_query(
+                    query.id,
+                    results=answers,
+                    switch_pm_text='Search For Torrent.',
+                    switch_pm_parameter='inline',
+                )
+                return
             tex = text.split(None, 1)[1].strip()
             answerss = await torrent_func(answers, tex)
             await client.answer_inline_query(
@@ -129,6 +200,14 @@ async def inline_query_handler(client, query):
             )
 
         elif text.split()[0] == "yt":
+            if len(text.split()) < 2:
+                await client.answer_inline_query(
+                    query.id,
+                    results=answers,
+                    switch_pm_text='Search YouTube.',
+                    switch_pm_parameter='inline',
+                )
+                return
             tex = text.split(None, 1)[1].strip()
             answerss = await youtube_func(answers, tex)
             await client.answer_inline_query(
@@ -137,6 +216,14 @@ async def inline_query_handler(client, query):
             )
 
         elif text.split()[0] == "lyrics":
+            if len(text.split()) < 2:
+                await client.answer_inline_query(
+                    query.id,
+                    results=answers,
+                    switch_pm_text='Search Lyrics.',
+                    switch_pm_parameter='inline',
+                )
+                return
             tex = text.split(None, 1)[1].strip()
             answerss = await lyrics_func(answers, tex)
             await client.answer_inline_query(
@@ -145,6 +232,14 @@ async def inline_query_handler(client, query):
             )
 
         elif text.split()[0] == "eval":
+            if len(text.split()) < 2:
+                await client.answer_inline_query(
+                    query.id,
+                    results=answers,
+                    switch_pm_text='Excute Python Code.',
+                    switch_pm_parameter='inline',
+                )
+                return
             user_id = query.from_user.id
             tex = text.split(None, 1)[1].strip()
             answerss = await eval_func(answers, tex, user_id)
@@ -155,6 +250,14 @@ async def inline_query_handler(client, query):
             )
 
         elif text.split()[0] == "gh_user":
+            if len(text.split()) < 2:
+                await client.answer_inline_query(
+                    query.id,
+                    results=answers,
+                    switch_pm_text='Search Github User.',
+                    switch_pm_parameter='inline',
+                )
+                return
             tex = text.split(None, 1)[1].strip()
             answerss = await github_user_func(answers, tex)
             await client.answer_inline_query(
@@ -164,6 +267,14 @@ async def inline_query_handler(client, query):
             )
 
         elif text.split()[0] == "gh_repo":
+            if len(text.split()) < 2:
+                await client.answer_inline_query(
+                    query.id,
+                    results=answers,
+                    switch_pm_text='Search Github Repo.',
+                    switch_pm_parameter='inline',
+                )
+                return
             tex = text.split(None, 1)[1].strip()
             answerss = await github_repo_func(answers, tex)
             await client.answer_inline_query(
@@ -173,6 +284,14 @@ async def inline_query_handler(client, query):
             )
 
         elif text.split()[0] == "search":
+            if len(text.split()) < 2:
+                await client.answer_inline_query(
+                    query.id,
+                    results=answers,
+                    switch_pm_text='Global Message Search.',
+                    switch_pm_parameter='inline',
+                )
+                return
             user_id = query.from_user.id
             tex = text.split(None, 1)[1].strip()
             answerss = await tg_search_func(answers, tex, user_id)

+ 18 - 3
wbb/utils/inlinefuncs.py

@@ -112,7 +112,11 @@ __**Translated to {lang}**__
 
 async def urban_func(answers, text):
     results = await arq.urbandict(text)
+    limit = 0
     for i in results:
+        if limit > 48:
+            break
+        limit += 1
         msg = f"""
 **Query:** {text}
 
@@ -131,7 +135,12 @@ async def urban_func(answers, text):
 
 async def google_search_func(answers, text):
     gresults = await GoogleSearch().async_search(text)
+    limit = 0
     for i in gresults:
+        if limit > 48:
+            break
+        limit += 1
+
         try:
             msg = f"""
 [{i['titles']}]({i['links']})
@@ -153,7 +162,11 @@ async def google_search_func(answers, text):
 
 async def wall_func(answers, text):
     results = await arq.wall(text)
+    limit = 0
     for i in results:
+        if limit > 48:
+            break
+        limit += 1
         try:
             answers.append(
                 InlineQueryResultPhoto(
@@ -326,9 +339,12 @@ async def torrent_func(answers, text):
 
 
 async def youtube_func(answers, text):
-    buttons_list = []
     results = await arq.youtube(text)
+    limit = 0
     for i in results:
+        if limit > 48:
+            break
+        limit += 1
         buttons = InlineKeyboard(row_width=1)
         video_url = f"https://youtube.com{results[i].url_suffix}"
         buttons.add(
@@ -337,7 +353,6 @@ async def youtube_func(answers, text):
                 url=video_url
             )
         )
-        buttons_list.append(buttons)
         caption = f"""
 **Title:** {results[i].title}
 **Views:** {results[i].views}
@@ -357,7 +372,7 @@ async def youtube_func(answers, text):
                         caption,
                         disable_web_page_preview=True
                     ),
-                    reply_markup=buttons_list[i]
+                    reply_markup=buttons
                 ))
         except (KeyError, ValueError):
             pass

+ 1 - 1
wbb/utils/pastebin.py

@@ -3,7 +3,7 @@ import socket
 
 async def _netcat(host, port, content):
     s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
-    s.connect((host, int(port)))
+    s.connect((host, port))
     s.sendall(content.encode())
     s.shutdown(socket.SHUT_WR)
     while True: