forked from TheTeamAlexa/MentionBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bot.py
234 lines (207 loc) · 10 KB
/
Bot.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
# A Powerful Music And Management Bot
# Property Of Rocks Indian Largest Chatting Group
# Rocks © @ASHWANI10 © Rocks
# Owner ASHWANI
import os, logging, asyncio
from telethon import Button
from telethon import TelegramClient, events
from telethon.tl.types import ChannelParticipantAdmin
from telethon.tl.types import ChannelParticipantCreator
from telethon.tl.types import ChannelParticipantsAdmins
from telethon.tl.functions.channels import GetParticipantRequest
from telethon.errors import UserNotParticipantError
from pyrogram import Client, filters
from pyrogram.types import Message, InlineKeyboardMarkup, InlineKeyboardButton
logging.basicConfig(
level=logging.INFO, format="%(name)s - [%(levelname)s] - %(message)s"
)
LOGGER = logging.getLogger(__name__)
api_id = int(os.environ.get("APP_ID", ""))
api_hash = os.environ.get("API_HASH", "")
bot_token = os.environ.get("TOKEN", "")
client = TelegramClient("client", api_id, api_hash).start(bot_token=bot_token)
spam_chats = []
@client.on(events.NewMessage(pattern="^/start$"))
async def start(event):
chat_id = event.chat_id
if not event.is_private:
return await event.respond("ɪ ᴀᴍ ᴀʟɪᴠᴇ 🥺")
await event.reply(
"━━━━━━━━━━━━━━━━━━━━━━━━\n\n✪ ɪ ᴀᴍ ᴀʟᴇxᴀ ᴛᴏ ᴍᴇɴᴛɪᴏɴ ᴀʟʟ ᴛʜᴇ ɢʀᴏᴜᴘ ᴍᴇᴍʙᴇʀs ɪɴ ᴛᴇʟᴇɢʀᴀᴍ\n✪ ᴛʜᴀɴᴋs ғᴏʀ ᴜsɪɴɢ ʀᴜɴ /help..\n\n┏━━━━━━━━━━━━━━━━━┓\n┣★ ᴏᴡɴᴇʀ : [ᴀsᴀᴅ ᴀʟɪ](https://t.me/Dr_Asad_Ali)\n┣★ ᴜᴘᴅᴀᴛᴇs › : [ᴀʟᴇxᴀ ʜᴇʟᴘ](https://t.me/Alexa_BotUpdates)┓\n┣★ ʀᴇᴘᴏ › : [ᴀʟᴇxᴀ ʀᴇᴘᴏ](https://github.com/TheTeamAlexa/MentionBot)\n┗━━━━━━━━━━━━━━━━━┛\n\n💞 ɪғ ʏᴏᴜ ʜᴀᴠᴇ ᴀɴʏ ǫᴜᴇsᴛɪᴏɴs ᴛʜᴇɴ\nᴅᴍ ᴛᴏ ᴍʏ [ᴏᴡɴᴇʀ](https://t.me/Jankari_Ki_Duniya) ...\n\n━━━━━━━━━━━━━━━━━━━━━━━━",
link_preview=False,
buttons=(
[
Button.url(
"☀︎︎️ OWNER ☀︎︎",
"https://t.me/ASHWANI10?startgroup=true",
),
],
[
Button.url("☀︎︎ ɢʀᴏᴜᴘ ☀︎︎︎", "https://t.me/WEB_NET_CHATMASTI"),
Button.url("☀︎︎ ᴄʜᴀɴɴᴇʟ ☀︎︎", "https://t.me/ASHWANI10_OFFICIAL"),
],
[
Button.url("☀︎︎ OWNER ☀︎︎️️", "https://t.me/ASHWANI10"),
Button.url("☀︎︎ STUDY ☀︎︎︎", "https://t.me/quizgroup10thclass"),
],
),
)
@client.on(events.NewMessage(pattern="^/help$"))
async def help(event):
chat_id = event.chat_id
if not event.is_private:
return await event.respond("ᴅᴇᴀʀ sᴛᴀʀᴛ ᴍᴇ ɪɴ ᴘᴍ ᴛᴏ ᴜsᴇ ᴛʜɪs ᴄᴏᴍᴍᴀɴғ 🥺")
helptext = "✪ ʜᴇʟᴘ ᴍᴇɴᴜ ᴏғ ᴀʟᴇxᴀ ᴍᴇɴᴛɪᴏɴ\n\n✪ ᴄᴏᴍᴍᴀɴᴅ: /mentionall\n✪ ᴄᴏᴍᴍᴀɴᴅ: /cancel ᴛᴏ ᴄᴀɴᴄᴇʟ ɢᴏɪɴɢ ᴏɴ ᴘʀᴏᴄᴇss.\n✪ ᴄᴏᴍᴍᴀɴᴅ /admin ᴛᴏ ᴍᴇɴᴛɪᴏɴ ᴀʟʟ ᴀᴅᴍɪɴ ʏᴏᴜʀ ɢʀᴏᴜᴘ\n✪ Yᴏᴜ ᴄᴀɴ ᴜsᴇ ᴛʜɪs ᴄᴏᴍᴍᴀɴᴅ ᴡɪᴛʜ ᴛᴇxᴛ ᴡʜᴀᴛ ʏᴏᴜ ᴡᴀɴᴛ ᴛᴏ ᴍᴇɴᴛɪᴏɴ ᴏᴛʜᴇʀs.\n✪ `Example: /mentionall Good Morning!`\n✪ Yᴏᴜ ᴄᴀɴ ʏᴏᴜ ᴛʜɪs ᴄᴏᴍᴍᴀɴᴅ ᴀs ᴀ ʀᴇᴘʟʏ ᴛᴏ ᴀɴʏ ᴍᴇssᴀɢᴇ. Bᴏᴛ ᴡɪʟʟ ᴛᴀɢ ᴜsᴇʀs ᴛᴏ ᴛʜᴀᴛ ʀᴇᴘʟɪᴇᴅ ᴍᴇsssᴀɢᴇ."
await event.reply(
helptext,
link_preview=False,
buttons=(
[
Button.url("☀︎︎ OWNER", "https://t.me/ASHWANI10"),
Button.url("☀︎︎ CHAT ☀︎︎", "https://t.me/WEB_NET_CHATMASTI"),
]
),
)
@client.on(events.NewMessage(pattern="^/owner$"))
async def help(event):
chat_id = event.chat_id
if not event.is_private:
return await event.respond("ᴅᴇᴀʀ sᴛᴀʀᴛ ᴍᴇ ɪɴ ᴘᴍ ᴛᴏ ᴜsᴇ ᴛʜɪs ᴄᴏᴍᴍᴀɴғ 🥺")
helptext = "✪ ᴏᴡɴᴇʀ ᴍᴇɴᴜ ᴏғ ᴀʟᴇxᴀ ᴍᴇɴᴛɪᴏɴ\n\n✪ ᴍʏ ᴏᴡɴᴇʀ ɪs [ᴀsᴀᴅ ᴀʟɪ](https://t.me/Dr_Asad_Ali)\n✪ ᴏғғɪᴄɪᴀʟ ᴍᴇᴍʙᴇʀ ᴏғ ʀᴏᴄᴋs\n✪ ʏᴏᴜᴛᴜʙᴇ [ᴄʜᴀɴɴᴇʟ](https://www.youtube.com/c/JankariKiDuniya)\n✪ ғᴜᴛᴜʀᴇ ᴀɴᴇsᴛʜᴇᴛɪᴄ."
await event.reply(
helptext,
link_preview=False,
buttons=(
[
Button.url("☀︎︎ ʜᴇᴀʀᴛ", "https://t.me/ASHWANI10"),
Button.url("CHAT ☀︎︎", "https://t.me/WEB_NET_CHATMASTI"),
]
),
)
@client.on(events.NewMessage(pattern="^/mentionall ?(.*)"))
async def mentionall(event):
chat_id = event.chat_id
if event.is_private:
return await event.respond(
"ᴛʜɪs ᴄᴏᴍᴍᴀɴᴅ ᴄᴀɴ ʙᴇ ᴜsᴇ ɪɴ ɢʀᴏᴜᴘs ᴀɴᴅ ᴄʜᴀɴɴᴇʟs"
)
is_admin = False
try:
partici_ = await client(GetParticipantRequest(event.chat_id, event.sender_id))
except UserNotParticipantError:
is_admin = False
else:
if isinstance(
partici_.participant, (ChannelParticipantAdmin, ChannelParticipantCreator)
):
is_admin = True
if not is_admin:
return await event.respond("ᴏɴʟʏ ᴀᴅᴍɪɴs ᴄᴀɴ ᴍᴇɴᴛɪᴏɴ ᴀʟʟ")
if event.pattern_match.group(1) and event.is_reply:
return await event.respond("ɢɪᴠᴇ ᴍᴇ ᴏɴᴇ ᴀʀɢᴜᴍᴇɴᴛ")
elif event.pattern_match.group(1):
mode = "text_on_cmd"
msg = event.pattern_match.group(1)
elif event.is_reply:
mode = "text_on_reply"
msg = await event.get_reply_message()
if msg == None:
return await event.respond(
"ɪ ᴄᴀɴ'ᴛ ᴍᴇɴᴛɪᴏɴ ᴍᴇᴍʙᴇʀs ꜰᴏʀ ᴏʟᴅᴇʀ ᴍᴇssᴀɢᴇs! (ᴍᴇssᴀɢᴇs ᴡʜɪᴄʜ ᴀʀᴇ sᴇɴᴛ ʙᴇꜰᴏʀᴇ ɪ'ᴍ ᴀᴅᴅᴇᴅ ᴛᴏ ɢʀᴏᴜᴘ)"
)
else:
return await event.respond(
"ʀᴇᴘʟʏ ᴛᴏ ᴀ ᴍᴇssᴀɢᴇ ᴏʀ ɢɪᴠᴇ ᴍᴇ sᴏᴍᴇ ᴛᴇxᴛ ᴛᴏ ᴍᴇɴᴛɪᴏɴ ᴏᴛʜᴇʀs"
)
spam_chats.append(chat_id)
usrnum = 0
usrtxt = ""
async for usr in client.iter_participants(chat_id):
if not chat_id in spam_chats:
break
usrnum += 1
usrtxt += f"[{usr.first_name}](tg://user?id={usr.id}) "
if usrnum == 5:
if mode == "text_on_cmd":
txt = f"{usrtxt}\n\n{msg}"
await client.send_message(chat_id, txt)
elif mode == "text_on_reply":
await msg.reply(usrtxt)
await asyncio.sleep(2)
usrnum = 0
usrtxt = ""
try:
spam_chats.remove(chat_id)
except:
pass
@client.on(events.NewMessage(pattern="^/admins|/admin|@admin|@admins ?(.*)"))
async def _(event):
chat_id = event.chat_id
if event.is_private:
return await event.respond("sᴏʀʀʏ ʏᴏᴜ ᴄᴀɴ ᴍᴇɴᴛɪᴏɴ ᴀᴅᴍɪɴ ᴏɴʟʏ ɪɴ ɢʀᴏᴜᴘ")
is_admin = False
try:
partici_ = await client(GetParticipantRequest(event.chat_id, event.sender_id))
except UserNotParticipantError:
is_admin = False
else:
if isinstance(
partici_.participant, (ChannelParticipantAdmin, ChannelParticipantCreator)
):
is_admin = True
if not is_admin:
return await event.respond("ᴏɴʟʏ ᴀᴅᴍɪɴ ᴄᴀɴ ᴍᴇɴᴛɪᴏɴ ɢʀᴏᴜᴘ ᴀᴅᴍɪɴs")
if event.pattern_match.group(1) and event.is_reply:
return await event.respond("ɢɪᴠᴇ sᴏᴍᴇ ᴛᴇxᴛ ᴛᴏ ᴍᴇɴᴛɪᴏɴ")
elif event.pattern_match.group(1):
mode = "text_on_cmd"
msg = event.pattern_match.group(1)
elif event.is_reply:
mode = "text_on_reply"
msg = await event.get_reply_message()
if msg == None:
return await event.respond(
"ɪ ᴄᴀɴ'ᴛ ᴍᴇɴᴛɪᴏɴ ᴍᴇᴍʙᴇʀs ꜰᴏʀ ᴏʟᴅᴇʀ ᴍᴇssᴀɢᴇs! (ᴍᴇssᴀɢᴇs ᴡʜɪᴄʜ ᴀʀᴇ sᴇɴᴛ ʙᴇꜰᴏʀᴇ ɪ'ᴍ ᴀᴅᴅᴇᴅ ᴛᴏ ɢʀᴏᴜᴘ)"
)
else:
return await event.respond(
"ʀᴇᴘʟʏ ᴛᴏ ᴀ ᴍᴇssᴀɢᴇ ᴏʀ ɢɪᴠᴇ ᴍᴇ sᴏᴍᴇ ᴛᴇxᴛ ᴛᴏ ᴍᴇɴᴛɪᴏɴ ᴏᴛʜᴇʀs!"
)
spam_chats.append(chat_id)
usrnum = 0
usrtxt = ""
chat = await event.get_input_chat()
async for x in client.iter_participants(chat, filter=ChannelParticipantsAdmins):
if not chat_id in spam_chats:
break
usrnum += 1
usrtxt += f" \n [{x.first_name}](tg://user?id={x.id})"
if usrnum == 5:
if mode == "text_on_cmd":
txt = f"{usrtxt}\n\n{msg}"
await client.send_message(chat_id, txt)
elif mode == "text_on_reply":
await msg.reply(usrtxt)
await asyncio.sleep(2)
usrnum = 0
usrtxt = ""
try:
spam_chats.remove(chat_id)
except:
pass
@client.on(events.NewMessage(pattern="^/cancel$"))
async def cancel_spam(event):
if not event.chat_id in spam_chats:
return await event.respond("ᴛʜᴇʀᴇ ɪs ɴᴏ ᴘʀᴏᴄᴄᴇss ᴏɴ ɢᴏɪɴɢ...")
else:
try:
spam_chats.remove(event.chat_id)
except:
pass
return await event.respond("sᴛᴏᴘᴘᴇᴅ.")
print(">> ASHWANI MENTION WORKING <<")
client.run_until_disconnected()
# A Powerful Music And Management Bot
# Property Of Rocks Indian Largest Chatting Group
# Rocks © @Dr_Asad_Ali © Rocks
# Owner Asad Ali + Harshit Sharma + Abhimanyu Singh + Krishna Ki Diwani