Selaa lähdekoodia

Added service message delete system (#59)

* Create antiservice.py

* Updated AntiServiceSystem

Added Dedicated Database functions

* [dbfunctions]-AntiServiceSystem

Added DB functions for AntiService
sᴡᴏɴɪᴛ 5 vuotta sitten
vanhempi
sitoutus
bee003dd71
2 muutettua tiedostoa jossa 71 lisäystä ja 0 poistoa
  1. 48 0
      wbb/modules/antiservice.py
  2. 23 0
      wbb/utils/dbfunctions.py

+ 48 - 0
wbb/modules/antiservice.py

@@ -0,0 +1,48 @@
+# Written By [MaskedVirus | swatv3nub] for William and Ryūga
+# Kang With Proper Credits
+
+from wbb import app
+from pyrogram import filters
+from wbb.modules.admin import member_permissions
+from wbb.utils.dbfunctions import is_antiservice_on, antiservice_on, antiservice_off
+
+__MODULE__ = "AntiService"
+__HELP__ = f"""
+Plugin to delete antiservice messages in a chat!
+
+/antiservice [enable|disable]
+"""
+
+@app.on_message(filters.command("antiservice") & ~filters.private)
+async def anti_service(_, message):
+    if len(message.command) != 2:
+        await message.reply_text("Usage: /antiservice [enable | disable]")
+        return
+    status = message.text.split(None, 1)[1].strip()
+    status = status.lower()
+    chat_id = message.chat.id
+    user_id = message.from_user.id
+    permissions = await member_permissions(chat_id, user_id)
+    if "can_change_info" not in permissions:
+        await message.reply_text("You don't have enough permissions.")
+        return
+    if status == "enable":
+        await antiservice_on(chat_id)
+        await message.reply_text("Enabled AntiService System. I will Delete Service Messages from Now on.")
+    elif status == "disable":
+        await antiservice_off(chat_id)
+        await message.reply_text("Disabled AntiService System. I won't Be Deleting Service Message from Now on.")
+    else:
+        await message.reply_text("Unknown Suffix, Use /antiservice [enable|disable]")
+
+
+
+@app.on_message(filters.service, group=11)
+async def delete_service(_, message):
+    chat_id = message.chat.id
+    try:
+        if await is_antiservice_on(chat_id):
+            await message.delete()
+            return
+    except:
+        pass

+ 23 - 0
wbb/utils/dbfunctions.py

@@ -10,6 +10,7 @@ chatsdb = db.chats
 gbansdb = db.gban
 coupledb = db.couple
 captchadb = db.captcha
+antiservicedb = db.antiservice
 
 """ Notes functions """
 
@@ -422,3 +423,25 @@ async def captcha_off(chat_id: int):
     if not is_captcha:
         return
     return await captchadb.insert_one({"chat_id": chat_id})
+
+"""Anti Service System"""
+
+async def is_antiservice_on(chat_id: int) -> bool:
+    chat = await antiservicedb.find_one({"chat_id": chat_id})
+    if not chat:
+        return True
+    return False
+
+
+async def antiservice_on(chat_id: int):
+    is_antiservice = await is_antiservice_on(chat_id)
+    if is_antiservice:
+        return
+    return await antiservicedb.delete_one({"chat_id": chat_id})
+
+
+async def antiservice_off(chat_id: int):
+    is_antiservice = await is_antiservice_on(chat_id)
+    if not is_antiservice:
+        return
+    return await antiservicedb.insert_one({"chat_id": chat_id})