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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
MIT License
|
3 |
+
|
4 |
+
Copyright (c) 2025 Randy Dev
|
5 |
+
|
6 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
7 |
+
of this software and associated documentation files (the "Software"), to deal
|
8 |
+
in the Software without restriction, including without limitation the rights
|
9 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10 |
+
copies of the Software, and to permit persons to whom the Software is
|
11 |
+
furnished to do so, subject to the following conditions:
|
12 |
+
|
13 |
+
The above copyright notice and this permission notice shall be included in all
|
14 |
+
copies or substantial portions of the Software.
|
15 |
+
|
16 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
22 |
+
SOFTWARE.
|
23 |
+
"""
|
24 |
+
|
25 |
+
from pyrogram import Client
|
26 |
+
import logging
|
27 |
+
from Detection import assistant
|
28 |
+
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton
|
29 |
+
|
30 |
+
from pyrogram.raw.types import (
|
31 |
+
UpdateNewMessage,
|
32 |
+
UpdateGroupInvitePrivacyForbidden,
|
33 |
+
UpdatePrivacy,
|
34 |
+
UpdateUserName,
|
35 |
+
UpdatePinnedMessages,
|
36 |
+
PeerUser,
|
37 |
+
MessageService,
|
38 |
+
PrivacyKeyProfilePhoto,
|
39 |
+
PrivacyValueDisallowAll,
|
40 |
+
PrivacyValueAllowAll,
|
41 |
+
PrivacyKeyChatInvite,
|
42 |
+
Username,
|
43 |
+
Channel,
|
44 |
+
ChatForbidden,
|
45 |
+
ChannelForbidden,
|
46 |
+
)
|
47 |
+
|
48 |
+
LOGS = logging.getLogger(__name__)
|
49 |
+
|
50 |
+
async def send_log(client, text):
|
51 |
+
return await assistant.send_message(
|
52 |
+
client.me.id,
|
53 |
+
text,
|
54 |
+
disable_web_page_preview=True,
|
55 |
+
reply_markup=InlineKeyboardMarkup([
|
56 |
+
[InlineKeyboardButton("View User", url=f"tg://openmessage?user_id={client.me.id}")]
|
57 |
+
])
|
58 |
+
)
|
59 |
+
|
60 |
+
@Client.on_raw_update()
|
61 |
+
async def check_raw(client: Client, update, users, chats):
|
62 |
+
if isinstance(update, UpdateGroupInvitePrivacyForbidden):
|
63 |
+
LOGS.info(f"Update Invite: {update}")
|
64 |
+
|
65 |
+
elif isinstance(update, UpdatePinnedMessages):
|
66 |
+
if not update:
|
67 |
+
return
|
68 |
+
peer = update.peer
|
69 |
+
if isinstance(peer, PeerUser):
|
70 |
+
if getattr(update, "pinned", False):
|
71 |
+
message_ids = ", ".join(str(msg_id) for msg_id in update.messages)
|
72 |
+
return await assistant.send_message(
|
73 |
+
client.me.id,
|
74 |
+
"#PINNED_MESSAGE_PM_ALERT\n\n"
|
75 |
+
f"**User ID:** `{peer.user_id}`\n",
|
76 |
+
disable_web_page_preview=True,
|
77 |
+
reply_markup=InlineKeyboardMarkup([
|
78 |
+
[InlineKeyboardButton("View User PM", url=f"tg://openmessage?user_id={peer.user_id}&message_id={message_ids}")]
|
79 |
+
])
|
80 |
+
)
|
81 |
+
|
82 |
+
elif isinstance(update, UpdatePrivacy):
|
83 |
+
if not update:
|
84 |
+
return
|
85 |
+
if isinstance(update.key, PrivacyKeyChatInvite):
|
86 |
+
for rule in update.rules:
|
87 |
+
if isinstance(rule, PrivacyValueDisallowAll):
|
88 |
+
return await send_log(
|
89 |
+
client,
|
90 |
+
"#PRIVACY_CHANGED_ALERT\n\n"
|
91 |
+
"**Reason:** π Does not allow anyone to accept group invitations."
|
92 |
+
)
|
93 |
+
elif isinstance(rule, PrivacyValueAllowAll):
|
94 |
+
return await send_log(
|
95 |
+
client,
|
96 |
+
"#PRIVACY_CHANGED_ALERT\n\n"
|
97 |
+
"**Reason:** β
Allows everyone to receive group invitations."
|
98 |
+
)
|
99 |
+
elif isinstance(update.key, PrivacyKeyProfilePhoto):
|
100 |
+
for rule in update.rules:
|
101 |
+
if isinstance(rule, PrivacyValueDisallowAll):
|
102 |
+
return await send_log(
|
103 |
+
client,
|
104 |
+
"#PRIVACY_CHANGED_ALERT\n\n"
|
105 |
+
"**Reason:** π Does not allow anyone to accept Profile Photo"
|
106 |
+
)
|
107 |
+
elif isinstance(rule, PrivacyValueAllowAll):
|
108 |
+
return await send_log(
|
109 |
+
client,
|
110 |
+
"#PRIVACY_CHANGED_ALERT\n\n"
|
111 |
+
"**Reason:** β
Allows everyone to receive Profile Photo"
|
112 |
+
)
|
113 |
+
|
114 |
+
elif isinstance(update, UpdateUserName):
|
115 |
+
if not update:
|
116 |
+
return
|
117 |
+
first_name = update.first_name
|
118 |
+
user_id = update.user_id
|
119 |
+
usernames = update.usernames
|
120 |
+
for username in usernames:
|
121 |
+
if isinstance(username, Username):
|
122 |
+
return await assistant.send_message(
|
123 |
+
client.me.id,
|
124 |
+
"#NAME_CHANGED_ALERT\n\n"
|
125 |
+
f"**First Name:** `{first_name}`\n"
|
126 |
+
f"**User ID:** `{user_id}`\n"
|
127 |
+
f"**Username:** <spoiler>{username.username}</spoiler>\n"
|
128 |
+
f"**Editable:** {username.editable}\n",
|
129 |
+
disable_web_page_preview=True,
|
130 |
+
reply_markup=InlineKeyboardMarkup([
|
131 |
+
[InlineKeyboardButton("View User", url=f"tg://openmessage?user_id={user_id}")]
|
132 |
+
])
|
133 |
+
)
|
134 |
+
elif isinstance(update, UpdateNewMessage):
|
135 |
+
message = update.message
|
136 |
+
if isinstance(message, MessageService):
|
137 |
+
return
|
138 |
+
if not message:
|
139 |
+
return
|
140 |
+
peer = message.peer_id
|
141 |
+
if not hasattr(peer, "user_id"):
|
142 |
+
return
|
143 |
+
user_id = peer.user_id
|
144 |
+
if user_id == client.me.id:
|
145 |
+
return
|
146 |
+
user = users.get(user_id)
|
147 |
+
if user and getattr(user, "bot", False):
|
148 |
+
return
|
149 |
+
return await assistant.send_message(
|
150 |
+
client.me.id,
|
151 |
+
f"#NEW_MESSAGE_PM_ALERT\n\n"
|
152 |
+
f"**User:** `{user_id}`\n"
|
153 |
+
f"**Message ID:** {message.id}\n"
|
154 |
+
f"**Message:** `{message.message}`\n",
|
155 |
+
disable_web_page_preview=True,
|
156 |
+
reply_markup=InlineKeyboardMarkup(
|
157 |
+
[[
|
158 |
+
InlineKeyboardButton(
|
159 |
+
"View Message",
|
160 |
+
url=f"tg://openmessage?user_id={user_id}&message_id={message.id}"
|
161 |
+
)
|
162 |
+
]]
|
163 |
+
)
|
164 |
+
)
|
165 |
+
for cid, chat in chats.items():
|
166 |
+
if isinstance(chat, ChannelForbidden):
|
167 |
+
await assistant.send_message(
|
168 |
+
client.me.id,
|
169 |
+
f"#BANNED_ALERT\n"
|
170 |
+
f"**Channel:** {chat.title}\n"
|
171 |
+
f"**ID:** `{cid}`\n"
|
172 |
+
f"**Access hash:** <spoiler>{chat.access_hash}</spoiler>\n"
|
173 |
+
f"**Type:** Channel\n"
|
174 |
+
f"**Reason:** Banned from channel",
|
175 |
+
disable_web_page_preview=True,
|
176 |
+
reply_markup=InlineKeyboardMarkup(
|
177 |
+
[[
|
178 |
+
InlineKeyboardButton(
|
179 |
+
"View Channel",
|
180 |
+
url=f"https://t.me/c/{cid}/1"
|
181 |
+
)
|
182 |
+
]]
|
183 |
+
)
|
184 |
+
)
|
185 |
+
elif isinstance(chat, ChatForbidden):
|
186 |
+
await assistant.send_message(
|
187 |
+
client.me.id,
|
188 |
+
f"#BANNED_ALERT\n"
|
189 |
+
f"**Chat:** {chat.title}\n"
|
190 |
+
f"**ID:** `{cid}`\n"
|
191 |
+
f"**Access hash:** <spoiler>{chat.access_hash}</spoiler>\n"
|
192 |
+
f"**Type:** Group\n"
|
193 |
+
f"**Reason:** Banned from group",
|
194 |
+
disable_web_page_preview=True,
|
195 |
+
reply_markup=InlineKeyboardMarkup(
|
196 |
+
[[
|
197 |
+
InlineKeyboardButton(
|
198 |
+
"View Group",
|
199 |
+
url=f"https://t.me/c/{cid}/1"
|
200 |
+
)
|
201 |
+
]]
|
202 |
+
)
|
203 |
+
)
|
204 |
+
elif isinstance(chat, Channel) and getattr(chat, "left", False):
|
205 |
+
await assistant.send_message(
|
206 |
+
client.me.id,
|
207 |
+
f"#UNBANNED #LEFT_ALERT\n"
|
208 |
+
f"**Channel:** {chat.title}\n"
|
209 |
+
f"**Date:** {chat.date}\n"
|
210 |
+
f"**ID:** `{cid}`\n"
|
211 |
+
f"**Username:** <spoiler>{chat.username if chat else None}</spoiler>\n"
|
212 |
+
f"**Access hash:** <spoiler>{chat.access_hash}</spoiler>\n",
|
213 |
+
disable_web_page_preview=True,
|
214 |
+
reply_markup=InlineKeyboardMarkup(
|
215 |
+
[[
|
216 |
+
InlineKeyboardButton(
|
217 |
+
"View Channel",
|
218 |
+
url=f"https://t.me/c/{cid}/1"
|
219 |
+
)
|
220 |
+
]]
|
221 |
+
)
|
222 |
+
)
|
223 |
+
elif isinstance(chat, Channel) and getattr(chat, "restricted", False):
|
224 |
+
await assistant.send_message(
|
225 |
+
client.me.id,
|
226 |
+
f"#RESTRICTED_ALERT\n"
|
227 |
+
f"**Channel:** {chat.title}\n"
|
228 |
+
f"**Date:** {chat.date}\n"
|
229 |
+
f"**ID:** `{cid}`\n"
|
230 |
+
f"**Username:** <spoiler>{chat.username if chat else None}</spoiler>\n"
|
231 |
+
f"**Access hash:** {chat.access_hash}\n",
|
232 |
+
disable_web_page_preview=True,
|
233 |
+
reply_markup=InlineKeyboardMarkup(
|
234 |
+
[[
|
235 |
+
InlineKeyboardButton(
|
236 |
+
"View Channel",
|
237 |
+
url=f"https://t.me/c/{cid}/1"
|
238 |
+
)
|
239 |
+
]]
|
240 |
+
)
|
241 |
+
)
|
242 |
+
elif isinstance(chat, Channel) and getattr(chat, "scam", False):
|
243 |
+
await assistant.send_message(
|
244 |
+
client.me.id,
|
245 |
+
f"#SCAM_ALERT\n"
|
246 |
+
f"**Channel:** {chat.title}\n"
|
247 |
+
f"**Date:** {chat.date}\n"
|
248 |
+
f"**ID:** `{cid}`\n"
|
249 |
+
f"**Username:** <spoiler>{chat.username if chat else None}</spoiler>\n"
|
250 |
+
f"**Access hash:** {chat.access_hash}\n",
|
251 |
+
disable_web_page_preview=True,
|
252 |
+
reply_markup=InlineKeyboardMarkup(
|
253 |
+
[[
|
254 |
+
InlineKeyboardButton(
|
255 |
+
"View Channel",
|
256 |
+
url=f"https://t.me/c/{cid}/1"
|
257 |
+
)
|
258 |
+
]]
|
259 |
+
)
|
260 |
+
)
|