Quellcode durchsuchen

Removed NSFW+Spam prediction

TheHamkerCat vor 5 Jahren
Ursprung
Commit
69366fa9d8

+ 0 - 4
app.json

@@ -75,10 +75,6 @@
             "description": "Userbot command prefix, Leave it empty if you don't know what that is.",
             "required": false
         },
-        "SPAM_CHECK_EXCEPTION_GROUPS": {
-            "description": "Groups where spam scans shouldn't happen, leave it empty if you don't know what that is",
-            "required": false
-        },
         "RSS_DELAY": {
             "description": "Delay in which RSS will send updates in chat",
             "value": 300,

+ 0 - 9
sample_config.py

@@ -30,12 +30,6 @@ if HEROKU:
     LOG_MENTIONS = (
         True if int(environ.get("LOG_MENTIONS", None)) == 1 else False
     )
-    SPAM_CHECK_EXCEPTION_GROUPS = list(
-        int(y)
-        for y in environ.get(
-            "SPAM_CHECK_EXCEPTION_GROUPS", ""
-        ).split()
-    )
     RSS_DELAY = int(environ.get("RSS_DELAY", None))
 else:
     BOT_TOKEN = "467677575:YZfaakjwd545dfg-N6JStihhuw5gQeZHntc"
@@ -56,7 +50,4 @@ else:
     ARQ_API_KEY = "Get this from @ARQRobot"
     ARQ_API_URL = "https://thearq.tech"
     LOG_MENTIONS = True
-    SPAM_CHECK_EXCEPTION_GROUPS = (
-        []
-    )  # Leave it empty if you don't know about it
     RSS_DELAY = 300  # In seconds

+ 2 - 5
wbb/__main__.py

@@ -173,13 +173,10 @@ async def help_parser(name, keyboard=None):
         )
     return (
         """Hello {first_name}! My name is {bot_name}!
-I'm a group management bot with some usefule features.
+I'm a group management bot with some useful features.
 You can choose an option below, by clicking a button.
 Also you can ask anything in Support Group.
-
-General command are:
- - /start: Start the bot
- - /help: Give this message""".format(
+""".format(
             first_name=name,
             bot_name=BOT_NAME,
         ),

+ 0 - 17
wbb/core/filters.py

@@ -26,7 +26,6 @@ from pyrogram.types import Message
 
 from wbb import SUDOERS
 from wbb import USERBOT_ID as OWNER_ID
-from wbb.modules.trust import get_spam_data
 from wbb.utils.functions import get_urls_from_text
 
 
@@ -43,13 +42,6 @@ def url(_, __, message: Message) -> bool:
     return bool(get_urls_from_text(text))
 
 
-async def spam(_, __, message: Message) -> bool:
-    text = message.text or message.caption
-    if not text:
-        return False
-    return (await get_spam_data(message, text)).is_spam
-
-
 async def admin(_, __, message: Message) -> bool:
     if message.chat.type not in ["group", "supergroup"]:
         return False
@@ -72,13 +64,6 @@ def entities(_, __, message: Message) -> bool:
     return bool(message.entities)
 
 
-async def profanity(_, __, message: Message) -> bool:
-    text = message.text or message.caption
-    if not text:
-        return False
-    return (await get_spam_data(message, text)).profanity
-
-
 def anonymous(_, __, message: Message) -> bool:
     return bool(message.sender_chat)
 
@@ -101,10 +86,8 @@ class Filters:
 
 filters = Filters
 filters.url = filters_.create(url)
-filters.spam = filters_.create(spam)
 filters.admin = filters_.create(admin)
 filters.entities = filters_.create(entities)
-filters.profanity = filters_.create(profanity)
 filters.anonymous = filters_.create(anonymous)
 filters.sudoers = filters_.create(sudoers)
 filters.owner = filters_.create(owner)

+ 0 - 18
wbb/modules/info.py

@@ -28,7 +28,6 @@ from pyrogram.types import Message
 
 from wbb import SUDOERS, app
 from wbb.core.decorators.errors import capture_err
-from wbb.modules.trust import get_spam_probability
 from wbb.utils.dbfunctions import is_gbanned_user, user_global_karma
 
 __MODULE__ = "Info"
@@ -51,19 +50,6 @@ async def get_user_info(user):
     is_gbanned = await is_gbanned_user(user_id)
     is_sudo = user_id in SUDOERS
     karma = await user_global_karma(user_id)
-    spam_probab, n_messages = await get_spam_probability(user_id)
-    isSpammer = (
-        True
-        if spam_probab > 50
-        else False
-        if spam_probab != 0
-        else "Uncertain"
-    )
-    spam_probab = (
-        str(round(spam_probab)) + " %"
-        if spam_probab != 0
-        else "Uncertain"
-    )
     caption = f"""
 **ID:** `{user_id}`
 **DC:** {dc_id}
@@ -73,10 +59,6 @@ async def get_user_info(user):
 **Sudo:** {is_sudo}
 **Karma:** {karma}
 **Gbanned:** {is_gbanned}
-**ARQ Spam Detection:**
-    **Spammer:** {isSpammer}
-    **Spam Probability:** {spam_probab}
-    __Stats Of Last {n_messages} Messages.__
 """
     return [caption, photo_id]
 

+ 0 - 170
wbb/modules/nsfw.py

@@ -1,170 +0,0 @@
-from os import remove
-
-from pyrogram import filters
-
-from wbb import app, arq
-from wbb.core.decorators.errors import capture_err
-from wbb.core.decorators.permissions import adminsOnly
-from wbb.utils.dbfunctions import is_nsfw_on, nsfw_off, nsfw_on
-from wbb.utils.filter_groups import nsfw_detect_group
-
-__MODULE__ = "NSFW"
-__HELP__ = """
-/nsfw_scan - Manually Scan An Image/Sticker/Document.
-/anti_nsfw [ENABLE | DISABLE] - Turn This Module On/Off
-"""
-
-
-async def get_file_id_from_message(message):
-    file_id = None
-    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
-        file_id = message.document.file_id
-
-    if message.sticker:
-        if message.sticker.is_animated:
-            if not message.sticker.thumbs:
-                return
-            file_id = message.sticker.thumbs[0].file_id
-        else:
-            file_id = message.sticker.file_id
-
-    if message.photo:
-        file_id = message.photo.file_id
-
-    if message.animation:
-        if not message.animation.thumbs:
-            return
-        file_id = message.animation.thumbs[0].file_id
-
-    if message.video:
-        if not message.video.thumbs:
-            return
-        file_id = message.video.thumbs[0].file_id
-    return file_id
-
-
-@app.on_message(
-    (
-        filters.document
-        | filters.photo
-        | filters.sticker
-        | filters.animation
-        | filters.video
-    )
-    & ~filters.private,
-    group=nsfw_detect_group,
-)
-@capture_err
-async def detect_nsfw(_, message):
-    if not await is_nsfw_on(message.chat.id):
-        return
-    if not message.from_user:
-        return
-    file_id = await get_file_id_from_message(message)
-    if not file_id:
-        return
-    file = await app.download_media(file_id)
-    try:
-        results = await arq.nsfw_scan(file=file)
-    except Exception:
-        return
-    if not results.ok:
-        return
-    results = results.result
-    remove(file)
-    nsfw = results.is_nsfw
-    if not nsfw:
-        return
-    try:
-        await message.delete()
-    except Exception:
-        return
-    await message.reply_text(
-        f"""
-**NSFW Image Detected & Deleted Successfully!
-————————————————————————**
-**User:** {message.from_user.mention} [`{message.from_user.id}`]
-**Safe:** `{results.neutral} %`
-**Porn:** `{results.porn} %`
-**Adult:** `{results.sexy} %`
-**Hentai:** `{results.hentai} %`
-**Drawings:** `{results.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/document/sticker/animation to scan 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 scan it."
-        )
-        return
-    m = await message.reply_text("Scanning")
-    file_id = await get_file_id_from_message(reply)
-    if not file_id:
-        return await m.edit("Something wrong happened.")
-    file = await app.download_media(file_id)
-    try:
-        results = await arq.nsfw_scan(file=file)
-    except Exception as e:
-        return await m.edit(str(e))
-    remove(file)
-    if not results.ok:
-        return await m.edit(results.result)
-    results = results.result
-    await m.edit(
-        f"""
-**Neutral:** `{results.neutral} %`
-**Porn:** `{results.porn} %`
-**Hentai:** `{results.hentai} %`
-**Sexy:** `{results.sexy} %`
-**Drawings:** `{results.drawings} %`
-**NSFW:** `{results.is_nsfw}`
-"""
-    )
-
-
-@app.on_message(filters.command("anti_nsfw") & ~filters.private)
-@adminsOnly("can_change_info")
-async def nsfw_enable_disable(_, message):
-    if len(message.command) != 2:
-        await message.reply_text(
-            "Usage: /anti_nsfw [enable | disable]"
-        )
-        return
-    status = message.text.split(None, 1)[1].strip()
-    status = status.lower()
-    chat_id = message.chat.id
-    if status == "enable":
-        await nsfw_on(chat_id)
-        await message.reply_text(
-            "Enabled AntiNSFW System. I will Delete Messages Containing Inappropriate Content."
-        )
-    elif status == "disable":
-        await nsfw_off(chat_id)
-        await message.reply_text("Disabled AntiNSFW System.")
-    else:
-        await message.reply_text(
-            "Unknown Suffix, Use /anti_nsfw [enable|disable]"
-        )

+ 1 - 1
wbb/modules/rss.py

@@ -46,7 +46,7 @@ async def rss_worker():
                 )
                 await update_rss_feed(chat, feed.title)
             except Exception as e:
-                print(str(e), "RSS")
+                print(str(e), f"RSS {chat}")
                 pass
         t2 = time()
         if (t2 - t1) >= RSS_DELAY:

+ 0 - 234
wbb/modules/spam.py

@@ -1,234 +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 pyrogram.types import (CallbackQuery, InlineKeyboardButton,
-                            InlineKeyboardMarkup, Message)
-
-from wbb import LOG_GROUP_ID, SUDOERS, USERBOT_PREFIX, app, app2, arq
-from wbb.core.decorators.permissions import adminsOnly
-from wbb.modules.admin import list_admins, member_permissions
-from wbb.modules.trust import get_spam_data
-from wbb.modules.userbot import edit_or_reply
-from wbb.utils.dbfunctions import (is_spam_detection_on,
-                                   spam_detection_off,
-                                   spam_detection_on)
-from wbb.utils.filter_groups import spam_protection_group
-
-__MODULE__ = "AntiSpam"
-__HELP__ = """
-**Antispam helps protect your group from spam.**
-
-- It's still new so it might be a bit inaccurate.
-
-- Currently, it only alerts for spam and gives you a button to delete the message,
-  but in the future, it will delete the spam message automatically.
-
-**Commands:**
-    - /spam
-        To mark a message as spam, this will help devs to
-        improve spam protection algorithm.
-
-    - /spam_detection [ENABLE|DISABLE]
-        To turn off spam detection in your chat.
-
-**Plot Twist:** NO, WE'RE NOT USING INTELLIVOID'S SPAM DETECTION API!
-"""
-
-
-@app.on_message(
-    (filters.text | filters.caption) & ~filters.private & ~filters.me,
-    group=spam_protection_group,
-)
-async def spam_protection_func(_, message: Message):
-    text = message.text or message.caption
-    chat_id = message.chat.id
-    user = message.from_user
-    if not text or not user:
-        return
-
-    # We'll handle admins only if it's spam, ignore only sudo users for now.
-    if user.id in SUDOERS:
-        return
-    enabled = await is_spam_detection_on(chat_id)
-    if not enabled:
-        return
-    data = await get_spam_data(message, text)
-    if isinstance(data, str):
-        return
-    if not data.is_spam:
-        return
-    if user.id in (await list_admins(chat_id)):
-        return
-    text = f"""
-🚨  **SPAM DETECTED**  🚨
-
-**User:** {user.mention}
-**Message:** [Link]({message.link})
-**Spam Probability:** {data.spam_probability} %
-**Action:** Alerted
-"""
-    keyboard = InlineKeyboardMarkup(
-        [
-            [
-                InlineKeyboardButton(
-                    text="Yes it's spam", callback_data="s_p_spam"
-                ),
-                InlineKeyboardButton(
-                    text="No, it's not spam",
-                    callback_data="s_p_ham",
-                ),
-            ],
-        ]
-    )
-    await message.reply_text(
-        text=text,
-        reply_markup=keyboard,
-        disable_web_page_preview=True,
-    )
-
-
-dev_forward = (
-    "If you're not a developer of WBB, forward this message to devs, "
-    + "so that they can use it to improve spam protection algorithm."
-)
-
-
-@app.on_callback_query(filters.regex("s_p_"))
-async def spam_p_callback(_, cq: CallbackQuery):
-    from_user = cq.from_user
-    chat_id = cq.message.chat.id
-
-    permissions = await member_permissions(chat_id, from_user.id)
-    permission = "can_delete_messages"
-    if permission not in permissions:
-        return await cq.answer(
-            "You don't have enough permissions to perform this action.\n"
-            + f"Permission needed: {permission}",
-            show_alert=True,
-        )
-
-    if cq.data.split("_")[-1] == "spam":
-        try:
-            await cq.message.reply_to_message.delete()
-        except Exception:
-            await cq.message.delete()
-            return
-        text = cq.message.text.markdown
-        text = text.replace(
-            "Alerted",
-            f"Deleted Message With {from_user.mention}'s Approval.",
-        )
-        return await cq.message.edit(text)
-
-    await cq.message.delete()
-    if cq.message.reply_to_message:
-        text = f"**ADMINS OF {chat_id} FLAGGED THIS MESSAGE AS NOT SPAM**\n\n"
-        text += f"`{cq.message.reply_to_message.text.markdown}`\n\n__{dev_forward}__"
-        return await app.send_message(
-            LOG_GROUP_ID, text, disable_web_page_preview=True
-        )
-
-
-@app.on_message(filters.command("spam") & ~filters.private)
-async def spam_flag_func(_, message: Message):
-    if not message.reply_to_message:
-        return await message.reply_text(
-            "Reply to a message to flag it as spam"
-        )
-
-    r = message.reply_to_message
-    if not r.text and not r.caption:
-        return await message.reply_text(
-            "Reply to a text message to flag it as spam"
-        )
-
-    text = r.text or r.caption
-    if not text:
-        return await message.reply_text(
-            "Reply to a text message to flag it as spam"
-        )
-
-    msg = f"""
-**ADMINS OF {message.chat.id} FLAGGED THIS MESSAGE AS SPAM. [Suggestion]**
-
-```
-{text.markdown}
-```
-
-__{dev_forward}__
-"""
-    await message.reply_text(
-        "Message was flagged as spam, Devs will use it to improve spam protection algorithm."
-    )
-    await app.send_message(
-        LOG_GROUP_ID, msg, disable_web_page_preview=True
-    )
-
-
-@app.on_message(filters.command("spam_detection") & ~filters.private)
-@adminsOnly("can_change_info")
-async def spam_toggle(_, message: Message):
-    if len(message.command) != 2:
-        return await message.reply_text(
-            "Usage: /spam_detection [ENABLE|DISABLE]"
-        )
-    status = message.text.split(None, 1)[1].strip()
-    status = status.lower()
-    chat_id = message.chat.id
-    if status == "enable":
-        await spam_detection_on(chat_id)
-        await message.reply_text("Enabled Spam Detection System.")
-    elif status == "disable":
-        await spam_detection_off(chat_id)
-        await message.reply_text("Disabled Spam Detection System.")
-    else:
-        await message.reply_text(
-            "Unknown Suffix, Use /spam_detection [ENABLE|DISABLE]"
-        )
-
-
-@app.on_message(filters.command("spam_scan"))
-@app2.on_message(
-    filters.command("spam_scan", prefixes=USERBOT_PREFIX)
-    & filters.user(SUDOERS)
-)
-async def scanNLP(_, message: Message):
-    if not message.reply_to_message:
-        return await edit_or_reply(
-            message, text="Reply to a message to scan it."
-        )
-    r = message.reply_to_message
-    text = r.text or r.caption
-    if not text:
-        return await edit_or_reply(message, text="Can't scan that")
-    data = await arq.nlp(text)
-    data = data.result[0]
-    msg = f"""
-**Is Spam:** {data.is_spam}
-**Spam Probability:** {data.spam_probability} %
-**Spam:** {data.spam}
-**Ham:** {data.ham}
-**Profanity:** {data.profanity}
-"""
-    await edit_or_reply(message, text=msg)

+ 0 - 91
wbb/modules/trust.py

@@ -1,91 +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 asyncio import Lock
-
-from pyrogram import filters
-from pyrogram.types import Message
-
-from wbb import (BOT_ID, MESSAGE_DUMP_CHAT, USERBOT_BOT_CHAT_COMMON,
-                 app, app2, arq)
-from wbb.utils.dbfunctions import get_trust_db, update_trust_db
-from wbb.utils.filter_groups import trust_group
-
-spam_db = {}
-
-lock_access = Lock()
-
-
-async def get_spam_data(message: Message, text: str):
-    async with lock_access:
-        c, m = message.chat.id, message.message_id
-        if c not in spam_db:
-            spam_db[c] = {}
-        if m not in spam_db[c]:
-            data = (await arq.nlp(text)).result[0]
-            spam_db[c][m] = data
-        return spam_db[c][m]
-
-
-@app2.on_message(
-    (filters.text | filters.caption)
-    & ~filters.chat(BOT_ID)
-    & ~filters.chat(USERBOT_BOT_CHAT_COMMON)
-    & ~filters.me,
-    group=trust_group,
-)
-@app.on_message(
-    (filters.text | filters.caption)
-    & ~filters.chat(MESSAGE_DUMP_CHAT)
-    & ~filters.me
-    & ~filters.private,
-    group=trust_group,
-)
-async def trust_watcher_func(_, message: Message):
-    # Sleeping so that we can get cached data created by
-    # spam.py with get_spam_data function
-    if message.command:
-        return
-    if not message.from_user:
-        return
-    user_id = message.from_user.id
-    text = message.text or message.caption
-    text = text.strip()
-    if not text:
-        return
-    if len(text) < 2:
-        return
-    data = await get_spam_data(message, text)
-    if isinstance(data, str):
-        return
-    spam = data.spam
-    await update_trust_db(user_id, spam)
-
-
-async def get_spam_probability(user_id) -> list:
-    data = await get_trust_db(user_id)
-    if not data:
-        return [0, 0]
-    mean = lambda x: sum(x) / len(x)
-    spam = [i for i in data]
-    return [mean(spam), len(spam)]

+ 0 - 51
wbb/utils/dbfunctions.py

@@ -52,9 +52,7 @@ pipesdb = db.pipes
 sudoersdb = db.sudoers
 blacklist_chatdb = db.blacklistChat
 restart_stagedb = db.restart_stage
-trustdb = db.trust
 flood_toggle_db = db.flood_toggle
-spam_toggle_db = db.spam_toggle
 rssdb = db.rss
 
 """ Notes functions """
@@ -774,55 +772,6 @@ async def clean_restart_stage() -> dict:
     }
 
 
-""" TRUST DB """
-
-
-async def get_trust_db(user_id: int) -> list:
-    user = await trustdb.find_one({"user_id": user_id})
-    if not user:
-        return []
-    return user["data"]
-
-
-async def update_trust_db(user_id: int, new_data: float):
-    user = await trustdb.find_one({"user_id": user_id})
-    data = user["data"] if user else []
-    if len(data) >= 100:
-        data = data[1:100]
-    data.append(new_data)
-    data = [
-        i for i in data if isinstance(i, float) or isinstance(i, int)
-    ]
-    await trustdb.update_one(
-        {"user_id": user_id},
-        {"$set": {"data": data}},
-        upsert=True,
-    )
-
-
-"""SPAM DETECTION System"""
-
-
-async def is_spam_detection_on(chat_id: int) -> bool:
-    chat = await spam_toggle_db.find_one({"chat_id": chat_id})
-    if not chat:
-        return True
-    return False
-
-
-async def spam_detection_on(chat_id: int):
-    is_on = await is_spam_detection_on(chat_id)
-    if is_on:
-        return
-    return await spam_toggle_db.delete_one({"chat_id": chat_id})
-
-
-async def spam_detection_off(chat_id: int):
-    is_on = await is_spam_detection_on(chat_id)
-    if not is_on:
-        return
-    return await spam_toggle_db.insert_one({"chat_id": chat_id})
-
 
 """FLOOD System"""
 

+ 2 - 4
wbb/utils/filter_groups.py

@@ -33,7 +33,5 @@ blacklist_filters_group = 9
 pipes_group = 10
 taglog_group = 11
 chat_watcher_group = 12
-trust_group = 13
-flood_group = 14
-spam_protection_group = 15
-autocorrect_group = 16
+flood_group = 13
+autocorrect_group = 14