File size: 2,989 Bytes
78b07ad
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import re

from pyrogram import Client, filters
from pyrogram.types import Message

from Hellbot.core import Config, Symbols
from Hellbot.functions.utility import BList

from . import HelpMenu, custom_handler, db, hellbot, on_message


@on_message("blacklist", admin_only=True, allow_stan=True)
async def blacklist(client: Client, message: Message):
    if len(message.command) < 2:
        return await hellbot.delete(message, "Give me something to blacklist.")

    text = await hellbot.input(message)

    if await db.is_blacklist(client.me.id, message.chat.id, text):
        return await hellbot.delete(message, f"**Already blacklisted** `{text}`")

    await BList.addBlacklist(client.me.id, message.chat.id, text)
    await hellbot.delete(message, f"**Blacklisted:** `{text}`")


@on_message("unblacklist", admin_only=True, allow_stan=True)
async def unblacklist(client: Client, message: Message):
    if len(message.command) < 2:
        return await hellbot.delete(message, "Give me something to unblacklist.")

    text = await hellbot.input(message)

    if not await db.is_blacklist(client.me.id, message.chat.id, text):
        return await hellbot.delete(message, f"`{text}` does not exist in blacklist.")

    await BList.rmBlacklist(client.me.id, message.chat.id, text)
    await hellbot.delete(message, f"**Unblacklisted:** `{text}`")


@on_message("blacklists", admin_only=True, allow_stan=True)
async def blacklists(client: Client, message: Message):
    blacklists = await db.get_all_blacklists(client.me.id, message.chat.id)

    if not blacklists:
        return await hellbot.delete(message, "No blacklists found.")

    text = f"**{Symbols.bullet} π–‘π—…π–Ίπ–Όπ—„π—…π—‚π—Œπ—π—Œ 𝗂𝗇 {message.chat.title}:**\n\n"
    for i in blacklists:
        text += f"    {Symbols.anchor} `{i}`\n"

    await hellbot.edit(message, text)


@custom_handler(filters.text & filters.incoming & ~Config.AUTH_USERS & ~filters.service)
async def handle_blacklists(client: Client, message: Message):
    if BList.check_client_chat(client.me.id, message.chat.id):
        blacklists = BList.getBlacklists(client.me.id, message.chat.id)
        for blacklist in blacklists:
            pattern = r"( |^|[^\w])" + re.escape(blacklist) + r"( |$|[^\w])"
            if re.search(pattern, message.text, flags=re.IGNORECASE):
                try:
                    await message.delete()
                except Exception:
                    await BList.rmBlacklist(client.me.id, message.chat.id, blacklist)


HelpMenu("blacklist").add(
    "blacklist",
    "<text>",
    "Add the text to blacklist. If the text is sent in the chat it will be deleted.",
    "blacklist hello",
).add(
    "unblacklist", "<text>", "Remove the text from blacklist.", "unblacklist hello"
).add(
    "blacklists", None, "List all the blacklisted words in the chat.", "blacklists"
).info(
    "Blacklist Module"
).done()