TheHamkerCat 5 vuotta sitten
vanhempi
sitoutus
39b02f2008
4 muutettua tiedostoa jossa 110 lisäystä ja 0 poistoa
  1. 80 0
      wbb/modules/antiflood.py
  2. 4 0
      wbb/modules/greetings.py
  3. 25 0
      wbb/utils/dbfunctions.py
  4. 1 0
      wbb/utils/filter_groups.py

+ 80 - 0
wbb/modules/antiflood.py

@@ -0,0 +1,80 @@
+from wbb import app
+from wbb.utils.filter_groups import antiflood_group
+from wbb.utils.errors import capture_err
+from wbb.utils.dbfunctions import (
+    is_antiflood_on,
+    antiflood_on,
+    antiflood_off
+)
+from wbb.modules.admin import list_admins, member_permissions
+from pyrogram import filters
+
+tdb = []
+
+
+@app.on_message(group=antiflood_group)
+async def antiflood_check(_, message):
+    global tdb
+    if not is_antiflood_on:
+        return
+    chat_id = message.chat.id
+    user_id = message.from_user.id
+    admins = await list_admins(chat_id)
+
+    # ignore admins
+    if user_id in admins:
+        return
+    for chat in tdb:
+        if chat['chat_id'] == chat_id:
+            for user in chat['user_ids']:
+                if user == user_id:
+                    chat['user_ids'][user]['messages'] == \
+                        ((chat['user_ids'][user]['messages'] + 1)) \
+                        if chat['user_ids'][user]['messages'] else 1
+                    if chat['user_ids'][user]['messages'] > 7:
+                        await message.chat.restrict_member(
+                            user_id,
+                            permissions=ChatPermissions()
+                        )
+                        await message.reply_text(f"Yeah i don't like spam, Muted!")
+                        return
+
+    if not tdb:
+        tdb.append(
+            {
+                "chat_id": chat_id,
+                "user_ids": [
+                    {
+                        user_id: {
+                            "messages": 1
+                        }
+                    }
+                ]
+            }
+        )
+        return
+
+
+@app.on_message(filters.command("flood"))
+@capture_err
+async def captcha_state(_, message):
+    usage = "**Usage:**\n/flood [ON|OFF]"
+    if len(message.command) != 2:
+        await message.reply_text(usage)
+        return
+    user_id = message.from_user.id
+    chat_id = message.chat.id
+    permissions = await member_permissions(chat_id, user_id)
+    if "can_restrict_members" not in permissions:
+        await message.reply_text("You don't have enough permissions.")
+        return
+    state = message.text.split(None, 1)[1].strip()
+    state = state.lower()
+    if state == "on":
+        await antiflood_on(chat_id)
+        await message.reply_text("Muting members on 7 consecutive messages.")
+    elif state == "off":
+        await antiflood_off(chat_id)
+        await message.reply_text("Disabled Antiflood")
+    else:
+        await message.reply_text(usage)

+ 4 - 0
wbb/modules/greetings.py

@@ -21,6 +21,9 @@ from pyrogram import filters
 from random import randint, shuffle
 from datetime import datetime
 
+__MODULE__ = "Captcha"
+__HELP__ = "/captcha [ON|OFF] - Enable/Disable Captcha."
+
 
 @app.on_message(filters.new_chat_members, group=welcome_captcha_group)
 @capture_err
@@ -153,6 +156,7 @@ async def _ban_restricted_user_until_date(group_chat,
 
 
 @app.on_message(filters.command("captcha"))
+@capture_err
 async def captcha_state(_, message):
     usage = "**Usage:**\n/captcha [ON|OFF]"
     if len(message.command) != 2:

+ 25 - 0
wbb/utils/dbfunctions.py

@@ -10,6 +10,7 @@ chatsdb = db.chats
 gbansdb = db.gban
 coupledb = db.couple
 captchadb = db.captcha
+antiflooddb = db.antiflood
 
 """ Notes functions """
 
@@ -402,6 +403,7 @@ async def save_couple(chat_id: int, date: str, couple: dict):
 
 # Captcha
 
+
 async def is_captcha_on(chat_id: int) -> bool:
     chat = await captchadb.find_one({"chat_id": chat_id})
     if not chat:
@@ -422,3 +424,26 @@ async def captcha_off(chat_id: int):
         return
     return await captchadb.insert_one({"chat_id": chat_id})
 
+
+# antiflood
+
+
+async def is_antiflood_on(chat_id: int) -> bool:
+    chat = await antiflooddb.find_one({"chat_id": chat_id})
+    if not chat:
+        return True
+    return False
+
+
+async def antiflood_on(chat_id: int):
+    is_antiflood = await is_antiflood_on(chat_id)
+    if is_antiflood:
+        return
+    return await antiflooddb.delete_one({"chat_id": chat_id})
+
+
+async def antiflood_off(chat_id: int):
+    is_antiflood = await is_antiflood_on(chat_id)
+    if not is_captcha:
+        return
+    return await antiflooddb.insert_one({"chat_id": chat_id})

+ 1 - 0
wbb/utils/filter_groups.py

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