Explorar o código

NSFW classification

TheHamkerCat %!s(int64=5) %!d(string=hai) anos
pai
achega
bac0c904ed

+ 4 - 4
app.json

@@ -29,10 +29,6 @@
             "description": "Need for Userbot Module So u can execute .sh & .l cmd",
             "required": false
         },
-        "MAIN_CHATS": {
-            "description": "These are the chats where main functions of bot will work, like music downloading etc.",
-            "required": true
-        },
         "SUDO_USERS_ID": {
             "description": "Sudo users have full access to everythin, don't trust anyone... ex:- 123456 654311 123456",
             "required": true
@@ -62,6 +58,10 @@
             "description": "For Music Downloading And Many More Things... Don't change this value",
             "value": "https://thearq.tech",
             "required": true
+        },
+        "IMGBB_API_KEY": {
+            "description": "Get From Here. https://api.imgbb.com/",
+            "required": true
         }
     }
 }

+ 2 - 3
sample_config.py

@@ -7,13 +7,13 @@ if HEROKU:
     API_HASH = environ.get("API_HASH", "eb06d4abfb49dc3eeb1aeb98ae0f581e")
     SESSION_STRING = environ.get("SESSION_STRING", None)
     USERBOT_PREFIX = environ.get("USERBOT_PREFIX", None)
-    MAIN_CHATS = int(environ.get("MAIN_CHATS", None))
     SUDO_USERS_ID = list(int(x) for x in environ.get("SUDO_USERS_ID", "").split())
     LOG_GROUP_ID = int(environ.get("LOG_GROUP_ID", None))
     GBAN_LOG_GROUP_ID = int(environ.get("GBAN_LOG_GROUP_ID", None))
     FERNET_ENCRYPTION_KEY = environ.get("FERNET_ENCRYPTION_KEY", None)
     WELCOME_DELAY_KICK_SEC = int(environ.get("WELCOME_DELAY_KICK_SEC", None))
     MONGO_DB_URI = environ.get("MONGO_DB_URI", None)
+    IMGBB_API_KEY = environ.get("IMGBB_API_KEY", None)
     ARQ_API_BASE_URL = environ.get("ARQ_API_BASE_URL", None)
 
 else:
@@ -22,13 +22,12 @@ else:
     API_HASH = "dfxcgs5s12hdcxfgdfz"
     USERBOT_PREFIX = "."
     PHONE_NUMBER = "+916969696969" # Need for Helper Userbot
-    MAIN_CHATS = [-100125431255]  # NOTE These are the chats where main functions of bot will work, like music downloading etc.
     SUDO_USERS_ID = [4543744343, 543214651351] # Sudo users have full access to everythin, don't trust anyone
     LOG_GROUP_ID = -100125431255
     GBAN_LOG_GROUP_ID = -100125431255
     FERNET_ENCRYPTION_KEY = "iKMq0WZMnJKjMQxZWKtv-cplMuF_LoyshXj0XbTGGWM=" # Leave this as it is
     WELCOME_DELAY_KICK_SEC = 300
     MONGO_DB_URI = "mongodb+srv://username:password@cluster0.ksiis.mongodb.net/YourDataBaseName?retryWrites=true&w=majority"
-
+    IMGBB_API_KEY = "6as4g35a4g35a4wrg3a5wr4g3ar6g"
     # NOTE Don't make changes below this line
     ARQ_API_BASE_URL = "http://thearq.tech"

+ 1 - 1
wbb/__init__.py

@@ -38,10 +38,10 @@ else:
 listen = listen
 USERBOT_PREFIX = USERBOT_PREFIX
 SUDOERS = SUDO_USERS_ID
-MAIN_CHATS = MAIN_CHATS
 GBAN_LOG_GROUP_ID = GBAN_LOG_GROUP_ID
 FERNET_ENCRYPTION_KEY = FERNET_ENCRYPTION_KEY
 WELCOME_DELAY_KICK_SEC = WELCOME_DELAY_KICK_SEC
+IMGBB_API_KEY = IMGBB_API_KEY
 LOG_GROUP_ID = LOG_GROUP_ID
 MOD_LOAD = []
 MOD_NOLOAD = []

+ 16 - 26
wbb/modules/admin.py

@@ -290,38 +290,28 @@ async def promote(_, message):
         if "can_promote_members" not in permissions and from_user_id not in SUDOERS:
             await message.reply_text("You don't have enough permissions")
             return
