Bläddra i källkod

Improved Many things

TheHamkerCat 5 år sedan
förälder
incheckning
8f7049658c
7 ändrade filer med 77 tillägg och 98 borttagningar
  1. 16 6
      wbb/modules/inline.py
  2. 1 6
      wbb/modules/music.py
  3. 0 43
      wbb/modules/paste.py
  4. 1 7
      wbb/modules/webss.py
  5. 7 1
      wbb/utils/functions.py
  6. 52 34
      wbb/utils/inlinefuncs.py
  7. 0 1
      wbb/utils/pastebin.py

+ 16 - 6
wbb/modules/inline.py

@@ -1,3 +1,4 @@
+import re
 from wbb import app
 from wbb.utils.inlinefuncs import *
 from pyrogram import filters
@@ -10,21 +11,21 @@ __HELP__ = '''```
 - tr [LANG] [QUERY] - Translate Text.
 - ud [QUERY] - Urban Dictionary Query.
 - google [QUERY] - Google Search.
-- webss [URL] - Take Screenshot Of A Website.
 - bitly [URL] - Shorten A Link.
 - wall [QUERY] - Find Wallpapers.
-- music [QUERY] - Get Music.
-- saavn [SONG_NAME] - Get Songs From Saavn.
-- deezer [SONG_NAME] - Get Songs From Deezer.
 - yt [Query] - Youtube Search.
 - torrent [QUERY] - Torrent Search.
 - lyrics [QUERY] - Lyrics Search.
 - wiki [QUERY] - Wikipedia Search.
 - speedtest - Perform A Speedtest.
 - eval [CODE] - Execute Python Code.
+- music [QUERY] - Get Music.
+- saavn [SONG_NAME] - Get Songs From Saavn.
+- deezer [SONG_NAME] - Get Songs From Deezer.
 - gh_user [USERNAME | PROFILE_LINK] - Search A Github User.
 - gh_repo [REPO_LINK] - Search A Github Repo.
 - search [QUERY] - Search For A Message Globally.
+- [MESSAGE_LINK] - To Paste A Message On Pastebin. Text | Document
 ```'''
 
 
@@ -342,6 +343,15 @@ async def inline_query_handler(client, query):
             )
             return
 
-    except Exception as e:
-        print(str(e) + "InLine")
+        elif re.search(r'^https?://t.me/', text.strip()):
+            answerss = await pastebin_func(answers, text.strip())
+            await client.answer_inline_query(
+                query.id,
+                results=answerss,
+                cache_time=2
+            )
+            return
+
+    except KeyError:
+        print(str(e) + " InLine")
         return

+ 1 - 6
wbb/modules/music.py

@@ -22,11 +22,6 @@ __HELP__ = """/ytmusic [link] To Download Music From Various Websites Including
 ydl_opts = {
     'format': 'bestaudio/best',
     'writethumbnail': True,
-    'postprocessors': [{
-        'key': 'FFmpegExtractAudio',
-        'preferredcodec': 'mp3',
-        'preferredquality': '192'
-    }]
 }
 
 
@@ -51,7 +46,7 @@ async def music(_, message):
             thumbnail_url = info_dict['thumbnail']
             thumbnail_file = basename + "." + \
                 get_file_extension_from_url(thumbnail_url)
-            audio_file = basename + ".mp3"
+            audio_file = basename + ".webm"
     except Exception as e:
         await m.edit(str(e))
         return

+ 0 - 43
wbb/modules/paste.py

@@ -1,43 +0,0 @@
-import os
-from pyrogram import filters
-from wbb.utils.pastebin import paste
-from wbb import app
-from wbb.core.decorators.errors import capture_err
-
-__MODULE__ = "Paste"
-__HELP__ = "/paste - To Paste Replied Text Or Document To Nekobin"
-
-
-@app.on_message(filters.command("paste") & ~filters.edited)
-@capture_err
-async def paste_func(_, message):
-    if message.reply_to_message:
-        app.set_parse_mode("markdown")
-        if message.reply_to_message.text:
-            m = await message.reply_text("Pasting...")
-            content = str(message.reply_to_message.text)
-            link = await paste(content)
-            await m.delete()
-            await app.send_photo(
-                    message.chat.id,
-                    photo=link + "/preview.png",
-                    caption=link
-                    )
-
-        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.")
-                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())
-            await m.delete()
-            await app.send_photo(
-                    message.chat.id,
-                    photo=link + "/preview.png",
-                    caption=link
-                    )
-            os.remove(doc_file)
-    else:
-        await message.reply_text("Reply To A Message With /paste")

+ 1 - 7
wbb/modules/webss.py

@@ -1,8 +1,6 @@
 from wbb import app
 from wbb.core.decorators.errors import capture_err
-from wbb.utils.fetch import fetch
 from pyrogram import filters
-import time
 
 
 __MODULE__ = "WebSS"
@@ -16,16 +14,12 @@ async def take_ss(_, message):
         await message.reply_text("Give A Url To Fetch Screenshot.")
         return
     url = message.text.split(None, 1)[1]
-    start_time = time.time()
     m = await message.reply_text("**Taking Screenshot**")
-    screenshot = await fetch(f"https://patheticprogrammers.cf/ss?site={url}")
     await m.edit("**Uploading**")
-    end_time = time.time()
     try:
         await app.send_photo(
             message.chat.id,
-            photo=screenshot['url'],
-            caption=(f"{url}\n__Took {round(end_time - start_time)} Seconds.__")
+            photo=f"https://webshot.amanoteam.com/print?q={url}",
             )
     except TypeError:
         await m.edit("No Such Website.")

+ 7 - 1
wbb/utils/functions.py

@@ -72,6 +72,12 @@ async def test_speedtest():
 
 async def file_size_from_url(url: str) -> int:
     async with aiohttp.ClientSession() as session:
-        async with session.get(url) as resp:
+        async with session.head(url) as resp:
             size = int(resp.headers['content-length'])
     return size
+
+
+async def get_http_status_code(url: str)-> int:
+    async with aiohttp.ClientSession() as session:
+        async with session.head(url) as resp:
+            return resp.status

+ 52 - 34
wbb/utils/inlinefuncs.py

@@ -18,7 +18,7 @@ from pyrogram import __version__ as pyrover, filters
 from time import time, ctime
 from wbb.modules.userbot import eval_executor_func
 from wbb.utils.fetch import fetch
-from wbb.utils.functions import test_speedtest
+from wbb.utils.functions import test_speedtest, get_http_status_code
 from wbb.utils.formatter import convert_seconds_to_minutes as time_convert
 from wbb.utils.pastebin import paste
 from wbb.core.types import InlineQueryResultCachedDocument
@@ -196,7 +196,7 @@ async def saavn_func(answers, text):
                 'Download | Play',
                 url=results[i].media_url
             )
-       )
+        )
         buttons_list.append(buttons)
         duration = await time_convert(results[i].duration)
         caption = f"""
