TheHamkerCat 5 лет назад
Родитель
Сommit
a35593f635
3 измененных файлов с 128 добавлено и 82 удалено
  1. 15 0
      wbb/modules/inline.py
  2. 26 29
      wbb/modules/paste.py
  3. 87 53
      wbb/utils/inlinefuncs.py

+ 15 - 0
wbb/modules/inline.py

@@ -398,6 +398,21 @@ async def inline_query_handler(client, query):
             await client.answer_inline_query(
             await client.answer_inline_query(
                 query.id, results=answerss, cache_time=2
                 query.id, results=answerss, cache_time=2
             )
             )
+
+        elif text.split()[0] == "pypi":
+            if len(text.split()) < 2:
+                await client.answer_inline_query(
+                    query.id,
+                    results=answers,
+                    switch_pm_text="Pypi Search | pypi [Package Name]",
+                    switch_pm_parameter="inline",
+                )
+                return
+            tex = text.split()[1].strip()
+            answerss = await pypiSearchFunc(answers, tex)
+            await client.answer_inline_query(
+                query.id, results=answerss, cache_time=2
+            )
     except Exception as e:
     except Exception as e:
         e = traceback.format_exc()
         e = traceback.format_exc()
         print(e, " InLine")
         print(e, " InLine")

+ 26 - 29
wbb/modules/paste.py

@@ -21,13 +21,16 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 SOFTWARE.
 SOFTWARE.
 """
 """
+import aiohttp
 import asyncio
 import asyncio
 import os
 import os
 
 
+from pykeyboard import InlineKeyboard
 from pyrogram import filters
 from pyrogram import filters
 from pyrogram.errors.exceptions.bad_request_400 import WebpageCurlFailed
 from pyrogram.errors.exceptions.bad_request_400 import WebpageCurlFailed
+from pyrogram.types import InlineKeyboardButton
 
 
-from wbb import aiohttpsession, app
+from wbb import aiohttpsession as session, app
 from wbb.core.decorators.errors import capture_err
 from wbb.core.decorators.errors import capture_err
 from wbb.utils.functions import get_http_status_code
 from wbb.utils.functions import get_http_status_code
 from wbb.utils.pastebin import paste
 from wbb.utils.pastebin import paste
@@ -46,8 +49,8 @@ async def isPreviewUp(preview: str) -> bool:
             return False
             return False
         if status == 404 or (status == 200 and size == 0):
         if status == 404 or (status == 200 and size == 0):
             await asyncio.sleep(0.4)
             await asyncio.sleep(0.4)
-        elif status == 200 and size > 0:
-            return True
+        else:
+            return True if status == 200 else False
     return False
     return False
 
 
 
 
@@ -55,37 +58,31 @@ async def isPreviewUp(preview: str) -> bool:
 @capture_err
 @capture_err
 async def paste_func(_, message):
 async def paste_func(_, message):
     if message.reply_to_message:
     if message.reply_to_message:
+        m = await message.reply_text("Pasting...")
         if message.reply_to_message.text:
         if message.reply_to_message.text:
-            m = await message.reply_text("Pasting...")
             content = str(message.reply_to_message.text)
             content = str(message.reply_to_message.text)
-            link = await paste(content)
-            preview = link + "/preview.png"
-            if await isPreviewUp(preview):
-                await message.reply_photo(
-                    photo=preview, caption=link, quote=false
-                )
-                return
-            await m.edit(link)
 
 
         elif message.reply_to_message.document:
         elif message.reply_to_message.document:
-            if message.reply_to_message.document.file_size > 1048576:
-                await message.reply_text(
-                    "You can only paste files smaller than 1MB."
-                )
+            document = message.reply_to_message.document
+            if document.file_size > 1048576:
+                await m.edit("You can only paste files smaller than 1MB.")
                 return
                 return
-            m = await message.reply_text("Pasting...")
-            doc_file = await message.reply_to_message.download(
-                file_name="paste.txt"
-            )
-            i = open(doc_file, "r")
-            link = await paste(i.read())
-            preview = link + "/preview.png"
-            if await isPreviewUp(preview):
-                await message.reply_photo(
-                    photo=preview, caption=link, quote=false
-                )
+            if "text" not in document.mime_type:
+                await m.edit("Only text files can be pasted.")
                 return
                 return