+        bot = get_chat_member(chat_id, BOT_ID)
         if len(message.command) == 2:
             username = message.text.split(None, 1)[1]
             user_id = (await app.get_users(username)).id
-            await message.chat.promote_member(
-                user_id=user_id,
-                can_change_info=True,
-                can_invite_users=True,
-                can_delete_messages=True,
-                can_restrict_members=False,
-                can_pin_messages=True,
-                can_promote_members=True,
-                can_manage_chat=True,
-                can_manage_voice_chats=True
-            )
-            await message.reply_text('Promoted!')
-
         elif len(message.command) == 1 and message.reply_to_message:
             user_id = message.reply_to_message.from_user.id
-            await message.chat.promote_member(
-                user_id=user_id,
-                can_change_info=True,
-                can_invite_users=True,
-                can_delete_messages=True,
-                can_restrict_members=False,
-                can_pin_messages=True,
-                can_promote_members=True,
-                can_manage_chat=True,
-                can_manage_voice_chats=True
-            )
-            await message.reply_text('Promoted!')
         else:
             await message.reply_text("Reply To A User's Message Or Give A Username To Promote.")
+
+        await message.chat.promote_member(
+            user_id=user_id,
+            can_change_info=bot.can_change_info,
+            can_invite_users=bot.can_invite_users,
+            can_delete_messages=bot.can_delete_messages,
+            can_restrict_members=bot.can_restrict_members,
+            can_pin_messages=bot.can_pin_messages,
+            can_promote_members=bot.can_promote_members,
+            can_manage_chat=bot.can_manage_chat,
+            can_manage_voice_chats=bot.can_manage_voice_chats
+        )
+        await message.reply_text('Promoted!')
+
     except Exception as e:
         await message.reply_text(str(e))
 
@@ -478,7 +468,7 @@ async def warn_user(_, message):
                         await add_warn(chat_id, await int_to_alpha(user_id), warn)
                         await message.reply_text(f"Warned {mention} !, 1/3 warnings now.")
                         return
-                    if warns >= 3:
+                    if warns >= 2:
                         await message.chat.kick_member(user_id)
                         await message.reply_text(f"Number of warns of {mention} exceeded, Banned!")
                         await remove_warns(chat_id, await int_to_alpha(user_id))

+ 4 - 1
wbb/modules/filters.py

