-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
main.py
162 lines (133 loc) · 4.7 KB
/
main.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
import os
import re
from pyrogram import Client, filters, idle
from pyrogram.types import (
CallbackQuery,
InlineKeyboardButton,
InlineKeyboardMarkup,
Message,
)
if os.environ.get("HEROKU"):
API_ID = os.environ.get("API_ID")
API_HASH = os.environ.get("API_HASH")
BOT_TOKEN = os.environ.get("BOT_TOKEN")
SESSION = os.environ.get("SESSION")
GROUP = os.environ.get("GROUP_ID")
else:
from config import API_HASH, API_ID, BOT_TOKEN, GROUP, SESSION
bot = Client("bot", api_id=API_ID, api_hash=API_HASH, bot_token=BOT_TOKEN)
user = Client(SESSION, api_id=API_ID, api_hash=API_HASH)
@user.on_message(filters.mentioned & filters.incoming)
async def alert(_, m: Message):
if m.sender_chat:
button_s = InlineKeyboardMarkup(
[
[InlineKeyboardButton(text="Anonymous Admin", callback_data="nuthing")],
[InlineKeyboardButton(text="📩 Message", url=m.link)],
],
)
await bot.send_message(GROUP, m.text, reply_markup=button_s)
m.continue_propagation()
return
if m.from_user.is_bot:
m.continue_propagation()
return
if not m:
m.continue_propagation()
return
if m.from_user.last_name:
name = f"{m.from_user.first_name} {m.from_user.last_name}"
else:
name = m.from_user.first_name
if m.from_user.username:
button_s = InlineKeyboardMarkup(
[
[
InlineKeyboardButton(
text=name,
url=f"https://t.me/{m.from_user.username}",
),
],
[InlineKeyboardButton(text=m.chat.title, url=m.link)],
],
)
else:
button_s = InlineKeyboardMarkup(
[
[
InlineKeyboardButton(
text=name,
callback_data=f"user({m.from_user.id})",
),
],
[InlineKeyboardButton(text=m.chat.title, url=m.link)],
],
)
if m.media:
if m.photo:
_f = await m.photo.download(f"{m.chat.id}_{m.message_id}")
await bot.send_photo(GROUP, _f, reply_markup=button_s)
os.remove(_f)
elif m.sticker:
await bot.send_sticker(GROUP, m.sticker.file_id, reply_markup=button_s)
os.remove(_f)
elif m.animation:
_f = await m.animation.download(f"{m.chat.id}_{m.message_id}")
await bot.send_animation(GROUP, _f, reply_markup=button_s)
os.remove(_f)
elif m.document:
_f = await m.document.download(f"{m.chat.id}_{m.message_id}")
await bot.send_document(GROUP, _f, reply_markup=button_s)
os.remove(_f)
else:
await bot.send_message(GROUP, "Unsupported Message", reply_markup=button_s)
elif m.text:
await bot.send_message(GROUP, m.text, reply_markup=button_s)
else:
await bot.send_message(GROUP, "Unsupported Message", reply_markup=button_s)
m.continue_propagation()
return
@bot.on_callback_query(filters.regex("^user.*"))
async def privacy(_, q: CallbackQuery):
old = q.message.text or None
if match := re.match(r"user\((.+?)\)", q.data):
user_id = int(match[1])
try:
user = await q.message._client.get_users(user_id)
if old != None:
new = f"{old}\n\nUser: {user.mention} [`{user.id}`]"
await q.message.edit_text(new)
else:
await q.message.reply_text("User: {user.mention} [`{user.id}`]")
return
except:
if old != None:
await q.message.edit_text(f"{old}\n\nFrom User ID: `{user_id}`")
else:
await q.message.reply_text(f"From User ID: `{user_id}`")
@bot.on_callback_query(filters.regex("^nuthing.*"))
async def privacy(_, __):
return None
async def _run():
if not API_ID:
raise NameError("API_ID is Required to Run the Bot")
if not API_HASH:
raise NameError("API_HASH is Required to Run the Bot")
if not GROUP:
raise NameError("GROUP_ID is Required to Run the Bot")
if not BOT_TOKEN:
raise NameError("BOT_TOKEN is Required to Run the Bot")
if not SESSION:
raise NameError("SESSION is Required to Run the Bot")
await bot.start()
bot_info = await bot.get_me()
await user.start()
user_info = await user.get_me()
FULL_INFO = (
f"[INFO] - SUCCESSFULLY STARTED BOT {bot_info.username}\n"
f"[INFO] - SUCCESSFULLY STARTED USER SESSION {user_info.username}"
)
print(FULL_INFO)
await idle()
if __name__ == "__main__":
user.loop.run_until_complete(_run())