-            await m.edit(link)
-            os.remove(doc_file)
+            doc = await message.reply_to_message.download()
+            async with aiofiles.open(doc, mode="r") as f:
+                content = await f.read()
+            os.remove(doc)
+        link = await paste(content)
+        preview = link + "/preview.png"
+        button = InlineKeyboard(row_width=1)
+        button.add(InlineKeyboardButton(text="Paste Link", url=link))
+
+        if await isPreviewUp(preview):
+            await message.reply_photo(photo=preview, quote=False, reply_markup=button)
+            await m.delete()
+            return
+        await m.edit(link)
     else:
     else:
         await message.reply_text("Reply To A Message With /paste")
         await message.reply_text("Reply To A Message With /paste")

+ 87 - 53
wbb/utils/inlinefuncs.py

@@ -36,19 +36,32 @@ from pykeyboard import InlineKeyboard
 from pyrogram import __version__ as pyrover
 from pyrogram import __version__ as pyrover
 from pyrogram import filters
 from pyrogram import filters
 from pyrogram.raw.functions import Ping
 from pyrogram.raw.functions import Ping
-from pyrogram.types import (InlineKeyboardButton, InlineQueryResultArticle,
-                            InlineQueryResultPhoto, InputTextMessageContent)
+from pyrogram.types import (
+    InlineKeyboardButton,
+    InlineQueryResultArticle,
+    InlineQueryResultPhoto,
+    InputTextMessageContent,
+)
 from search_engine_parser import GoogleSearch
 from search_engine_parser import GoogleSearch
 
 
-from wbb import (BOT_USERNAME, MESSAGE_DUMP_CHAT, SUDOERS, USERBOT_ID,
-                 USERBOT_NAME, USERBOT_USERNAME, app, app2, arq)
+from wbb import (
+    BOT_USERNAME,
+    MESSAGE_DUMP_CHAT,
+    SUDOERS,
+    USERBOT_ID,
+    USERBOT_NAME,
+    USERBOT_USERNAME,
+    app,
+    app2,
+    arq,
+)
 from wbb.core.types import InlineQueryResultCachedDocument
 from wbb.core.types import InlineQueryResultCachedDocument
 from wbb.modules.info import get_chat_info, get_user_info
 from wbb.modules.info import get_chat_info, get_user_info
 from wbb.modules.music import download_youtube_audio
 from wbb.modules.music import download_youtube_audio
+from wbb.modules.paste import isPreviewUp
 from wbb.utils.fetch import fetch
 from wbb.utils.fetch import fetch
 from wbb.utils.formatter import convert_seconds_to_minutes as time_convert
 from wbb.utils.formatter import convert_seconds_to_minutes as time_convert
-from wbb.utils.functions import (get_http_status_code, make_carbon,
-                                 test_speedtest)
+from wbb.utils.functions import make_carbon, test_speedtest
 from wbb.utils.pastebin import paste
 from wbb.utils.pastebin import paste
 
 
 keywords_list = [
 keywords_list = [
@@ -77,6 +90,7 @@ keywords_list = [
     "info",
     "info",
     "chat_info",
     "chat_info",
     "tmdb",
     "tmdb",
+    "pypi",
 ]
 ]
 
 
 
 
@@ -117,9 +131,7 @@ async def alive_function(answers):
     ubot_state = "Dead" if not await app2.get_me() else "Alive"
     ubot_state = "Dead" if not await app2.get_me() else "Alive"
     buttons.add(
     buttons.add(
         InlineKeyboardButton("Stats", callback_data="stats_callback"),
         InlineKeyboardButton("Stats", callback_data="stats_callback"),
-        InlineKeyboardButton(
-            "Go Inline!", switch_inline_query_current_chat=""
-        ),
+        InlineKeyboardButton("Go Inline!", switch_inline_query_current_chat=""),
     )
     )
 
 
     msg = f"""
     msg = f"""
@@ -175,9 +187,7 @@ __**Translated from {result.src} to {result.dest}**__
             ),
             ),
             InlineQueryResultArticle(
             InlineQueryResultArticle(
                 title=result.translatedText,
                 title=result.translatedText,
-                input_message_content=InputTextMessageContent(
-                    result.translatedText
-                ),
+                input_message_content=InputTextMessageContent(result.translatedText),
             ),
             ),
         ]
         ]
     )
     )
@@ -435,9 +445,7 @@ async def youtube_func(answers, text):
 **Duration:** {i.duration}
 **Duration:** {i.duration}
 **Uploaded:** {i.publish_time}
 **Uploaded:** {i.publish_time}
 **Description:** {i.long_desc}"""
 **Description:** {i.long_desc}"""
