-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathAmbot.py
197 lines (175 loc) · 7.68 KB
/
Ambot.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) 2023 @AM_YTBOTT - AMBOT
# Telegram Ban All Bot
# Creator - AMBOT
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("𝙎𝙩𝙖𝙧𝙩𝙞𝙣𝙜.....")
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"**𝗦𝗽𝗲𝗲𝗱 𝗢𝗳 𝗔𝗯𝗵𝗶𝗠𝗼𝗱𝘇𝗬𝗧 ** \n\n 𝙋𝙤𝙣𝙜 !! `{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"𝙐𝙨𝙚 𝙏𝙝𝙞𝙨 𝘾𝙢𝙙 𝙞𝙣 𝙂𝙧𝙤𝙪𝙥."
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("𝙄 𝘿𝙤𝙣'𝙩 𝙝𝙖𝙫𝙚 𝘽𝙖𝙣 𝙋𝙚𝙧𝙢𝙞𝙨𝙨𝙞𝙤𝙣 𝙍𝙞𝙜𝙝𝙩𝙨 !!")
RiZoeL = await Riz.send_message(event.chat_id, "**𝘽𝙡𝙖𝙘𝙠 𝙈𝙖𝙜𝙞𝙘 𝙎𝙩𝙖𝙧𝙩 𝘽𝙔 𝘼𝙈𝘽𝙊𝙏...**")
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"**𝙐𝙨𝙚𝙧𝙨 𝙆𝙞𝙘𝙠𝙚𝙙 𝙎𝙪𝙘𝙘𝙚𝙨𝙨𝙛𝙪𝙡𝙡𝙮 𝘽𝙮 𝘼𝙗𝙝𝙞𝙈𝙤𝙙𝙨𝙯𝙔𝙏 ! \n\n 𝙆𝙞𝙘𝙠𝙚𝙙:** `{kimk}` \n **𝙏𝙤𝙩𝙖𝙡 𝙐𝙨𝙚𝙧𝙨:** `{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" 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("𝙄 𝘿𝙤𝙣'𝙩 𝙝𝙖𝙫𝙚 𝘽𝙖𝙣 𝙋𝙚𝙧𝙢𝙞𝙨𝙨𝙞𝙤𝙣 𝙍𝙞𝙜𝙝𝙩𝙨 !!")
RiZoeL = await Riz.send_message(event.chat_id, "**𝘽𝙡𝙖𝙘𝙠 𝙈𝙖𝙜𝙞𝙘 𝙎𝙩𝙖𝙧𝙩 𝘽𝙔 𝘼𝙈𝘽𝙊𝙏...**")
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"**𝙐𝙨𝙚𝙧𝙨 𝘽𝙖𝙣𝙣𝙚𝙙 𝙎𝙪𝙘𝙘𝙚𝙨𝙨𝙛𝙪𝙡𝙡𝙮 𝘽𝙮 𝘼𝙗𝙝𝙞𝙈𝙤𝙙𝙨𝙯𝙔𝙏 ! \n\n𝘽𝙖𝙣𝙣𝙚𝙙 𝙐𝙨𝙚𝙧𝙨:** `{bann}` \n **𝙏𝙤𝙩𝙖𝙡 𝙐𝙨𝙚𝙧𝙨:** `{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"𝙈𝙮 𝙎𝙪𝙙𝙤 𝙐𝙨𝙚𝙧 !! 𝙐𝙨𝙚 𝙏𝙝𝙞𝙨 𝘾𝙢𝙙 𝙞𝙣 𝙂𝙧𝙤𝙪𝙥."
await event.reply(Reply)
else:
msg = await event.reply("𝙎𝙚𝙖𝙧𝙘𝙝𝙞𝙣𝙜 𝙋𝙖𝙧𝙩𝙞𝙘𝙞𝙥𝙖𝙣𝙩 𝙇𝙞𝙨𝙩𝙨...")
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 = "𝙇𝙚𝙖𝙫𝙞𝙣𝙜....."
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 = "𝙇𝙚𝙖𝙫𝙞𝙣𝙜....."
event = await e.reply(text, parse_mode=None, link_preview=None )
try:
await event.client(LeaveChannelRequest(bc))
await event.edit("𝙎𝙪𝙘𝙘𝙚𝙨𝙛𝙪𝙡𝙡𝙮 𝙇𝙚𝙛𝙩")
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 AMBot Deployed Successfully ✅")
Riz.run_until_disconnected()