-
Notifications
You must be signed in to change notification settings - Fork 1
/
globalban.py
154 lines (146 loc) · 5.06 KB
/
globalban.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import asyncio
import time
from pyrogram import filters
from pyrogram.errors import FloodWait
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 import get_readable_time
from AnonX.utils.database import (add_banned_user,
get_banned_count,
get_banned_users,
get_served_chats,
is_banned_user,
remove_banned_user)
from AnonX.utils.decorators.language import language
from strings.filters import command
# Command
GBAN_COMMAND = get_command("GBAN_COMMAND")
UNGBAN_COMMAND = get_command("UNGBAN_COMMAND")
GBANNED_COMMAND = get_command("GBANNED_COMMAND")
@app.on_message(
command(GBAN_COMMAND)
& SUDOERS
)
@language
async def gbanuser(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]
user = await app.get_users(user)
user_id = user.id
mention = user.mention
else:
user_id = message.reply_to_message.from_user.id
mention = message.reply_to_message.from_user.mention
if user_id == message.from_user.id:
return await message.reply_text(_["gban_1"])
elif user_id == app.id:
return await message.reply_text(_["gban_2"])
elif user_id in SUDOERS:
return await message.reply_text(_["gban_3"])
is_gbanned = await is_banned_user(user_id)
if is_gbanned:
return await message.reply_text(_["gban_4"].format(mention))
if user_id not in BANNED_USERS:
BANNED_USERS.add(user_id)
served_chats = []
chats = await get_served_chats()
for chat in chats:
served_chats.append(int(chat["chat_id"]))
time_expected = len(served_chats)
time_expected = get_readable_time(time_expected)
mystic = await message.reply_text(
_["gban_5"].format(mention, time_expected)
)
number_of_chats = 0
for chat_id in served_chats:
try:
await app.ban_chat_member(chat_id, user_id)
number_of_chats += 1
except FloodWait as e:
await asyncio.sleep(int(e.x))
except Exception:
pass
await add_banned_user(user_id)
await message.reply_sticker("CAACAgUAAxkBAAIjZmKPbsuJzL3TVFQ7q2lc_rRuqa6xAAIyCQACHjuBVOwXUJB64QeSJAQ")
await message.reply_text(
_["gban_6"].format(mention, number_of_chats)
)
await mystic.delete()
@app.on_message(
command(UNGBAN_COMMAND)
& SUDOERS
)
@language
async def gungabn(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]
user = await app.get_users(user)
user_id = user.id
mention = user.mention
else:
user_id = message.reply_to_message.from_user.id
mention = message.reply_to_message.from_user.mention
is_gbanned = await is_banned_user(user_id)
if not is_gbanned:
return await message.reply_text(_["gban_7"].format(mention))
if user_id in BANNED_USERS:
BANNED_USERS.remove(user_id)
served_chats = []
chats = await get_served_chats()
for chat in chats:
served_chats.append(int(chat["chat_id"]))
time_expected = len(served_chats)
time_expected = get_readable_time(time_expected)
mystic = await message.reply_text(
_["gban_8"].format(mention, time_expected)
)
number_of_chats = 0
for chat_id in served_chats:
try:
await app.unban_chat_member(chat_id, user_id)
number_of_chats += 1
except FloodWait as e:
await asyncio.sleep(int(e.x))
except Exception:
pass
await remove_banned_user(user_id)
await message.reply_sticker("CAACAgUAAxkBAAIjbGKPb3oOFXIT3KSxlIoefG7jTLOiAAJuBgAC_415VDBZlDYZrGxCJAQ")
await message.reply_text(
_["gban_9"].format(mention, number_of_chats)
)
await mystic.delete()
@app.on_message(
command(GBANNED_COMMAND)
& SUDOERS
)
@language
async def gbanned_list(client, message: Message, _):
counts = await get_banned_count()
if counts == 0:
return await message.reply_text(_["gban_10"])
mystic = await message.reply_text(_["gban_11"])
msg = "ɢʙᴀɴɴᴇᴅ ᴜsᴇʀs:\n\n"
count = 0
users = await get_banned_users()
for user_id in users:
count += 1
try:
user = await app.get_users(user_id)
user = (
user.first_name if not user.mention else user.mention
)
msg += f"{count}➤ {user}\n"
except Exception:
msg += f"{count}➤ [ᴜɴᴋɴᴏᴡɴ ᴜsᴇʀ]{user_id}\n"
continue
if count == 0:
return await mystic.edit_text(_["gban_10"])
else:
return await mystic.edit_text(msg)