TheHamkerCat 5 سال پیش
والد
کامیت
35cf349bc3
4فایلهای تغییر یافته به همراه77 افزوده شده و 13 حذف شده
  1. 17 0
      wbb/modules/inline.py
  2. 29 11
      wbb/modules/nsfw.py
  3. 4 0
      wbb/modules/pmpermit.py
  4. 27 2
      wbb/utils/inlinefuncs.py

+ 17 - 0
wbb/modules/inline.py

@@ -353,6 +353,23 @@ async def inline_query_handler(client, query):
             )
             return
 
+        elif text.split()[0] == "nsfw_scan":
+            if len(text.split()) < 2:
+                await client.answer_inline_query(
+                    query.id,
+                    results=answers,
+                    switch_pm_text='NSFW Scan | nsfw_scan [url]',
+                    switch_pm_parameter='inline',
+                )
+                return
+            tex = text.split(None, 1)[1].strip()
+            answerss = await nsfw_scan_func(answers, tex)
+            await client.answer_inline_query(
+                query.id,
+                results=answerss,
+                cache_time=2
+            )
+
     except Exception as e:
         e = traceback.format_exc()
         print(e, " InLine")

+ 29 - 11
wbb/modules/nsfw.py

@@ -2,6 +2,7 @@ from wbb import app, arq, IMGBB_API_KEY, MESSAGE_DUMP_CHAT
 from wbb.utils.filter_groups import nsfw_detect_group
 from wbb.utils.dbfunctions import is_nsfw_on, nsfw_on, nsfw_off
 from wbb.modules.admin import member_permissions
+from wbb.core.decorators.errors import capture_err
 from pyrogram import filters
 from random import randint
 import aiohttp
@@ -9,7 +10,15 @@ import aiofiles
 import os
 
 
+__MODULE__ = "NSFW"
+__HELP__ = """
+/nsfw_scan - Manually Scan An Image/Sticker/Document.
+/anti_nsfw [ENABLE | DISABLE] - Turn This Module On/Off
+"""
+
+
 @app.on_message((filters.document | filters.photo | filters.sticker) & ~filters.private, group=nsfw_detect_group)
+@capture_err
 async def detect_nsfw(_, message):
     if message.document:
         if int(message.document.file_size) > 3145728:
@@ -39,10 +48,13 @@ async def detect_nsfw(_, message):
     hentai = results.data.hentai
     sexy = results.data.sexy
     porn = results.data.porn
+    drawings = results.data.drawings
     neutral = results.data.neutral
-    if hentai < 80 and porn < 70 and sexy < 95:
+    if neutral > 80:
         return
-    if neutral > 30:
+    if (hentai + porn + sexy) < 85:
+        return
+    if neutral > 20:
         return
     user_mention = message.from_user.mention
     user_id = message.from_user.id
@@ -54,16 +66,19 @@ async def detect_nsfw(_, message):
     await message.reply_text(f"""
 **NSFW [Image]({m.link}) Detected & Deleted Successfully!
 ————————————————————————**
-
 **User:** {user_mention} [`{user_id}`]
-**Safe:** `{neutral}` %
-**Porn:** `{porn}` %
-**Adult:** `{sexy}` %
-**Hentai:** `{hentai}` %
+**Safe:** `{neutral} %`
+**Porn:** `{porn} %`
+**Adult:** `{sexy} %`
+**Hentai:** `{hentai} %`
+**Drawings:** `{drawings} %`
+**————————————————————————**
+__Use '/anti_nsfw disable' to disable this.__
 """)
 
 
 @app.on_message(filters.command("nsfw_scan"))
+@capture_err
 async def nsfw_scan_command(_, message):
     if not message.reply_to_message:
         await message.reply_text("Reply to an image or document to scan it.")
@@ -100,16 +115,19 @@ async def nsfw_scan_command(_, message):
     hentai = results.data.hentai
     sexy = results.data.sexy
     porn = results.data.porn