-        description = (
-            f"{i.views} | {i.channel} | {i.duration} | {i.publish_time}"
-        )
+        description = f"{i.views} | {i.channel} | {i.duration} | {i.publish_time}"
         answers.append(
         answers.append(
             InlineQueryResultArticle(
             InlineQueryResultArticle(
                 title=i.title,
                 title=i.title,
@@ -488,9 +496,7 @@ async def github_user_func(answers, text):
     result = await fetch(URL)
     result = await fetch(URL)
     buttons = InlineKeyboard(row_width=1)
     buttons = InlineKeyboard(row_width=1)
     buttons.add(
     buttons.add(
-        InlineKeyboardButton(
-            text="Open On Github", url=f"https://github.com/{text}"
-        )
+        InlineKeyboardButton(text="Open On Github", url=f"https://github.com/{text}")
     )
     )
     caption = f"""
     caption = f"""
 **Info Of {result['name']}**
 **Info Of {result['name']}**
@@ -529,9 +535,7 @@ async def github_repo_func(answers, text):
         commits += developer["contributions"]
         commits += developer["contributions"]
     buttons = InlineKeyboard(row_width=1)
     buttons = InlineKeyboard(row_width=1)
     buttons.add(
     buttons.add(
-        InlineKeyboardButton(
-            "Open On Github", url=f"https://github.com/{text}"
-        )
+        InlineKeyboardButton("Open On Github", url=f"https://github.com/{text}")
     )
     )
     caption = f"""
     caption = f"""
 **Info Of {r['full_name']}**
 **Info Of {r['full_name']}**
@@ -595,9 +599,7 @@ async def tg_search_func(answers, text, user_id):
             ),
             ),
         )
         )
         name = (
         name = (
-            message.from_user.first_name
-            if message.from_user.first_name
-            else "NO NAME"
+            message.from_user.first_name if message.from_user.first_name else "NO NAME"
         )
         )
         caption = f"""
         caption = f"""
 **Query:** {text}
 **Query:** {text}
@@ -651,9 +653,7 @@ async def music_inline_func(answers, query):
                 "duration": f_.audio.duration if f_.audio.duration else 0,
                 "duration": f_.audio.duration if f_.audio.duration else 0,
             }
             }
         )
         )
-    messages = list(
-        {v["duration"]: v for v in messages_ids_and_duration}.values()
-    )
+    messages = list({v["duration"]: v for v in messages_ids_and_duration}.values())
     messages_ids = []
     messages_ids = []
     for ff_ in messages:
     for ff_ in messages:
         messages_ids.append(ff_["message_id"])
         messages_ids.append(ff_["message_id"])
@@ -710,9 +710,7 @@ async def speedtest_init(query):
         return answers
         return answers
     msg = "**Click The Button Below To Perform A Speedtest**"
     msg = "**Click The Button Below To Perform A Speedtest**"
     button = InlineKeyboard(row_width=1)
     button = InlineKeyboard(row_width=1)
