-
Notifications
You must be signed in to change notification settings - Fork 1
/
block.py
104 lines (97 loc) · 3.21 KB
/
block.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
from pyrogram import filters
from pyrogram.types import Message
from config import BANNED_USERS
from strings import get_command
from AnonX import app
from AnonX.misc import SUDOERS
from AnonX.utils.database import add_gban_user, remove_gban_user
from AnonX.utils.decorators.language import language
from strings.filters import command
# Command
BLOCK_COMMAND = get_command("BLOCK_COMMAND")
UNBLOCK_COMMAND = get_command("UNBLOCK_COMMAND")
BLOCKED_COMMAND = get_command("BLOCKED_COMMAND")
@app.on_message(
command(BLOCK_COMMAND)
& SUDOERS
)
@language
async def useradd(client, message: Message, _):
if not message.reply_to_message:
if len(message.command) != 2:
return await message.reply_text(_["general_1"])
user = message.text.split(None, 1)[1]
if "@" in user:
user = user.replace("@", "")
user = await app.get_users(user)
if user.id in BANNED_USERS:
return await message.reply_text(
_["block_1"].format(user.mention)
)
await add_gban_user(user.id)
BANNED_USERS.add(user.id)
await message.reply_text(_["block_2"].format(user.mention))
return
if message.reply_to_message.from_user.id in BANNED_USERS:
return await message.reply_text(
_["block_1"].format(
message.reply_to_message.from_user.mention
)
)
await add_gban_user(message.reply_to_message.from_user.id)
BANNED_USERS.add(message.reply_to_message.from_user.id)
await message.reply_text(
_["block_2"].format(
message.reply_to_message.from_user.mention
)
)
@app.on_message(
command(UNBLOCK_COMMAND)
& SUDOERS
)
@language
async def userdel(client, message: Message, _):
if not message.reply_to_message:
if len(message.command) != 2:
return await message.reply_text(_["general_1"])
user = message.text.split(None, 1)[1]
if "@" in user:
user = user.replace("@", "")
user = await app.get_users(user)
if user.id not in BANNED_USERS:
return await message.reply_text(_["block_3"])
await remove_gban_user(user.id)
BANNED_USERS.remove(user.id)
await message.reply_text(_["block_4"])
return
user_id = message.reply_to_message.from_user.id
if user_id not in BANNED_USERS:
return await message.reply_text(_["block_3"])
await remove_gban_user(user_id)
BANNED_USERS.remove(user_id)
await message.reply_text(_["block_4"])
@app.on_message(
command(BLOCKED_COMMAND)
& SUDOERS
)
@language
async def sudoers_list(client, message: Message, _):
if not BANNED_USERS:
return await message.reply_text(_["block_5"])
mystic = await message.reply_text(_["block_6"])
msg = _["block_7"]
count = 0
for users in BANNED_USERS:
try:
user = await app.get_users(users)
user = (
user.first_name if not user.mention else user.mention
)
count += 1
except Exception:
continue
msg += f"{count}➤ {user}\n"
if count == 0:
return await mystic.edit_text(_["block_5"])
else:
return await mystic.edit_text(msg)