+    drawings = results.data.drawings
     neutral = results.data.neutral
     await m.edit(f"""
-**Neutral:** `{neutral}`
-**Porn:** `{porn}`
-**Hentai:** `{hentai}`
-**sexy:** `{sexy}`
+**Neutral:** `{neutral} %`
+**Porn:** `{porn} %`
+**Hentai:** `{hentai} %`
+**Sexy:** `{sexy} %`
+**Drawings:** `{drawings} %`
 """)
 
 
 @app.on_message(filters.command("anti_nsfw") & ~filters.private)
+@capture_err
 async def nsfw_enable_disable(_, message):
     if len(message.command) != 2:
         await message.reply_text("Usage: /anti_nsfw [enable | disable]")

+ 4 - 0
wbb/modules/pmpermit.py

@@ -25,12 +25,14 @@ SOFTWARE.
 from wbb import app, app2, BOT_ID, USERBOT_ID, SUDOERS, USERBOT_PREFIX
 from pyrogram import filters
 from wbb.utils.dbfunctions import is_pmpermit_approved, approve_pmpermit, disapprove_pmpermit
+from wbb.core.decorators.errors import capture_err
 import asyncio
 
 flood = {}
 
 
 @app2.on_message(filters.private & ~filters.edited & ~filters.me & ~filters.bot & ~filters.user(SUDOERS))
+@capture_err
 async def pmpermit_func(_, message):
     user_id = message.from_user.id
     if await is_pmpermit_approved(user_id):
@@ -56,6 +58,7 @@ async def pmpermit_func(_, message):
 
 
 @app2.on_message(filters.command("approve", prefixes=USERBOT_PREFIX) & filters.user(SUDOERS) & ~filters.via_bot)
+@capture_err
 async def pm_approve(_, message):
     if not message.reply_to_message:
         await message.edit("Reply to a user's message to approve.")
@@ -90,6 +93,7 @@ async def pm_disapprove(_, message):
 
 
 @app2.on_message(filters.command("block", prefixes=USERBOT_PREFIX) & filters.user(SUDOERS) & ~filters.via_bot)
+@capture_err
 async def block_user_func(_, message):
     if not message.reply_to_message:
         await message.edit("Reply to a user's message to approve.")

+ 27 - 2
wbb/utils/inlinefuncs.py

@@ -61,7 +61,7 @@ async def inline_help_func(__HELP__):
         "alive", "ping", "tr", "ud", "google", "bitly",
         "wall", "yt", "torrent", "lyrics", "wiki",
         "speedtest", "eval", "music", "saavn", "deezer",
-        "gh_repo", "gh_user", "search", "pastebin"
+        "gh_repo", "gh_user", "search", "pastebin", "nsfw_scan"
     ]
     buttons.add(*[(InlineKeyboardButton(
         text=i, switch_inline_query_current_chat=i)) for i in keywords_list])
@@ -786,7 +786,7 @@ async def ping_func(answers):
     ping = Ping(ping_id=randint(696969, 6969696))
     await app.send(ping)
     t2 = time()
-    ping = f"{str(round((t2 - t1), 4))} Seconds"
+    ping = f"{str(round((t2 - t1), 6))} Seconds"
     answers.append(
         InlineQueryResultArticle(
             title=ping,
@@ -795,3 +795,28 @@ async def ping_func(answers):
         )
     )
     return answers
+
+
+async def nsfw_scan_func(answers, url:str):
+    t1 = time()
+    data = (await arq.nsfw_scan(url)).data
+    t2 = time()
+    tt = round(t2-t1, 4)
+    content = f"""
+**Scanned [Image]({url}) In {tt} Seconds.**
+
+**Drawings:** `{data.drawings} %`
+**Neutral:** `{data.neutral} %`
+**Hentai:** `{data.hentai} %`
+**Porn:** `{data.porn} %`
+**Sexy:** `{data.sexy} %`
+    """
+    answers.append(
+            InlineQueryResultArticle(
+                title="Scanned",
+                description=f"Took {tt} Seconds.",
+                input_message_content=InputTextMessageContent(content)
+                )
+            )
+    return answers
+