Karma
commited on
Commit
·
f3c7238
1
Parent(s):
fc256ee
Create blacklist.py
Browse files- Mikobot/plugins/blacklist.py +112 -0
Mikobot/plugins/blacklist.py
ADDED
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# <============================================== IMPORTS =========================================================>
|
2 |
+
import re
|
3 |
+
from datetime import datetime, timedelta
|
4 |
+
|
5 |
+
from pyrogram import filters
|
6 |
+
from pyrogram.types import ChatPermissions
|
7 |
+
|
8 |
+
from Database.mongodb.blacklistdb import (
|
9 |
+
delete_blacklist_filter,
|
10 |
+
get_blacklisted_words,
|
11 |
+
save_blacklist_filter,
|
12 |
+
)
|
13 |
+
from Mikobot import DRAGONS, app
|
14 |
+
from Mikobot.utils.errors import capture_err
|
15 |
+
from Mikobot.utils.permissions import adminsOnly, list_admins
|
16 |
+
|
17 |
+
# <=======================================================================================================>
|
18 |
+
|
19 |
+
blacklist_filters_group = 8
|
20 |
+
|
21 |
+
|
22 |
+
# <================================================ FUNCTION =======================================================>
|
23 |
+
@app.on_message(filters.command("blacklist") & ~filters.private)
|
24 |
+
@adminsOnly("can_restrict_members")
|
25 |
+
async def save_filters(_, message):
|
26 |
+
if len(message.command) < 2:
|
27 |
+
return await message.reply_text("Usage:\n/blacklist [WORD|SENTENCE]")
|
28 |
+
word = message.text.split(None, 1)[1].strip()
|
29 |
+
if not word:
|
30 |
+
return await message.reply_text("**Usage**\n__/blacklist [WORD|SENTENCE]__")
|
31 |
+
chat_id = message.chat.id
|
32 |
+
await save_blacklist_filter(chat_id, word)
|
33 |
+
await message.reply_text(f"__**Blacklisted {word}.**__")
|
34 |
+
|
35 |
+
|
36 |
+
@app.on_message(filters.command("blacklisted") & ~filters.private)
|
37 |
+
@capture_err
|
38 |
+
async def get_filterss(_, message):
|
39 |
+
data = await get_blacklisted_words(message.chat.id)
|
40 |
+
if not data:
|
41 |
+
await message.reply_text("**No blacklisted words in this chat.**")
|
42 |
+
else:
|
43 |
+
msg = f"List of blacklisted words in {message.chat.title} :\n"
|
44 |
+
for word in data:
|
45 |
+
msg += f"**-** `{word}`\n"
|
46 |
+
await message.reply_text(msg)
|
47 |
+
|
48 |
+
|
49 |
+
@app.on_message(filters.command("whitelist") & ~filters.private)
|
50 |
+
@adminsOnly("can_restrict_members")
|
51 |
+
async def del_filter(_, message):
|
52 |
+
if len(message.command) < 2:
|
53 |
+
return await message.reply_text("Usage:\n/whitelist [WORD|SENTENCE]")
|
54 |
+
word = message.text.split(None, 1)[1].strip()
|
55 |
+
if not word:
|
56 |
+
return await message.reply_text("Usage:\n/whitelist [WORD|SENTENCE]")
|
57 |
+
chat_id = message.chat.id
|
58 |
+
deleted = await delete_blacklist_filter(chat_id, word)
|
59 |
+
if deleted:
|
60 |
+
return await message.reply_text(f"**Whitelisted {word}.**")
|
61 |
+
await message.reply_text("**No such blacklist filter.**")
|
62 |
+
|
63 |
+
|
64 |
+
@app.on_message(filters.text & ~filters.private, group=blacklist_filters_group)
|
65 |
+
@capture_err
|
66 |
+
async def blacklist_filters_re(_, message):
|
67 |
+
text = message.text.lower().strip()
|
68 |
+
if not text:
|
69 |
+
return
|
70 |
+
chat_id = message.chat.id
|
71 |
+
user = message.from_user
|
72 |
+
if not user:
|
73 |
+
return
|
74 |
+
if user.id in DRAGONS:
|
75 |
+
return
|
76 |
+
list_of_filters = await get_blacklisted_words(chat_id)
|
77 |
+
for word in list_of_filters:
|
78 |
+
pattern = r"( |^|[^\w])" + re.escape(word) + r"( |$|[^\w])"
|
79 |
+
if re.search(pattern, text, flags=re.IGNORECASE):
|
80 |
+
if user.id in await list_admins(chat_id):
|
81 |
+
return
|
82 |
+
try:
|
83 |
+
await message.delete()
|
84 |
+
await message.chat.restrict_member(
|
85 |
+
user.id,
|
86 |
+
ChatPermissions(),
|
87 |
+
until_date=datetime.now() + timedelta(minutes=60),
|
88 |
+
)
|
89 |
+
except Exception:
|
90 |
+
return
|
91 |
+
return await app.send_message(
|
92 |
+
chat_id,
|
93 |
+
f"Muted {user.mention} [`{user.id}`] for 1 hour "
|
94 |
+
+ f"due to a blacklist match on {word}.",
|
95 |
+
)
|
96 |
+
|
97 |
+
|
98 |
+
# <=================================================== HELP ====================================================>
|
99 |
+
|
100 |
+
|
101 |
+
__help__ = """
|
102 |
+
❌ *Get your word/sentence blacklisted*
|
103 |
+
|
104 |
+
» /blacklisted - Get All The Blacklisted Words In The Chat.
|
105 |
+
|
106 |
+
» /blacklist [WORD|SENTENCE] - Blacklist A Word Or A Sentence.
|
107 |
+
|
108 |
+
» /whitelist [WORD|SENTENCE] - Whitelist A Word Or A Sentence.
|
109 |
+
"""
|
110 |
+
|
111 |
+
__mod_name__ = "BLACKLIST"
|
112 |
+
# <================================================ END =======================================================>
|