/
vulgar.py
63 lines (49 loc) · 1.76 KB
/
vulgar.py
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
import asyncio
import re
from pyrogram import filters
from pyrogram.errors import MessageNotModified
from pyrogram.types import Message
from userbot import LOGS, UserBot
from userbot.plugins.help import add_command_help
bad_words = ["nigga", "nigger", "coon", "retard", "cock", "kiss"]
good_words = ["black person", "black person", "bruh", "50...40...30...20...RETARD...RETARD", "coke", "keys"]
vulgar_filter = True
def switch():
global vulgar_filter
vulgar_filter = not vulgar_filter
return vulgar_filter
@UserBot.on_message(filters.command("vulgar", ".") & filters.me)
async def toggle(bot: UserBot, message: Message):
c = switch()
await message.edit("`Vulgar Enabled`" if c else "`Vulgar Disabled`")
await asyncio.sleep(3)
await message.delete()
@UserBot.on_message(~filters.regex(r"^\.\w*") & filters.me & ~filters.media, group=10)
async def i_am_not_allowed_to_say_this(bot: UserBot, message: Message):
if vulgar_filter:
try:
txt = None
if message.caption:
txt = message.caption
elif message.text:
txt = message.text
for word in bad_words:
try:
txt = re.sub(word, good_words[bad_words.index(word)], txt, flags=re.IGNORECASE)
except Exception as e:
LOGS.warn(e)
if message.caption:
if txt != message.caption:
await message.edit_caption(txt)
elif message.text:
if txt != message.text:
await message.edit(txt)
except MessageNotModified:
return
# Command help section
add_command_help(
"vulgar",
[
[".vulgar", "Toggles bad word filtering on and off."],
],
)