-
Notifications
You must be signed in to change notification settings - Fork 91
/
Copy pathpingallbot.py
267 lines (247 loc) · 10.4 KB
/
pingallbot.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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
#Copyright ©️ 2022 TeLe TiPs. All Rights Reserved
#You are free to use this code in any of your project, but you MUST include the following in your README.md (Copy & paste)
# ##Credits - [Ping All Telegram bot by TeLe TiPs] (https://github.com/teletips/PingAllBot-teletips)
# Changing the code is not allowed! Read GNU AFFERO GENERAL PUBLIC LICENSE: https://github.com/teletips/PingAllBot-teletips/blob/main/LICENSE
from pyrogram import Client, filters
from pyrogram.types import Message
import os
import asyncio
from pyrogram import enums
from pyrogram.enums import ChatMemberStatus
from pyrogram.errors import FloodWait
teletips=Client(
"PingAllBot",
api_id = int(os.environ["API_ID"]),
api_hash = os.environ["API_HASH"],
bot_token = os.environ["BOT_TOKEN"]
)
chatQueue = []
stopProcess = False
@teletips.on_message(filters.command(["ping","all"]))
async def everyone(client, message):
global stopProcess
try:
try:
sender = await teletips.get_chat_member(message.chat.id, message.from_user.id)
has_permissions = sender.privileges
except:
has_permissions = message.sender_chat
if has_permissions:
if len(chatQueue) > 5:
await message.reply("⛔️ | I'm already working on my maximum number of 5 chats at the moment. Please try again shortly.")
else:
if message.chat.id in chatQueue:
await message.reply("🚫 | There's already an ongoing process in this chat. Please /stop to start a new one.")
else:
chatQueue.append(message.chat.id)
if len(message.command) > 1:
inputText = message.command[1]
elif len(message.command) == 1:
inputText = ""
membersList = []
async for member in teletips.get_chat_members(message.chat.id):
if member.user.is_bot == True:
pass
elif member.user.is_deleted == True:
pass
else:
membersList.append(member.user)
i = 0
lenMembersList = len(membersList)
if stopProcess: stopProcess = False
while len(membersList) > 0 and not stopProcess :
j = 0
text1 = f"{inputText}\n\n"
try:
while j < 10:
user = membersList.pop(0)
if user.username == None:
text1 += f"{user.mention} "
j+=1
else:
text1 += f"@{user.username} "
j+=1
try:
await teletips.send_message(message.chat.id, text1)
except Exception:
pass
await asyncio.sleep(10)
i+=10
except IndexError:
try:
await teletips.send_message(message.chat.id, text1)
except Exception:
pass
i = i+j
if i == lenMembersList:
await message.reply(f"✅ | Successfully mentioned **total number of {i} members**.\n❌ | Bots and deleted accounts were rejected.")
else:
await message.reply(f"✅ | Successfully mentioned **{i} members.**\n❌ | Bots and deleted accounts were rejected.")
chatQueue.remove(message.chat.id)
else:
await message.reply("👮🏻 | Sorry, **only admins** can execute this command.")
except FloodWait as e:
await asyncio.sleep(e.value)
@teletips.on_message(filters.command(["remove","clean"]))
async def remove(client, message):
global stopProcess
try:
try:
sender = await teletips.get_chat_member(message.chat.id, message.from_user.id)
has_permissions = sender.privileges
except:
has_permissions = message.sender_chat
if has_permissions:
bot = await teletips.get_chat_member(message.chat.id, "self")
if bot.status == ChatMemberStatus.MEMBER:
await message.reply("🕹 | I need admin permissions to remove deleted accounts.")
else:
if len(chatQueue) > 5 :
await message.reply("⛔️ | I'm already working on my maximum number of 5 chats at the moment. Please try again shortly.")
else:
if message.chat.id in chatQueue:
await message.reply("🚫 | There's already an ongoing process in this chat. Please /stop to start a new one.")
else:
chatQueue.append(message.chat.id)
deletedList = []
async for member in teletips.get_chat_members(message.chat.id):
if member.user.is_deleted == True:
deletedList.append(member.user)
else:
pass
lenDeletedList = len(deletedList)
if lenDeletedList == 0:
await message.reply("👻 | No deleted accounts in this chat.")
chatQueue.remove(message.chat.id)
else:
k = 0
processTime = lenDeletedList*10
temp = await teletips.send_message(message.chat.id, f"🚨 | Total of {lenDeletedList} deleted accounts has been detected.\n⏳ | Estimated time: {processTime} seconds from now.")
if stopProcess: stopProcess = False
while len(deletedList) > 0 and not stopProcess:
deletedAccount = deletedList.pop(0)
try:
await teletips.ban_chat_member(message.chat.id, deletedAccount.id)
except Exception:
pass
k+=1
await asyncio.sleep(10)
if k == lenDeletedList:
await message.reply(f"✅ | Successfully removed all deleted accounts from this chat.")
await temp.delete()
else:
await message.reply(f"✅ | Successfully removed {k} deleted accounts from this chat.")
await temp.delete()
chatQueue.remove(message.chat.id)
else:
await message.reply("👮🏻 | Sorry, **only admins** can execute this command.")
except FloodWait as e:
await asyncio.sleep(e.value)
@teletips.on_message(filters.command(["stop","cancel"]))
async def stop(client, message):
global stopProcess
try:
try:
sender = await teletips.get_chat_member(message.chat.id, message.from_user.id)
has_permissions = sender.privileges
except:
has_permissions = message.sender_chat
if has_permissions:
if not message.chat.id in chatQueue:
await message.reply("🤷🏻♀️ | There is no ongoing process to stop.")
else:
stopProcess = True
await message.reply("🛑 | Stopped.")
else:
await message.reply("👮🏻 | Sorry, **only admins** can execute this command.")
except FloodWait as e:
await asyncio.sleep(e.value)
@teletips.on_message(filters.command(["admins","staff"]))
async def admins(client, message):
try:
adminList = []
ownerList = []
async for admin in teletips.get_chat_members(message.chat.id, filter=enums.ChatMembersFilter.ADMINISTRATORS):
if admin.privileges.is_anonymous == False:
if admin.user.is_bot == True:
pass
elif admin.status == ChatMemberStatus.OWNER:
ownerList.append(admin.user)
else:
adminList.append(admin.user)
else:
pass
lenAdminList= len(ownerList) + len(adminList)
text2 = f"**GROUP STAFF - {message.chat.title}**\n\n"
try:
owner = ownerList[0]
if owner.username == None:
text2 += f"👑 Owner\n└ {owner.mention}\n\n👮🏻 Admins\n"
else:
text2 += f"👑 Owner\n└ @{owner.username}\n\n👮🏻 Admins\n"
except:
text2 += f"👑 Owner\n└ <i>Hidden</i>\n\n👮🏻 Admins\n"
if len(adminList) == 0:
text2 += "└ <i>Admins are hidden</i>"
await teletips.send_message(message.chat.id, text2)
else:
while len(adminList) > 1:
admin = adminList.pop(0)
if admin.username == None:
text2 += f"├ {admin.mention}\n"
else:
text2 += f"├ @{admin.username}\n"
else:
admin = adminList.pop(0)
if admin.username == None:
text2 += f"└ {admin.mention}\n\n"
else:
text2 += f"└ @{admin.username}\n\n"
text2 += f"✅ | **Total number of admins**: {lenAdminList}\n❌ | Bots and hidden admins were rejected."
await teletips.send_message(message.chat.id, text2)
except FloodWait as e:
await asyncio.sleep(e.value)
@teletips.on_message(filters.command("bots"))
async def bots(client, message):
try:
botList = []
async for bot in teletips.get_chat_members(message.chat.id, filter=enums.ChatMembersFilter.BOTS):
botList.append(bot.user)
lenBotList = len(botList)
text3 = f"**BOT LIST - {message.chat.title}**\n\n🤖 Bots\n"
while len(botList) > 1:
bot = botList.pop(0)
text3 += f"├ @{bot.username}\n"
else:
bot = botList.pop(0)
text3 += f"└ @{bot.username}\n\n"
text3 += f"✅ | **Total number of bots**: {lenBotList}"
await teletips.send_message(message.chat.id, text3)
except FloodWait as e:
await asyncio.sleep(e.value)
@teletips.on_message(filters.command("start") & filters.private)
async def start(client, message):
text = f'''
Heya {message.from_user.mention},
My name is **PingAll**. I'm here to help you to get everyone's attention by mentioning all members in your chat.
I have some additional cool features and also I can work in channels.
Don't forget to join my [channel](http://t.me/teletipsofficialchannel) to recieve information on all the latest updates.
Hit /help to find out my commands and the use of them.
'''
await teletips.send_message(message.chat.id, text, disable_web_page_preview=True)
@teletips.on_message(filters.command("help"))
async def help(client, message):
text = '''
Hey, let's have a quick look at my commands.
**Commands**:
- /ping "input": <i>Mention all members.</i>
- /remove: <i>Remove all deleted accounts.</i>
- /admins: <i>Mention all admins.</i>
- /bots: <i>Get the full bot list.</i>
- /stop: <i>Stop an on going process.</i>
If you have any questions on how to use me, feel free to ask in my [support group](https://t.me/teletipsofficialontopicchat). More on my [page](https://github.com/teletips/PingAllBot-TeLeTiPs).
'''
await teletips.send_message(message.chat.id, text, disable_web_page_preview=True)
print("PingAll is alive!")
teletips.run()
#Copyright ©️ 2021 TeLe TiPs. All Rights Reserved