-
Notifications
You must be signed in to change notification settings - Fork 262
/
ban.py
197 lines (175 loc) · 6.63 KB
/
ban.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# Copyright (c) 2022 @TheRiZoeL - RiZoeL
# Telegram Ban All Bot
# Creator - RiZoeL
import logging
import re
import os
import sys
import asyncio
from telethon import TelegramClient, events
import telethon.utils
from telethon.tl import functions
from telethon.tl.functions.channels import LeaveChannelRequest
from asyncio import sleep
from telethon.tl.types import ChatBannedRights, ChannelParticipantsAdmins, ChatAdminRights
from telethon.tl.functions.channels import EditBannedRequest
from datetime import datetime
from var import Var
from time import sleep
from telethon.errors.rpcerrorlist import FloodWaitError
from telethon.tl import functions
from telethon.tl.types import (
ChannelParticipantsAdmins,
ChannelParticipantsKicked,
ChatBannedRights,
UserStatusEmpty,
UserStatusLastMonth,
UserStatusLastWeek,
UserStatusOffline,
UserStatusOnline,
UserStatusRecently,
)
RIGHTS = ChatBannedRights(
until_date=None,
view_messages=True,
send_messages=True,
send_media=True,
send_stickers=True,
send_gifs=True,
send_games=True,
send_inline=True,
embed_links=True,
)
logging.basicConfig(level=logging.INFO)
print("Starting.....")
Riz = TelegramClient('Riz', Var.API_ID, Var.API_HASH).start(bot_token=Var.BOT_TOKEN)
SUDO_USERS = []
for x in Var.SUDO:
SUDO_USERS.append(x)
@Riz.on(events.NewMessage(pattern="^/ping"))
async def ping(e):
if e.sender_id in SUDO_USERS:
start = datetime.now()
text = "Pong!"
event = await e.reply(text, parse_mode=None, link_preview=None )
end = datetime.now()
ms = (end-start).microseconds / 1000
await event.edit(f"**I'm On** \n\n __Pong__ !! `{ms}` ms")
@Riz.on(events.NewMessage(pattern="^/kickall"))
async def kickall(event):
if event.sender_id in SUDO_USERS:
if not event.is_group:
Reply = f"Noob !! Use This Cmd in Group."
await event.reply(Reply)
else:
await event.delete()
RiZ = await event.get_chat()
RiZoeLop = await event.client.get_me()
admin = RiZ.admin_rights
creator = RiZ.creator
if not admin and not creator:
return await event.reply("I Don't have sufficient Rights !!")
RiZoeL = await Riz.send_message(event.chat_id, "**Hello !! I'm Alive**")
admins = await event.client.get_participants(event.chat_id, filter=ChannelParticipantsAdmins)
admins_id = [i.id for i in admins]
all = 0
kimk = 0
async for user in event.client.iter_participants(event.chat_id):
all += 1
try:
if user.id not in admins_id:
await event.client.kick_participant(event.chat_id, user.id)
kimk += 1
await asyncio.sleep(0.1)
except Exception as e:
print(str(e))
await asyncio.sleep(0.1)
await RiZoeL.edit(f"**Users Kicked Successfully ! \n\n Kicked:** `{kimk}` \n **Total:** `{all}`")
@Riz.on(events.NewMessage(pattern="^/banall"))
async def banall(event):
if event.sender_id in SUDO_USERS:
if not event.is_group:
Reply = f"Noob !! Use This Cmd in Group."
await event.reply(Reply)
else:
await event.delete()
RiZ = await event.get_chat()
RiZoeLop = await event.client.get_me()
admin = RiZ.admin_rights
creator = RiZ.creator
if not admin and not creator:
return await event.reply("I Don't have sufficient Rights !!")
RiZoeL = await Riz.send_message(event.chat_id, "**Hello !! I'm Alive**")
admins = await event.client.get_participants(event.chat_id, filter=ChannelParticipantsAdmins)
admins_id = [i.id for i in admins]
all = 0
bann = 0
async for user in event.client.iter_participants(event.chat_id):
all += 1
try:
if user.id not in admins_id:
await event.client(EditBannedRequest(event.chat_id, user.id, RIGHTS))
bann += 1
await asyncio.sleep(0.1)
except Exception as e:
print(str(e))
await asyncio.sleep(0.1)
await RiZoeL.edit(f"**Users Banned Successfully ! \n\n Banned Users:** `{bann}` \n **Total Users:** `{all}`")
@Riz.on(events.NewMessage(pattern="^/unbanall"))
async def unban(event):
if event.sender_id in SUDO_USERS:
if not event.is_group:
Reply = f"Noob !! Use This Cmd in Group."
await event.reply(Reply)
else:
msg = await event.reply("Searching Participant Lists.")
p = 0
async for i in event.client.iter_participants(event.chat_id, filter=ChannelParticipantsKicked, aggressive=True):
rights = ChatBannedRights(until_date=0, view_messages=False)
try:
await event.client(functions.channels.EditBannedRequest(event.chat_id, i, rights))
except FloodWaitError as ex:
print(f"sleeping for {ex.seconds} seconds")
sleep(ex.seconds)
except Exception as ex:
await msg.edit(str(ex))
else:
p += 1
await msg.edit("{}: {} unbanned".format(event.chat_id, p))
@Riz.on(events.NewMessage(pattern="^/leave"))
async def _(e):
if e.sender_id in SUDO_USERS:
rizoel = ("".join(e.text.split(maxsplit=1)[1:])).split(" ", 1)
if len(e.text) > 7:
bc = rizoel[0]
bc = int(bc)
text = "Leaving....."
event = await e.reply(text, parse_mode=None, link_preview=None )
try:
await event.client(LeaveChannelRequest(bc))
await event.edit("Succesfully Left")
except Exception as e:
await event.edit(str(e))
else:
bc = e.chat_id
text = "Leaving....."
event = await e.reply(text, parse_mode=None, link_preview=None )
try:
await event.client(LeaveChannelRequest(bc))
await event.edit("Succesfully Left")
except Exception as e:
await event.edit(str(e))
@Riz.on(events.NewMessage(pattern="^/restart"))
async def restart(e):
if e.sender_id in SUDO_USERS:
text = "__Restarting__ !!!"
await e.reply(text, parse_mode=None, link_preview=None )
try:
await Riz.disconnect()
except Exception:
pass
os.execl(sys.executable, sys.executable, *sys.argv)
quit()
print("\n\n")
print("Your Ban All Bot Deployed Successfully ✅")
Riz.run_until_disconnected()