@@ -36,7 +36,10 @@ import re
 __MODULE__ = "Filters"
 __HELP__ = """/filters To Get All The Filters In The Chat.
 /filter [FILTER_NAME] To Save A Filter (Can be a sticker or text).
-/stop [FILTER_NAME] To Stop A Filter."""
+/stop [FILTER_NAME] To Stop A Filter.
+
+
+You can use markdown or html to save text too."""
 
 
 @app.on_message(filters.command("filter") & ~filters.edited & ~filters.private)

+ 4 - 3
wbb/modules/greetings.py

@@ -316,11 +316,12 @@ async def captcha_state(_, message):
 @app.on_message(filters.command("set_welcome") & ~filters.private)
 @capture_err
 async def set_welcome_func(_, message):
+    usage = "You need to reply to a text, check the Greetings module in /help"
     if not message.reply_to_message:
-        await message.reply_text("You need to reply to a text, check the Welcome module in /help")
+        await message.reply_text(usage)
         return
     if not message.reply_to_message.text:
-        await message.reply_text("You need to reply to a text, check the Welcome module in /help")
+        await message.reply_text(usage)
         return
     user_id = message.from_user.id
     chat_id = message.chat.id
@@ -330,7 +331,7 @@ async def set_welcome_func(_, message):
         return
     raw_text = str(message.reply_to_message.text.markdown)
     await set_welcome(chat_id, raw_text)
-    await message.reply_text("Welcome message has been set, Send /show_welcome to see what's been set.")
+    await message.reply_text("Welcome message has been successfully set.")
 
 
 @app.on_message(filters.command("del_welcome") & ~filters.private)

+ 51 - 0
wbb/modules/nsfw.py

@@ -0,0 +1,51 @@
+from wbb import app, arq, SUDOERS, IMGBB_API_KEY
+from wbb.utils.filter_groups import nsfw_detect_group
+from pyrogram import filters
+from random import randint
+import aiohttp
+import aiofiles
+import os
+
+
+@app.on_message(filters.document | filters.photo & ~filters.private, group=nsfw_detect_group)
+async def detect_nsfw(_, message):
+    if message.document:
+        if int(message.document.file_size) > 3145728:
+            return
+        mime_type = message.document.mime_type
+        if mime_type != "image/png" and mime_type != "image/jpeg":
+            return
+    image = await message.download(f"{randint(6666, 9999)}.jpg")
+    async with aiofiles.open(image, mode='rb') as f:
+        payload = {
+        "key": IMGBB_API_KEY,
+        "image": await f.read(),
+        "expiration": "60"
+    }
+    async with aiohttp.ClientSession() as session:
+        async with session.post("https://api.imgbb.com/1/upload", data=payload) as resp:
+            data = await resp.json()
+        url = data['data']['url']
+    os.remove(image)
+    results = await arq.nsfw_scan(url)
+    hentai = results.data.hentai
+    sexy = results.data.sexy
+    porn = results.data.porn
+    neutral = results.data.neutral
+    if hentai < 80 and porn < 70 and sexy < 80:
+        return
+    if neutral > 30:
+        return
+    await message.delete()
+    user_mention = message.from_user.mention
+    user_id = message.from_user.id
+    await message.reply_text(f"""
+**NSFW Image Detected & Deleted Successfully!
+————————————————————————**
+
+**User:** {user_mention} [`{user_id}`]
+**Safe:** `{neutral}`
+**Porn:** `{porn}`
+**Adult:** `{sexy}`
+**Hentai:** `{hentai}`
+""")

+ 0 - 33
wbb/modules/ping.py

@@ -1,33 +0,0 @@
-"""
-MIT License
-
-Copyright (c) 2021 TheHamkerCat
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-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
-SOFTWARE.
-"""
-from pyrogram import filters
-from wbb import app
-
-__MODULE__ = "Ping"
-__HELP__ = " /ping - To Check If Bot Is Alive"
-
-
-@app.on_message(filters.command("ping") & ~filters.edited)
-async def ping(_, message):
-    await message.reply_text("Alive!")

+ 5 - 2
wbb/modules/sudoers.py

@@ -59,13 +59,16 @@ async def bot_sys_stats():
     cpu = psutil.cpu_percent(interval=0.5)
     mem = psutil.virtual_memory().percent
     disk = psutil.disk_usage("/").percent
+    process = psutil.Process(os.getpid())
     stats = f'''
 {USERBOT_USERNAME}@William
 ------------------
-Uptime: {formatter.get_readable_time((bot_uptime))}
+UPTIME: {formatter.get_readable_time((bot_uptime))}
+BOT: {process.memory_info()[0] / 1024 ** 2} MB
 CPU: {cpu}%
 RAM: {mem}%
-Disk: {disk}%'''
+DISK: {disk}%
+'''
     return stats
 
 

+ 17 - 14
wbb/modules/webss.py

@@ -33,18 +33,21 @@ __HELP__ = "/webss | .webss [URL] - Take A Screenshot Of A Webpage"
 @app.on_message(filters.command("webss"))
 @capture_err
 async def take_ss(_, message):
-    if len(message.command) != 2:
-        await message.reply_text("Give A Url To Fetch Screenshot.")
-        return
-    url = message.text.split(None, 1)[1]
-    m = await message.reply_text("**Taking Screenshot**")
-    await m.edit("**Uploading**")
     try:
-        await app.send_photo(
-            message.chat.id,
-            photo=f"https://webshot.amanoteam.com/print?q={url}",
-            )
-    except TypeError:
-        await m.edit("No Such Website.")
-        return
-    await m.delete()
+        if len(message.command) != 2:
+            await message.reply_text("Give A Url To Fetch Screenshot.")
+            return
+        url = message.text.split(None, 1)[1]
+        m = await message.reply_text("**Taking Screenshot**")
+        await m.edit("**Uploading**")
+        try:
+            await app.send_photo(
+                message.chat.id,
+                photo=f"https://webshot.amanoteam.com/print?q={url}",
+                )
+        except TypeError:
+            await m.edit("No Such Website.")
+            return
+        await m.delete()
+    except Exception as e:
+        await message.reply_text(str(e))

+ 1 - 0
wbb/utils/filter_groups.py

@@ -28,3 +28,4 @@ karma_negative_group = 4
 regex_group = 5
 welcome_captcha_group = 6
 antiflood_group = 7
+nsfw_detect_group = 8

+ 1 - 1
wbb/utils/inlinefuncs.py

@@ -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), 2))} Seconds"
+    ping = f"{str(round((t2 - t1), 4))} Seconds"
     answers.append(
         InlineQueryResultArticle(
             title=ping,