Quellcode durchsuchen

Reverse search module

TheHamkerCat vor 5 Jahren
Ursprung
Commit
1ab301f980
4 geänderte Dateien mit 90 neuen und 2 gelöschten Zeilen
  1. 0 1
      wbb/modules/inline.py
  2. 1 0
      wbb/modules/misc.py
  3. 88 0
      wbb/modules/reverse.py
  4. 1 1
      wbb/utils/inlinefuncs.py

+ 0 - 1
wbb/modules/inline.py

@@ -23,7 +23,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 SOFTWARE.
 """
 
-import re
 import traceback
 from wbb import app
 from wbb.utils.inlinefuncs import *

+ 1 - 0
wbb/modules/misc.py

@@ -72,6 +72,7 @@ async def getid(_, message):
     if len(message.command) == 2:
         id = (await app.get_users(message.text.split(None, 1)[1])).id
         text = f"<b>ID:</b> {id}"
+        await message.reply_text(text)
         return
     text_unping = "<b>Chat ID:</b>"
     if message.chat.username:

+ 88 - 0
wbb/modules/reverse.py

@@ -0,0 +1,88 @@
+from wbb import app
+from wbb.core.decorators.errors import capture_err
+from pyrogram import filters
+from bs4 import BeautifulSoup
+from random import randint
+import aiohttp
+import aiofiles
+import requests
+import os
+
+__MODULE__ = "Reverse"
+__HELP__ = "/reverse  - Reverse search an image."
+
+
+@app.on_message(filters.command("reverse"))
+@capture_err
+async def reverse_image_search(_, message):
+    if not message.reply_to_message:
+        await message.reply_text("Reply to a message to reverse search it.")
+        return
+    reply = message.reply_to_message
+    if not reply.document and not reply.photo and not reply.sticker and not reply.animation and not reply.video:
+        await message.reply_text("Reply to an image/document/sticker/animation to reverse search it.")
+        return
+    m = await message.reply_text("Searching")
+    if reply.document:
+        if int(reply.document.file_size) > 3145728:
+            await m.edit("File too large")
+            return
+        mime_type = reply.document.mime_type
+        if mime_type != "image/png" and mime_type != "image/jpeg":
+            await m.edit("Document Mimetype Invalid")
+            return
+    if reply.sticker:
+        if reply.sticker.is_animated:
+            if not reply.sticker.thumbs:
+                await m.edit("Sticker Has No Thumb")
+                return
+            file_id = reply.sticker.thumbs[0].file_id
+        else:
+            file_id = reply.sticker.file_id
+
+    if reply.photo:
+        file_id = reply.photo.file_id
+
+    if reply.animation:
+        if not reply.animation.thumbs:
+            await m.edit("Gif Has No Thumbnail, so it cannot be reverse searched")
+            return
+        file_id = reply.animation.thumbs[0].file_id
+
+    if reply.video:
+        if not reply.video.thumbs:
+            return
+        file_id = reply.video.thumbs[0].file_id
+    image = await app.download_media(file_id, f"{randint(1000, 10000)}.jpg")
+    async with aiofiles.open(image, "rb") as f:
+        if image:
+            search_url = "http://www.google.com/searchbyimage/upload"
+            multipart = {
+                "encoded_image": (image, await f.read()),
+                "image_content": ""
+            }
+            response = requests.post(search_url, files=multipart, allow_redirects=False)
+            location = response.headers.get("Location")
+            os.remove(image)
+        else:
+            await m.edit("Something wrong happened.")
+            return
+    headers = {
+        "User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:58.0) Gecko/20100101 Firefox/58.0"
+    }
+    async with aiohttp.ClientSession() as session:
+        async with session.get(location, headers=headers) as resp:
+            soup = BeautifulSoup(await resp.text(), "html.parser")
+    div = soup.find_all("div", {"class": "r5a77d"})[0]
+    anchor_element = div.find("a")
+    text = anchor_element.text
+    try:
+        await app.send_photo(
+                message.chat.id,
+                photo=f"https://webshot.amanoteam.com/print?q={location}",
+                caption=f"**Query** [{text}]({location})"
+                )
+        await m.delete()
+    except Exception:
+        text = f"**Result**: [Link]({location})"
+        await m.edit(text)

+ 1 - 1
wbb/utils/inlinefuncs.py

@@ -64,7 +64,7 @@ async def inline_help_func(__HELP__):
         "wall", "yt", "torrent", "lyrics", "wiki",
         "speedtest", "eval", "music", "saavn", "deezer",
         "gh_repo", "gh_user", "search", "pastebin",
-        "nsfw_scan", "ytmusic", "carbon"
+        "nsfw_scan", "ytmusic", "carbon", "info"
     ]
     buttons.add(*[(InlineKeyboardButton(
         text=i, switch_inline_query_current_chat=i)) for i in keywords_list])