@@ -260,26 +260,6 @@ async def deezer_func(answers, text):
     return answers
 
 
-async def webss(url):
-    start_time = time()
-    if "." not in url:
-        return
-    screenshot = await fetch(f"https://patheticprogrammers.cf/ss?site={url}")
-    end_time = time()
-    try:
-        m = await app.send_photo(LOG_GROUP_ID, photo=screenshot['url'])
-    except TypeError:
-        return
-    await m.delete()
-    a = []
-    pic = InlineQueryResultPhoto(
-        photo_url=screenshot['url'],
-        caption=(f"`{url}`\n__Took {round(end_time - start_time)} Seconds.__")
-    )
-    a.append(pic)
-    return a
-
-
 # Used my api key here, don't fuck with it
 async def shortify(url):
     if "." not in url:
@@ -597,7 +577,8 @@ async def music_inline_func(answers, query):
     messages_ids_and_duration = []
     for f_ in messages:
         messages_ids_and_duration.append(
-            {"message_id": f_.message_id, "duration": f_.audio.duration if f_.audio.duration else 0}
+            {"message_id": f_.message_id,
+                "duration": f_.audio.duration if f_.audio.duration else 0}
         )
     messages = list(
         {v["duration"]: v for v in messages_ids_and_duration}.values())
@@ -647,14 +628,15 @@ async def speedtest_init(query):
         return answers
     msg = "**Click The Button Below To Perform A Speedtest**"
     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(
-             InlineQueryResultArticle(
-                 title="Click Here",
-                 input_message_content=InputTextMessageContent(msg),
-                 reply_markup=button
-                 )
-             )
+        InlineQueryResultArticle(
+            title="Click Here",
+            input_message_content=InputTextMessageContent(msg),
+            reply_markup=button
+        )
+    )
     return answers
 
 """ callback query for the function above """
@@ -667,8 +649,8 @@ async def test_speedtest_cq(_, cq):
         return
     inline_message_id = cq.inline_message_id
     await app.edit_inline_text(
-            inline_message_id,
-            "**Testing**"
+        inline_message_id,
+        "**Testing**"
     )
     download, upload, info = await test_speedtest()
     msg = f"""
@@ -680,7 +662,43 @@ async def test_speedtest_cq(_, cq):
 **Longitude:** `{info['lon']}`
 """
     await app.edit_inline_text(
-            inline_message_id,
-            msg
+        inline_message_id,
+        msg
     )
 
+pastebin_cache = {}
+
+
+async def pastebin_func(answers, link):
+    global pastebin_cache
+    link = link.split("/")
+    if link[3] == "c":
+        chat, message_id = int("-100" + link[4]), int(link[5])
+    else:
+        chat, message_id = link[3], link[4]
+    m = await app.get_messages(chat, message_ids=int(message_id))
+    if m.text not in pastebin_cache:
+        link = await paste(m.text)
+        preview = link + "/preview.png"
+        pastebin_cache[m.text] = link
+        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 
+        await app.send_photo(USERBOT_ID, preview) # To Pre-cache the media
+    else:
+        link = pastebin_cache[m.text]
+        preview = link + "/preview.png"
+    buttons = InlineKeyboard(row_width=1)
+    buttons.add(InlineKeyboardButton(text="Paste Link", url=link))
+    answers.append(
+        InlineQueryResultPhoto(
+            photo_url=preview,
+            reply_markup=buttons
+        )
+        )
+    return answers

+ 0 - 1
wbb/utils/pastebin.py

@@ -1,6 +1,5 @@
 import socket
 
-
 async def _netcat(host, port, content):
     s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     s.connect((host, port))