-    button.add(
-        InlineKeyboardButton(text="Test", callback_data="test_speedtest")
-    )
+    button.add(InlineKeyboardButton(text="Test", callback_data="test_speedtest"))
     answers.append(
     answers.append(
         InlineQueryResultArticle(
         InlineQueryResultArticle(
             title="Click Here",
             title="Click Here",
@@ -762,9 +760,7 @@ async def pastebin_func(answers, link):
                 InlineQueryResultArticle(
                 InlineQueryResultArticle(
                     title="DOCUMENT TOO BIG",
                     title="DOCUMENT TOO BIG",
                     description="Maximum supported size is 1MB",
                     description="Maximum supported size is 1MB",
-                    input_message_content=InputTextMessageContent(
-                        "DOCUMENT TOO BIG"
-                    ),
+                    input_message_content=InputTextMessageContent("DOCUMENT TOO BIG"),
                 )
                 )
             )
             )
             return answers
             return answers
@@ -774,20 +770,12 @@ async def pastebin_func(answers, link):
         os.remove(doc)
         os.remove(doc)
     link = await paste(content)
     link = await paste(content)
     preview = link + "/preview.png"
     preview = link + "/preview.png"
-    status_code = await get_http_status_code(preview)
-    i = 0
-    while status_code != 200:
-        if i == 5:
-            break
-        status_code = await get_http_status_code(preview)
-        await asyncio.sleep(0.2)
-        i += 1
+    if not await isPreviewUp(preview):
+        return []
     await app.send_photo(MESSAGE_DUMP_CHAT, preview)  # To Pre-cache the media
     await app.send_photo(MESSAGE_DUMP_CHAT, preview)  # To Pre-cache the media
     buttons = InlineKeyboard(row_width=1)
     buttons = InlineKeyboard(row_width=1)
     buttons.add(InlineKeyboardButton(text="Paste Link", url=link))
     buttons.add(InlineKeyboardButton(text="Paste Link", url=link))
-    answers.append(
-        InlineQueryResultPhoto(photo_url=preview, reply_markup=buttons)
-    )
+    answers.append(InlineQueryResultPhoto(photo_url=preview, reply_markup=buttons))
     return answers
     return answers
 
 
 
 
@@ -803,9 +791,7 @@ async def pmpermit_func(answers, user_id, victim):
         InlineKeyboardButton(
         InlineKeyboardButton(
             text="For promotion", callback_data="pmpermit to_scam_you a"
             text="For promotion", callback_data="pmpermit to_scam_you a"
         ),
         ),
-        InlineKeyboardButton(
-            text="Approve me", callback_data="pmpermit approve_me a"
-        ),
+        InlineKeyboardButton(text="Approve me", callback_data="pmpermit approve_me a"),
         InlineKeyboardButton(
         InlineKeyboardButton(
             text="Approve", callback_data=f"pmpermit approve {victim}"
             text="Approve", callback_data=f"pmpermit approve {victim}"
         ),
         ),
@@ -923,9 +909,7 @@ async def carbon_inline_func(answers, link):
                 InlineQueryResultArticle(
                 InlineQueryResultArticle(
                     title="DOCUMENT TOO BIG",
                     title="DOCUMENT TOO BIG",
                     description="Maximum supported size is 1MB",
                     description="Maximum supported size is 1MB",
-                    input_message_content=InputTextMessageContent(
-                        "DOCUMENT TOO BIG"
-                    ),
+                    input_message_content=InputTextMessageContent("DOCUMENT TOO BIG"),
                 )
                 )
             )
             )
             return answers
             return answers
@@ -1012,9 +996,7 @@ async def tmdb_func(answers, query):
         )
         )
         answers.append(
         answers.append(
             InlineQueryResultPhoto(
             InlineQueryResultPhoto(
-                photo_url=result.backdrop
-                if result.backdrop
-                else result.poster,
+                photo_url=result.backdrop if result.backdrop else result.poster,
                 caption=caption,
                 caption=caption,
                 title=result.title,
                 title=result.title,
                 description=f"{genre} • {result.releaseDate} • {result.rating} • {description}",
                 description=f"{genre} • {result.releaseDate} • {result.rating} • {description}",
@@ -1022,3 +1004,55 @@ async def tmdb_func(answers, query):
             )
             )
         )
         )
     return answers
     return answers
+
+
+async def pypiSearchFunc(answers: list, query: str) -> list:
+    result = await arq.pypi(query)
+    if not result.ok:
+        answers.append(
+            InlineQueryResultArticle(
+                title="No Such Package",
+                description=result.result,
+                input_message_content=InputTextMessageContent(result.result),
+            )
+        )
+        return answers
+    result = result.result
+    pURLS = [f"**{key}**: {value}" for key, value in result.projectURLS.items()]
+    pURLS = ("\n" + "\n".join(pURLS)) if pURLS else None
+    caption = f"""
+**Name:** {result.name}
+**Version:** {result.version}
+**License:** {result.license}
+**Description:** {result.description}
+**Size:** {result.size}
+**Last Update:** {result.uploadTime}
+**Author:** {result.author}
+**Author's Email:** {result.authorEmail}
+**Requirements:** {(f'`{" | ".join(result.requirements)}`') if result.requirements else None}
+**Minimum Python Version:** {result.minPyVersion}
+**Homepage:** {result.homepage}
+**Bug Tracker:** {result.bugTrackURL}
+**Docs Url:** {result.docsURL}
+**Pypi Url:** {result.pypiURL}
+**Releases:** {result.releaseURL}
+**Project Urls:** ->{pURLS}
+"""
+    button = InlineKeyboard(row_width=2)
+    button.add(
+        InlineKeyboardButton(text="Open Page", url=result.pypiURL),
+        InlineKeyboardButton(
+            text="Search Again", switch_inline_query_current_chat="pypi"
+        ),
+    )
+    answers.append(
+        InlineQueryResultArticle(
+            title=f"{result.name}  |  {result.version}",
+            description=result.description,
+            input_message_content=InputTextMessageContent(
+                caption, disable_web_page_preview=True
+            ),
+            reply_markup=button,
+        )
+    )
+    return answers