Merge pull request #36 from Infamous-Hydra/Infamous-Hydra-patch-8
Browse files- Mikobot/plugins/ban.py +629 -926
Mikobot/plugins/ban.py
CHANGED
@@ -1,1045 +1,748 @@
|
|
1 |
# <============================================== IMPORTS =========================================================>
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
from pyrogram.errors import (
|
7 |
-
ChatAdminRequired,
|
8 |
-
PeerIdInvalid,
|
9 |
-
RightForbidden,
|
10 |
-
RPCError,
|
11 |
-
UserAdminInvalid,
|
12 |
-
)
|
13 |
-
from pyrogram.filters import regex
|
14 |
-
from pyrogram.types import (
|
15 |
-
CallbackQuery,
|
16 |
InlineKeyboardButton,
|
17 |
InlineKeyboardMarkup,
|
18 |
-
|
19 |
)
|
20 |
-
|
21 |
-
from
|
22 |
-
from
|
23 |
-
from
|
24 |
-
|
25 |
-
from Mikobot
|
26 |
-
from Mikobot.utils.
|
27 |
-
from Mikobot.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
# <=======================================================================================================>
|
30 |
|
31 |
|
32 |
# <================================================ FUNCTION =======================================================>
|
33 |
-
@
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
)
|
55 |
-
LOGGER.info(
|
56 |
-
f"{m.from_user.id} trying to ban {user_id} (SUPPORT_STAFF) in {m.chat.id}",
|
57 |
-
)
|
58 |
-
await m.stop_propagation()
|
59 |
-
|
60 |
-
r_id = m.reply_to_message.id if m.reply_to_message else m.id
|
61 |
-
|
62 |
-
if m.reply_to_message and len(m.text.split()) >= 2:
|
63 |
-
reason = m.text.split(None, 1)[1]
|
64 |
-
elif not m.reply_to_message and len(m.text.split()) >= 3:
|
65 |
-
reason = m.text.split(None, 2)[2]
|
66 |
-
else:
|
67 |
-
await m.reply_text("Read /help !!")
|
68 |
-
return
|
69 |
-
|
70 |
-
if not reason:
|
71 |
-
await m.reply_text("You haven't specified a time to ban this user for!")
|
72 |
-
return
|
73 |
-
|
74 |
-
split_reason = reason.split(None, 1)
|
75 |
-
time_val = split_reason[0].lower()
|
76 |
-
reason = split_reason[1] if len(split_reason) > 1 else ""
|
77 |
-
|
78 |
-
bantime = await extract_time(m, time_val)
|
79 |
-
|
80 |
-
if not bantime:
|
81 |
-
return
|
82 |
-
|
83 |
-
try:
|
84 |
-
admins_group = {i[0] for i in ADMIN_CACHE[m.chat.id]}
|
85 |
-
except KeyError:
|
86 |
-
admins_group = await admin_cache_reload(m, "ban")
|
87 |
-
|
88 |
-
if user_id in admins_group:
|
89 |
-
await m.reply_text(text="This user is an admin, I cannot ban them!")
|
90 |
-
await m.stop_propagation()
|
91 |
-
|
92 |
-
try:
|
93 |
-
admin = await mention_html(m.from_user.first_name, m.from_user.id)
|
94 |
-
banned = await mention_html(user_first_name, user_id)
|
95 |
-
chat_title = m.chat.title
|
96 |
-
LOGGER.info(f"{m.from_user.id} tbanned {user_id} in {m.chat.id}")
|
97 |
-
await m.chat.ban_member(user_id, until_date=bantime)
|
98 |
-
t_t = (f"{admin} banned {banned} in <b>{chat_title}</b>!",)
|
99 |
-
txt = t_t
|
100 |
-
if type(t_t) is tuple:
|
101 |
-
txt = t_t[
|
102 |
-
0
|
103 |
-
] # Done this bcuz idk why t_t is tuple type data. SO now if it is tuple this will get text from it
|
104 |
-
if reason:
|
105 |
-
txt += f"\n<b>Reason</b>: {reason}"
|
106 |
-
else:
|
107 |
-
txt += "\n<b>Reason</b>: Not Specified"
|
108 |
-
if time_val:
|
109 |
-
txt += f"\n<b>Banned for</b>:{time_val}"
|
110 |
-
keyboard = InlineKeyboardMarkup(
|
111 |
-
[
|
112 |
-
[
|
113 |
-
InlineKeyboardButton(
|
114 |
-
"UNBAN",
|
115 |
-
callback_data=f"unban_={user_id}",
|
116 |
-
),
|
117 |
-
],
|
118 |
-
],
|
119 |
-
)
|
120 |
-
anim = choice(BAN_GIFS)
|
121 |
try:
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
135 |
)
|
136 |
-
|
137 |
-
# await m.reply_text(txt, reply_markup=keyboard,
|
138 |
-
# reply_to_message_id=r_id)
|
139 |
-
except ChatAdminRequired:
|
140 |
-
await m.reply_text(text="I'm not admin or I don't have rights.")
|
141 |
-
except PeerIdInvalid:
|
142 |
-
await m.reply_text(
|
143 |
-
"I have not seen this user yet...!\nMind forwarding one of their message so I can recognize them?",
|
144 |
)
|
145 |
-
|
146 |
-
|
147 |
-
|
|
|
148 |
)
|
149 |
-
|
150 |
-
await m.reply_text(text="I don't have enough rights to ban this user.")
|
151 |
-
except RPCError as ef:
|
152 |
-
await m.reply_text(
|
153 |
-
(
|
154 |
-
f"""Some error occured, report it using `/bug`
|
155 |
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
LOGGER.error(ef)
|
160 |
-
LOGGER.error(format_exc())
|
161 |
-
return
|
162 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
163 |
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
|
170 |
-
|
171 |
-
user_id, _, _ = await extract_user(c, m)
|
172 |
-
except Exception:
|
173 |
-
return
|
174 |
-
|
175 |
-
if not user_id:
|
176 |
-
await m.reply_text("Cannot find user to ban")
|
177 |
-
return
|
178 |
-
if user_id == BOT_ID:
|
179 |
-
await m.reply_text("What the heck? Why would I ban myself?")
|
180 |
-
await m.stop_propagation()
|
181 |
|
182 |
-
if
|
183 |
-
|
184 |
-
|
185 |
-
)
|
186 |
-
LOGGER.info(
|
187 |
-
f"{m.from_user.id} trying to ban {user_id} (SUPPORT_STAFF) in {m.chat.id}",
|
188 |
-
)
|
189 |
-
await m.stop_propagation()
|
190 |
|
191 |
-
if m.reply_to_message and len(m.text.split()) >= 2:
|
192 |
-
reason = m.text.split(None, 1)[1]
|
193 |
-
elif not m.reply_to_message and len(m.text.split()) >= 3:
|
194 |
-
reason = m.text.split(None, 2)[2]
|
195 |
else:
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
if not reason:
|
200 |
-
await m.reply_text("You haven't specified a time to ban this user for!")
|
201 |
-
return
|
202 |
-
|
203 |
-
split_reason = reason.split(None, 1)
|
204 |
-
time_val = split_reason[0].lower()
|
205 |
-
reason = split_reason[1] if len(split_reason) > 1 else ""
|
206 |
-
|
207 |
-
bantime = await extract_time(m, time_val)
|
208 |
|
209 |
-
if
|
210 |
-
|
211 |
|
212 |
try:
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
if user_id in admins_group:
|
218 |
-
await m.reply_text(text="This user is an admin, I cannot ban them!")
|
219 |
-
await m.stop_propagation()
|
220 |
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
await m.reply_to_message.delete()
|
227 |
-
return
|
228 |
-
return
|
229 |
-
except ChatAdminRequired:
|
230 |
-
await m.reply_text(text="I'm not admin or I don't have rights.")
|
231 |
-
except PeerIdInvalid:
|
232 |
-
await m.reply_text(
|
233 |
-
"I have not seen this user yet...!\nMind forwarding one of their message so I can recognize them?",
|
234 |
-
)
|
235 |
-
except UserAdminInvalid:
|
236 |
-
await m.reply_text(
|
237 |
-
text="Cannot act on this user, maybe I wasn't the one who changed their permissions."
|
238 |
-
)
|
239 |
-
except RightForbidden:
|
240 |
-
await m.reply_text(text="I don't have enough rights to ban this user.")
|
241 |
-
except RPCError as ef:
|
242 |
-
await m.reply_text(
|
243 |
-
text=f"""Some error occured, report it using `/bug`
|
244 |
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
251 |
|
252 |
-
|
253 |
-
async def dtban_usr(c: app, m: Message):
|
254 |
-
if len(m.text.split()) == 1 and not m.reply_to_message:
|
255 |
-
await m.reply_text(text="I can't ban nothing!")
|
256 |
-
await m.stop_propagation()
|
257 |
|
258 |
-
if not m.reply_to_message:
|
259 |
-
await m.reply_text(
|
260 |
-
"Reply to a message with this command to temp ban and delete the message.",
|
261 |
-
)
|
262 |
-
await m.stop_propagation()
|
263 |
|
264 |
-
|
265 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
266 |
|
267 |
if not user_id:
|
268 |
-
await
|
269 |
-
return
|
270 |
-
if user_id == BOT_ID:
|
271 |
-
await m.reply_text("Huh, why would I ban myself?")
|
272 |
-
await m.stop_propagation()
|
273 |
-
|
274 |
-
if user_id in SUPPORT_STAFF:
|
275 |
-
await m.reply_text(text="I am not going to ban one of my support staff")
|
276 |
-
LOGGER.info(
|
277 |
-
f"{m.from_user.id} trying to ban {user_id} (SUPPORT_STAFF) in {m.chat.id}",
|
278 |
-
)
|
279 |
-
await m.stop_propagation()
|
280 |
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
await
|
287 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
288 |
|
289 |
if not reason:
|
290 |
-
await
|
291 |
-
return
|
292 |
|
293 |
split_reason = reason.split(None, 1)
|
|
|
294 |
time_val = split_reason[0].lower()
|
295 |
reason = split_reason[1] if len(split_reason) > 1 else ""
|
296 |
-
|
297 |
-
bantime = await extract_time(m, time_val)
|
298 |
|
299 |
if not bantime:
|
300 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
301 |
|
302 |
try:
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
await
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
if
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
if bantime:
|
325 |
-
txt += f"\n<b>Banned for</b>: {time_val}"
|
326 |
-
keyboard = InlineKeyboardMarkup(
|
327 |
-
[
|
328 |
-
[
|
329 |
-
InlineKeyboardButton(
|
330 |
-
"UNBAN",
|
331 |
-
callback_data=f"unban_={user_id}",
|
332 |
-
),
|
333 |
-
],
|
334 |
-
],
|
335 |
-
)
|
336 |
-
anim = choice(BAN_GIFS)
|
337 |
-
try:
|
338 |
-
await m.reply_animation(
|
339 |
-
animation=str(anim),
|
340 |
-
caption=txt,
|
341 |
-
reply_markup=keyboard,
|
342 |
-
parse_mode=enums.ParseMode.HTML,
|
343 |
-
)
|
344 |
-
except Exception:
|
345 |
-
await m.reply_text(
|
346 |
-
txt,
|
347 |
-
reply_markup=keyboard,
|
348 |
-
parse_mode=enums.ParseMode.HTML,
|
349 |
)
|
350 |
-
|
351 |
-
# await c.send_message(m.chat.id, txt, reply_markup=keyboard)
|
352 |
-
except ChatAdminRequired:
|
353 |
-
await m.reply_text(text="I'm not admin or I don't have rights.")
|
354 |
-
except PeerIdInvalid:
|
355 |
-
await m.reply_text(
|
356 |
-
"I have not seen this user yet...!\nMind forwarding one of their message so I can recognize them?",
|
357 |
-
)
|
358 |
-
except UserAdminInvalid:
|
359 |
-
await m.reply_text(
|
360 |
-
text="Cannot act on this user, maybe I wasn't the one who changed their permissions."
|
361 |
-
)
|
362 |
-
except RightForbidden:
|
363 |
-
await m.reply_text(text="I don't have enough rights to ban this user.")
|
364 |
-
except RPCError as ef:
|
365 |
-
await m.reply_text(
|
366 |
-
text=f"""Some error occured, report it using `/bug`
|
367 |
-
|
368 |
-
<b>Error:</b> <code>{ef}</code>"""
|
369 |
-
)
|
370 |
-
LOGGER.error(ef)
|
371 |
-
LOGGER.error(format_exc())
|
372 |
-
return
|
373 |
-
|
374 |
-
|
375 |
-
@app.on_message(command("kick") & restrict_filter)
|
376 |
-
async def kick_usr(c: app, m: Message):
|
377 |
-
if len(m.text.split()) == 1 and not m.reply_to_message:
|
378 |
-
await m.reply_text(text="I can't kick nothing!")
|
379 |
-
return
|
380 |
-
|
381 |
-
reason = None
|
382 |
-
|
383 |
-
if m.reply_to_message:
|
384 |
-
r_id = m.reply_to_message.id
|
385 |
-
if len(m.text.split()) >= 2:
|
386 |
-
reason = m.text.split(None, 1)[1]
|
387 |
-
else:
|
388 |
-
r_id = m.id
|
389 |
-
if len(m.text.split()) >= 3:
|
390 |
-
reason = m.text.split(None, 2)[2]
|
391 |
-
try:
|
392 |
-
user_id, user_first_name, _ = await extract_user(c, m)
|
393 |
-
except Exception:
|
394 |
-
return
|
395 |
-
|
396 |
-
if not user_id:
|
397 |
-
await m.reply_text("Cannot find user to kick")
|
398 |
-
return
|
399 |
-
|
400 |
-
if user_id == BOT_ID:
|
401 |
-
await m.reply_text("Huh, why would I kick myself?")
|
402 |
-
await m.stop_propagation()
|
403 |
-
|
404 |
-
if user_id in SUPPORT_STAFF:
|
405 |
-
await m.reply_text(
|
406 |
-
text="This user is in my support staff, cannot restrict them."
|
407 |
-
)
|
408 |
-
LOGGER.info(
|
409 |
-
f"{m.from_user.id} trying to kick {user_id} (SUPPORT_STAFF) in {m.chat.id}",
|
410 |
-
)
|
411 |
-
await m.stop_propagation()
|
412 |
-
|
413 |
-
try:
|
414 |
-
admins_group = {i[0] for i in ADMIN_CACHE[m.chat.id]}
|
415 |
-
except KeyError:
|
416 |
-
admins_group = await admin_cache_reload(m, "kick")
|
417 |
-
|
418 |
-
if user_id in admins_group:
|
419 |
-
await m.reply_text(text="This user is an admin, I cannot kick them!")
|
420 |
-
await m.stop_propagation()
|
421 |
-
|
422 |
-
try:
|
423 |
-
admin = await mention_html(m.from_user.first_name, m.from_user.id)
|
424 |
-
kicked = await mention_html(user_first_name, user_id)
|
425 |
-
chat_title = m.chat.title
|
426 |
-
LOGGER.info(f"{m.from_user.id} kicked {user_id} in {m.chat.id}")
|
427 |
-
await m.chat.ban_member(user_id)
|
428 |
-
txt = f"{admin} kicked {kicked} in <b>{chat_title}</b>!"
|
429 |
-
if reason:
|
430 |
-
txt += f"\n<b>Reason</b>: {reason}"
|
431 |
else:
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
caption=txt,
|
440 |
-
parse_mode=enums.ParseMode.HTML,
|
441 |
)
|
442 |
-
|
443 |
-
await m.reply_text(
|
444 |
-
reply_to_message_id=r_id,
|
445 |
-
text=txt,
|
446 |
-
parse_mode=enums.ParseMode.HTML,
|
447 |
-
)
|
448 |
-
await c.send_message(MESSAGE_DUMP, f"#REMOVE from KICK_GFIS\n{kickk}")
|
449 |
-
await m.chat.unban_member(user_id)
|
450 |
-
except ChatAdminRequired:
|
451 |
-
await m.reply_text(text="I'm not admin or I don't have rights.")
|
452 |
-
except PeerIdInvalid:
|
453 |
-
await m.reply_text(
|
454 |
-
"I have not seen this user yet...!\nMind forwarding one of their message so I can recognize them?",
|
455 |
-
)
|
456 |
-
except UserAdminInvalid:
|
457 |
-
await m.reply_text(
|
458 |
-
text="Cannot act on this user, maybe I wasn't the one who changed their permissions."
|
459 |
-
)
|
460 |
-
except RightForbidden:
|
461 |
-
await m.reply_text(text="I don't have enough rights to ban this user.")
|
462 |
-
except RPCError as ef:
|
463 |
-
await m.reply_text(
|
464 |
-
text=f"""Some error occured, report it using `/bug`
|
465 |
|
466 |
-
|
467 |
-
)
|
468 |
-
LOGGER.error(ef)
|
469 |
-
LOGGER.error(format_exc())
|
470 |
-
|
471 |
-
return
|
472 |
|
473 |
|
474 |
-
@
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
|
485 |
if not user_id:
|
486 |
-
await
|
487 |
-
return
|
488 |
-
|
489 |
-
if user_id == BOT_ID:
|
490 |
-
await m.reply_text("Huh, why would I kick myself?")
|
491 |
-
await m.stop_propagation()
|
492 |
-
|
493 |
-
if user_id in SUPPORT_STAFF:
|
494 |
-
await m.reply_text(
|
495 |
-
text="This user is in my support staff, cannot restrict them."
|
496 |
-
)
|
497 |
-
LOGGER.info(
|
498 |
-
f"{m.from_user.id} trying to skick {user_id} (SUPPORT_STAFF) in {m.chat.id}",
|
499 |
-
)
|
500 |
-
await m.stop_propagation()
|
501 |
-
|
502 |
-
try:
|
503 |
-
admins_group = {i[0] for i in ADMIN_CACHE[m.chat.id]}
|
504 |
-
except KeyError:
|
505 |
-
admins_group = await admin_cache_reload(m, "kick")
|
506 |
-
|
507 |
-
if user_id in admins_group:
|
508 |
-
await m.reply_text(text="This user is an admin, I cannot kick them!")
|
509 |
-
await m.stop_propagation()
|
510 |
|
511 |
try:
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
await
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
523 |
)
|
524 |
-
|
525 |
-
|
526 |
-
text="Cannot act on this user, maybe I wasn't the one who changed their permissions."
|
527 |
-
)
|
528 |
-
except RightForbidden:
|
529 |
-
await m.reply_text(text="I don't have enough rights to kick this user.")
|
530 |
-
except RPCError as ef:
|
531 |
-
await m.reply_text(
|
532 |
-
text=f"""Some error occured, report it using `/bug`
|
533 |
-
|
534 |
-
<b>Error:</b> <code>{ef}</code>"""
|
535 |
-
)
|
536 |
-
LOGGER.error(ef)
|
537 |
-
LOGGER.error(format_exc())
|
538 |
-
|
539 |
-
return
|
540 |
|
|
|
541 |
|
542 |
-
|
543 |
-
|
544 |
-
if len(m.text.split()) == 1 and not m.reply_to_message:
|
545 |
-
await m.reply_text(text="I can't ban nothing!")
|
546 |
-
return
|
547 |
-
if not m.reply_to_message:
|
548 |
-
return await m.reply_text("Reply to a message to delete it and kick the user!")
|
549 |
|
550 |
-
|
551 |
|
552 |
-
user_id = m.reply_to_message.from_user.id
|
553 |
-
user_first_name = m.reply_to_message.from_user.first_name
|
554 |
|
555 |
-
|
556 |
-
|
|
|
|
|
|
|
|
|
|
|
557 |
return
|
558 |
|
559 |
-
|
560 |
-
|
561 |
-
|
562 |
-
|
563 |
-
if
|
564 |
-
await
|
565 |
-
|
566 |
)
|
567 |
-
|
568 |
-
|
569 |
-
)
|
570 |
-
await m.stop_propagation()
|
571 |
|
572 |
-
try:
|
573 |
-
admins_group = {i[0] for i in ADMIN_CACHE[m.chat.id]}
|
574 |
-
except KeyError:
|
575 |
-
admins_group = await admin_cache_reload(m, "kick")
|
576 |
|
577 |
-
|
578 |
-
|
579 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
580 |
|
581 |
-
|
582 |
-
LOGGER.info(f"{m.from_user.id} dkicked {user_id} in {m.chat.id}")
|
583 |
-
await m.reply_to_message.delete()
|
584 |
-
await m.chat.ban_member(user_id)
|
585 |
-
admin = await mention_html(m.from_user.first_name, m.from_user.id)
|
586 |
-
kicked = await mention_html(user_first_name, user_id)
|
587 |
-
chat_title = m.chat.title
|
588 |
-
txt = f"{admin} kicked {kicked} in <b>{chat_title}</b>!"
|
589 |
-
if reason:
|
590 |
-
txt += f"\n<b>Reason</b>: {reason}"
|
591 |
-
else:
|
592 |
-
txt += "\n<b>Reason</b>: Not Specified"
|
593 |
-
kickk = choice(KICK_GIFS)
|
594 |
try:
|
595 |
-
|
596 |
-
|
597 |
-
|
598 |
-
parse_mode=enums.ParseMode.HTML,
|
599 |
-
)
|
600 |
-
except:
|
601 |
-
await m.reply_text(
|
602 |
-
txt,
|
603 |
-
parse_mode=enums.ParseMode.HTML,
|
604 |
-
)
|
605 |
-
await c.send_message(MESSAGE_DUMP, f"#REMOVE from KICK_GFIS\n{kickk}")
|
606 |
-
await m.chat.unban_member(user_id)
|
607 |
-
except ChatAdminRequired:
|
608 |
-
await m.reply_text(text="I'm not admin or I don't have rights.")
|
609 |
-
except PeerIdInvalid:
|
610 |
-
await m.reply_text(
|
611 |
-
"I have not seen this user yet...!\nMind forwarding one of their message so I can recognize them?",
|
612 |
-
)
|
613 |
-
except UserAdminInvalid:
|
614 |
-
await m.reply_text(
|
615 |
-
text="Cannot act on this user, maybe I wasn't the one who changed their permissions."
|
616 |
-
)
|
617 |
-
except RightForbidden:
|
618 |
-
await m.reply_text(text="I don't have enough rights to kick this user.")
|
619 |
-
except RPCError as ef:
|
620 |
-
await m.reply_text(
|
621 |
-
text=f"""Some error occured, report it using `/bug`
|
622 |
|
623 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
624 |
)
|
625 |
-
LOGGER.error(ef)
|
626 |
-
LOGGER.error(format_exc())
|
627 |
|
628 |
-
|
629 |
|
|
|
|
|
|
|
630 |
|
631 |
-
|
632 |
-
|
633 |
-
|
634 |
-
await m.reply_text(text="I can't unban nothing!")
|
635 |
-
await m.stop_propagation()
|
636 |
|
637 |
-
if
|
638 |
-
|
639 |
-
|
640 |
-
m.reply_to_message.sender_chat.title,
|
641 |
-
)
|
642 |
else:
|
|
|
643 |
try:
|
644 |
-
|
645 |
-
|
646 |
-
|
647 |
-
|
648 |
-
|
649 |
-
|
650 |
-
|
651 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
652 |
else:
|
653 |
-
|
654 |
-
|
655 |
-
|
656 |
-
statu = (await m.chat.get_member(user_id)).status
|
657 |
-
if statu not in [
|
658 |
-
enums.ChatMemberStatus.BANNED,
|
659 |
-
enums.ChatMemberStatus.RESTRICTED,
|
660 |
-
]:
|
661 |
-
await m.reply_text(
|
662 |
-
"User is not banned in this chat\nOr using this command as reply to his message"
|
663 |
-
)
|
664 |
-
return
|
665 |
-
except Exception as e:
|
666 |
-
LOGGER.error(e)
|
667 |
-
LOGGER.exception(format_exc())
|
668 |
-
try:
|
669 |
-
await m.chat.unban_member(user_id)
|
670 |
-
admin = m.from_user.mention
|
671 |
-
unbanned = await mention_html(user_first_name, user_id)
|
672 |
-
chat_title = (m.chat.title,)
|
673 |
-
txt = f"{admin} unbanned {unbanned} in chat <b>{chat_title}</b>!"
|
674 |
-
if reason:
|
675 |
-
txt += f"\n<b>Reason</b>: {reason}"
|
676 |
-
else:
|
677 |
-
txt += "\n<b>Reason</b>: Not Specified"
|
678 |
-
await m.reply_text(txt)
|
679 |
-
except ChatAdminRequired:
|
680 |
-
await m.reply_text(text="I'm not admin or I don't have rights.")
|
681 |
-
except RightForbidden:
|
682 |
-
await m.reply_text(text="I don't have enough rights to unban this user.")
|
683 |
-
except RPCError as ef:
|
684 |
-
await m.reply_text(
|
685 |
-
text=f"""Some error occured, report it using `/bug`
|
686 |
-
|
687 |
-
<b>Error:</b> <code>{ef}</code>"""
|
688 |
-
)
|
689 |
-
LOGGER.error(ef)
|
690 |
-
LOGGER.error(format_exc())
|
691 |
|
692 |
-
|
|
|
693 |
|
|
|
694 |
|
695 |
-
@app.on_message(command("sban") & restrict_filter)
|
696 |
-
async def sban_usr(c: app, m: Message):
|
697 |
-
if len(m.text.split()) == 1 and not m.reply_to_message:
|
698 |
-
await m.reply_text(text="I can't ban nothing!")
|
699 |
-
await m.stop_propagation()
|
700 |
|
701 |
-
|
702 |
-
|
703 |
-
|
704 |
-
|
705 |
-
|
706 |
-
|
707 |
-
|
708 |
-
|
709 |
-
if not user_id:
|
710 |
-
await m.reply_text("Cannot find user to ban")
|
711 |
return
|
712 |
-
if user_id == m.chat.id:
|
713 |
-
await m.reply_text("That's an admin!")
|
714 |
-
await m.stop_propagation()
|
715 |
-
if user_id == BOT_ID:
|
716 |
-
await m.reply_text("Huh, why would I ban myself?")
|
717 |
-
await m.stop_propagation()
|
718 |
-
|
719 |
-
if user_id in SUPPORT_STAFF:
|
720 |
-
await m.reply_text(
|
721 |
-
text="This user is in my support staff, cannot restrict them."
|
722 |
-
)
|
723 |
-
LOGGER.info(
|
724 |
-
f"{m.from_user.id} trying to sban {user_id} (SUPPORT_STAFF) in {m.chat.id}",
|
725 |
-
)
|
726 |
-
await m.stop_propagation()
|
727 |
|
728 |
try:
|
729 |
-
|
730 |
-
except
|
731 |
-
|
|
|
732 |
|
733 |
-
|
734 |
-
await m.reply_text(text="This user is an admin, I cannot ban them!")
|
735 |
-
await m.stop_propagation()
|
736 |
|
737 |
try:
|
738 |
-
|
739 |
-
|
740 |
-
|
741 |
-
|
742 |
-
|
743 |
-
|
744 |
-
|
745 |
-
except PeerIdInvalid:
|
746 |
-
await m.reply_text(
|
747 |
-
"I have not seen this user yet...!\nMind forwarding one of their message so I can recognize them?",
|
748 |
-
)
|
749 |
-
except UserAdminInvalid:
|
750 |
-
await m.reply_text(
|
751 |
-
text="Cannot act on this user, maybe I wasn't the one who changed their permissions."
|
752 |
-
)
|
753 |
-
except RightForbidden:
|
754 |
-
await m.reply_text(text="I don't have enough rights to ban this user.")
|
755 |
-
except RPCError as ef:
|
756 |
-
await m.reply_text(
|
757 |
-
text=f"""Some error occured, report it using `/bug`
|
758 |
-
|
759 |
-
<b>Error:</b> <code>{ef}</code>"""
|
760 |
-
)
|
761 |
-
LOGGER.error(ef)
|
762 |
-
LOGGER.error(format_exc())
|
763 |
-
return
|
764 |
-
|
765 |
|
766 |
-
|
767 |
-
|
768 |
-
|
769 |
-
await m.reply_text(text="I can't ban nothing!")
|
770 |
-
await m.stop_propagation()
|
771 |
|
772 |
-
|
773 |
-
|
774 |
|
775 |
-
|
776 |
-
|
777 |
-
|
778 |
-
|
779 |
-
|
780 |
-
else:
|
781 |
-
user_id, user_first_name = (
|
782 |
-
m.reply_to_message.from_user.id,
|
783 |
-
m.reply_to_message.from_user.first_name,
|
784 |
-
)
|
785 |
|
786 |
-
|
787 |
-
await m.reply_text("Cannot find user to ban")
|
788 |
-
return
|
789 |
-
if user_id == m.chat.id:
|
790 |
-
await m.reply_text("That's an admin!")
|
791 |
-
await m.stop_propagation()
|
792 |
-
if user_id == BOT_ID:
|
793 |
-
await m.reply_text("Huh, why would I ban myself?")
|
794 |
-
await m.stop_propagation()
|
795 |
-
|
796 |
-
if user_id in SUPPORT_STAFF:
|
797 |
-
await m.reply_text(
|
798 |
-
text="This user is in my support staff, cannot restrict them."
|
799 |
-
)
|
800 |
-
LOGGER.info(
|
801 |
-
f"{m.from_user.id} trying to dban {user_id} (SUPPORT_STAFF) in {m.chat.id}",
|
802 |
-
)
|
803 |
-
await m.stop_propagation()
|
804 |
|
805 |
-
try:
|
806 |
-
admins_group = {i[0] for i in ADMIN_CACHE[m.chat.id]}
|
807 |
-
except KeyError:
|
808 |
-
admins_group = await admin_cache_reload(m, "ban")
|
809 |
|
810 |
-
|
811 |
-
|
812 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
813 |
|
814 |
-
|
815 |
-
|
816 |
-
reason = m.text.split(None, 1)[1]
|
817 |
|
818 |
-
|
819 |
-
|
820 |
-
await m.reply_to_message.delete()
|
821 |
-
await m.chat.ban_member(user_id)
|
822 |
-
txt = f"{m.from_user.mention} banned {m.reply_to_message.from_user.mention} in <b>{m.chat.title}</b>!"
|
823 |
-
if reason:
|
824 |
-
txt += f"\n<b>Reason</b>: {reason}"
|
825 |
-
else:
|
826 |
-
txt += "\n<b>Reason</b>: Not Specified"
|
827 |
-
keyboard = InlineKeyboardMarkup(
|
828 |
-
[
|
829 |
-
[
|
830 |
-
InlineKeyboardButton(
|
831 |
-
"UNBAN",
|
832 |
-
callback_data=f"unban_={user_id}",
|
833 |
-
),
|
834 |
-
],
|
835 |
-
],
|
836 |
-
)
|
837 |
-
animm = choice(BAN_GIFS)
|
838 |
try:
|
839 |
-
|
840 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
841 |
)
|
842 |
-
|
843 |
-
|
844 |
-
|
|
|
|
|
845 |
)
|
846 |
-
|
847 |
-
except ChatAdminRequired:
|
848 |
-
await m.reply_text(text="I'm not admin or I don't have rights.")
|
849 |
-
except PeerIdInvalid:
|
850 |
-
await m.reply_text(
|
851 |
-
"I have not seen this user yet...!\nMind forwarding one of their message so I can recognize them?",
|
852 |
-
)
|
853 |
-
except UserAdminInvalid:
|
854 |
-
await m.reply_text(
|
855 |
-
text="Cannot act on this user, maybe I wasn't the one who changed their permissions."
|
856 |
-
)
|
857 |
-
except RightForbidden:
|
858 |
-
await m.reply_text(text="I don't have enough rights to ban this user.")
|
859 |
-
except RPCError as ef:
|
860 |
-
await m.reply_text(
|
861 |
-
text=f"""Some error occured, report it using `/bug`
|
862 |
-
|
863 |
-
<b>Error:</b> <code>{ef}</code>"""
|
864 |
-
)
|
865 |
-
LOGGER.error(ef)
|
866 |
-
LOGGER.error(format_exc())
|
867 |
-
return
|
868 |
|
|
|
|
|
|
|
869 |
|
870 |
-
|
871 |
-
|
872 |
-
|
873 |
-
await m.reply_text(text="I can't ban nothing!")
|
874 |
-
await m.stop_propagation()
|
875 |
|
876 |
-
|
877 |
-
|
878 |
-
|
879 |
-
|
880 |
-
|
881 |
-
|
882 |
-
|
883 |
-
|
884 |
-
|
885 |
-
|
886 |
-
|
887 |
-
|
888 |
-
|
889 |
-
|
890 |
-
|
891 |
-
|
892 |
-
|
893 |
-
|
894 |
-
|
895 |
-
|
896 |
-
|
897 |
-
|
898 |
-
|
899 |
-
|
900 |
-
|
901 |
-
|
902 |
-
|
903 |
-
|
904 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
905 |
|
906 |
-
|
907 |
-
|
908 |
-
|
909 |
-
admins_group = await admin_cache_reload(m, "ban")
|
910 |
-
|
911 |
-
if user_id in admins_group:
|
912 |
-
await m.reply_text(text="This user is an admin, I cannot ban them!")
|
913 |
-
await m.stop_propagation()
|
914 |
-
|
915 |
-
reason = None
|
916 |
-
if m.reply_to_message:
|
917 |
-
r_id = m.reply_to_message.id
|
918 |
-
if len(m.text.split()) >= 2:
|
919 |
-
reason = m.text.split(None, 1)[1]
|
920 |
-
else:
|
921 |
-
r_id = m.id
|
922 |
-
if len(m.text.split()) >= 3:
|
923 |
-
reason = m.text.split(None, 2)[2]
|
924 |
|
925 |
-
try:
|
926 |
-
LOGGER.info(f"{m.from_user.id} banned {user_id} in {m.chat.id}")
|
927 |
-
await m.chat.ban_member(user_id)
|
928 |
-
banned = await mention_html(user_first_name, user_id)
|
929 |
-
txt = f"{m.from_user.mention} banned {banned} in <b>{m.chat.title}</b>!"
|
930 |
if reason:
|
931 |
-
|
932 |
-
|
933 |
-
txt += "\n<b>Reason</b>: Not Specified"
|
934 |
-
keyboard = InlineKeyboardMarkup(
|
935 |
-
[
|
936 |
-
[
|
937 |
-
InlineKeyboardButton(
|
938 |
-
"UNBAN",
|
939 |
-
callback_data=f"unban_={user_id}",
|
940 |
-
),
|
941 |
-
],
|
942 |
-
],
|
943 |
-
)
|
944 |
-
anim = choice(BAN_GIFS)
|
945 |
try:
|
946 |
-
|
947 |
-
|
948 |
-
|
949 |
-
|
950 |
-
|
951 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
952 |
)
|
953 |
-
|
954 |
-
|
955 |
-
|
956 |
-
|
957 |
-
|
958 |
-
|
959 |
-
|
960 |
-
|
961 |
-
|
962 |
-
|
963 |
-
|
964 |
-
|
965 |
-
|
966 |
-
|
967 |
-
|
968 |
-
|
969 |
-
|
970 |
-
|
971 |
-
|
972 |
-
|
973 |
-
|
974 |
-
|
975 |
-
|
976 |
-
|
977 |
-
|
978 |
-
|
979 |
-
|
980 |
-
|
981 |
-
|
982 |
-
|
983 |
-
|
984 |
-
|
985 |
-
|
986 |
-
|
987 |
-
|
988 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
989 |
|
990 |
-
|
991 |
-
|
992 |
-
"You don't have enough permission to do this!\nStay in your limits!",
|
993 |
-
show_alert=True,
|
994 |
-
)
|
995 |
-
return
|
996 |
|
997 |
-
|
998 |
-
await q.answer(
|
999 |
-
"You don't have enough permission to do this!\nStay in your limits!",
|
1000 |
-
show_alert=True,
|
1001 |
-
)
|
1002 |
-
return
|
1003 |
-
whoo = await c.get_chat(user_id)
|
1004 |
-
doneto = whoo.first_name if whoo.first_name else whoo.title
|
1005 |
-
try:
|
1006 |
-
await q.message.chat.unban_member(user_id)
|
1007 |
-
except RPCError as e:
|
1008 |
-
await q.message.edit_text(f"Error: {e}")
|
1009 |
-
return
|
1010 |
-
await q.message.edit_text(f"{q.from_user.mention} unbanned {doneto}!")
|
1011 |
-
return
|
1012 |
|
1013 |
|
1014 |
-
#
|
1015 |
|
1016 |
|
1017 |
__help__ = """
|
1018 |
-
|
1019 |
|
1020 |
-
|
|
|
1021 |
|
1022 |
-
» /
|
1023 |
|
1024 |
-
» /
|
1025 |
|
1026 |
-
» /
|
1027 |
|
1028 |
-
» /
|
1029 |
|
1030 |
-
|
|
|
|
|
1031 |
|
1032 |
-
|
1033 |
-
|
1034 |
-
|
1035 |
-
|
1036 |
-
|
1037 |
-
|
1038 |
-
|
1039 |
-
|
1040 |
-
|
1041 |
-
|
1042 |
-
|
|
|
1043 |
|
1044 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1045 |
# <================================================ END =======================================================>
|
|
|
1 |
# <============================================== IMPORTS =========================================================>
|
2 |
+
import html
|
3 |
+
|
4 |
+
from telegram import (
|
5 |
+
ChatMemberAdministrator,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
InlineKeyboardButton,
|
7 |
InlineKeyboardMarkup,
|
8 |
+
Update,
|
9 |
)
|
10 |
+
from telegram.constants import ParseMode
|
11 |
+
from telegram.error import BadRequest
|
12 |
+
from telegram.ext import CallbackQueryHandler, CommandHandler, ContextTypes, filters
|
13 |
+
from telegram.helpers import mention_html
|
14 |
+
|
15 |
+
from Mikobot import DEV_USERS, DRAGONS, LOGGER, OWNER_ID, function
|
16 |
+
from Mikobot.utils.can_restrict import BAN_STICKER
|
17 |
+
from Mikobot.plugins.disable import DisableAbleCommandHandler
|
18 |
+
from Mikobot.plugins.helper_funcs.chat_status import (
|
19 |
+
can_delete,
|
20 |
+
check_admin,
|
21 |
+
connection_status,
|
22 |
+
is_user_admin,
|
23 |
+
is_user_ban_protected,
|
24 |
+
is_user_in_chat,
|
25 |
+
)
|
26 |
+
from Mikobot.plugins.helper_funcs.extraction import extract_user_and_text
|
27 |
+
from Mikobot.plugins.helper_funcs.misc import mention_username
|
28 |
+
from Mikobot.plugins.helper_funcs.string_handling import extract_time
|
29 |
+
from Mikobot.plugins.log_channel import gloggable, loggable
|
30 |
|
31 |
# <=======================================================================================================>
|
32 |
|
33 |
|
34 |
# <================================================ FUNCTION =======================================================>
|
35 |
+
@connection_status
|
36 |
+
@loggable
|
37 |
+
@check_admin(permission="can_restrict_members", is_both=True)
|
38 |
+
async def ban(update: Update, context: ContextTypes.DEFAULT_TYPE) -> str:
|
39 |
+
chat = update.effective_chat
|
40 |
+
user = update.effective_user
|
41 |
+
message = update.effective_message
|
42 |
+
log_message = ""
|
43 |
+
bot = context.bot
|
44 |
+
args = context.args
|
45 |
+
user_id, reason = await extract_user_and_text(message, context, args)
|
46 |
+
|
47 |
+
member = await chat.get_member(user.id)
|
48 |
+
SILENT = bool(True if message.text.startswith("/s") else False)
|
49 |
+
|
50 |
+
# if update is coming from anonymous admin then send button and return.
|
51 |
+
if message.from_user.id == 1087968824:
|
52 |
+
if SILENT:
|
53 |
+
await message.reply_text("Currently /sban won't work for anoymous admins.")
|
54 |
+
return log_message
|
55 |
+
# Need chat title to be forwarded on callback data to mention channel after banning.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
try:
|
57 |
+
chat_title = message.reply_to_message.sender_chat.title
|
58 |
+
except AttributeError:
|
59 |
+
chat_title = None
|
60 |
+
await update.effective_message.reply_text(
|
61 |
+
text="You are an anonymous admin.",
|
62 |
+
reply_markup=InlineKeyboardMarkup(
|
63 |
+
[
|
64 |
+
[
|
65 |
+
InlineKeyboardButton(
|
66 |
+
text="Click to prove Admin.",
|
67 |
+
callback_data=f"bans_{chat.id}=ban={user_id}={reason}={chat_title}",
|
68 |
+
),
|
69 |
+
],
|
70 |
+
]
|
71 |
+
),
|
72 |
+
)
|
73 |
+
|
74 |
+
return log_message
|
75 |
+
elif (
|
76 |
+
not (
|
77 |
+
(
|
78 |
+
member.can_restrict_members
|
79 |
+
if isinstance(member, ChatMemberAdministrator)
|
80 |
+
else None
|
81 |
)
|
82 |
+
or member.status == "creator"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
)
|
84 |
+
and user.id not in DRAGONS
|
85 |
+
):
|
86 |
+
await update.effective_message.reply_text(
|
87 |
+
"Sorry son, but you're not worthy to wield the banhammer.",
|
88 |
)
|
89 |
+
return log_message
|
|
|
|
|
|
|
|
|
|
|
90 |
|
91 |
+
if user_id == bot.id:
|
92 |
+
await message.reply_text("Oh yeah, ban myself, noob!")
|
93 |
+
return log_message
|
|
|
|
|
|
|
94 |
|
95 |
+
if user_id is not None and user_id < 0:
|
96 |
+
CHAT_SENDER = True
|
97 |
+
chat_sender = message.reply_to_message.sender_chat
|
98 |
+
else:
|
99 |
+
CHAT_SENDER = False
|
100 |
+
try:
|
101 |
+
member = await chat.get_member(user_id)
|
102 |
+
except BadRequest as excp:
|
103 |
+
if excp.message == "User not found":
|
104 |
+
raise
|
105 |
+
elif excp == "Invalid user_id specified":
|
106 |
+
await message.reply_text("I Doubt that's a user.")
|
107 |
+
await message.reply_text("Can't find this person here.")
|
108 |
+
return log_message
|
109 |
+
|
110 |
+
if await is_user_ban_protected(chat, user_id, member) and user not in DEV_USERS:
|
111 |
+
if user_id == OWNER_ID:
|
112 |
+
await message.reply_text(
|
113 |
+
"Trying to put me against a God level disaster huh?"
|
114 |
+
)
|
115 |
+
elif user_id in DEV_USERS:
|
116 |
+
await message.reply_text("I can't act against our own.")
|
117 |
+
elif user_id in DRAGONS:
|
118 |
+
await message.reply_text(
|
119 |
+
"Fighting this Dragon here will put me and my people's at risk.",
|
120 |
+
)
|
121 |
+
else:
|
122 |
+
await message.reply_text("This user has immunity and cannot be banned.")
|
123 |
+
return log_message
|
124 |
+
|
125 |
+
if SILENT:
|
126 |
+
silent = True
|
127 |
+
if not await can_delete(chat, context.bot.id):
|
128 |
+
return ""
|
129 |
+
else:
|
130 |
+
silent = False
|
131 |
|
132 |
+
log = (
|
133 |
+
f"<b>{html.escape(chat.title)}:</b>\n"
|
134 |
+
f"#{'S' if silent else ''}BANNED\n"
|
135 |
+
f"<b>Admin:</b> {mention_html(user.id, html.escape(user.first_name))}\n"
|
136 |
+
)
|
137 |
|
138 |
+
reply = f"<code>❕</code><b>Ban Event</b>\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
139 |
|
140 |
+
if CHAT_SENDER:
|
141 |
+
log += f"<b>Channel:</b> {mention_username(chat_sender.username, html.escape(chat_sender.title))}"
|
142 |
+
reply += f"<code> </code><b>• Channel:</b> {mention_username(chat_sender.username, html.escape(chat_sender.title))}"
|
|
|
|
|
|
|
|
|
|
|
143 |
|
|
|
|
|
|
|
|
|
144 |
else:
|
145 |
+
log += f"<b>User:</b> {mention_html(member.user.id, html.escape(member.user.first_name))}"
|
146 |
+
reply += f"<code> </code><b>• User:</b> {mention_html(member.user.id, html.escape(member.user.first_name))}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
147 |
|
148 |
+
if reason:
|
149 |
+
log += "\n<b>Reason:</b> {}".format(reason)
|
150 |
|
151 |
try:
|
152 |
+
if CHAT_SENDER:
|
153 |
+
await chat.ban_sender_chat(sender_chat_id=chat_sender.id)
|
154 |
+
else:
|
155 |
+
await chat.ban_member(user_id)
|
|
|
|
|
|
|
156 |
|
157 |
+
if silent:
|
158 |
+
if message.reply_to_message:
|
159 |
+
await message.reply_to_message.delete()
|
160 |
+
await message.delete()
|
161 |
+
return log
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
162 |
|
163 |
+
await bot.send_sticker(
|
164 |
+
chat.id,
|
165 |
+
BAN_STICKER,
|
166 |
+
message_thread_id=message.message_thread_id if chat.is_forum else None,
|
167 |
+
) # banhammer marie sticker
|
168 |
|
169 |
+
if reason:
|
170 |
+
reply += f"\n<code> </code><b>• Reason:</b> \n{html.escape(reason)}"
|
171 |
+
await bot.sendMessage(
|
172 |
+
chat.id,
|
173 |
+
reply,
|
174 |
+
parse_mode=ParseMode.HTML,
|
175 |
+
message_thread_id=message.message_thread_id if chat.is_forum else None,
|
176 |
+
)
|
177 |
+
return log
|
178 |
+
|
179 |
+
except BadRequest as excp:
|
180 |
+
if excp.message == "Reply message not found":
|
181 |
+
# Do not reply
|
182 |
+
if silent:
|
183 |
+
return log
|
184 |
+
await message.reply_text("Banned!", quote=False)
|
185 |
+
return log
|
186 |
+
else:
|
187 |
+
LOGGER.warning(update)
|
188 |
+
LOGGER.exception(
|
189 |
+
"ERROR banning user %s in chat %s (%s) due to %s",
|
190 |
+
user_id,
|
191 |
+
chat.title,
|
192 |
+
chat.id,
|
193 |
+
excp.message,
|
194 |
+
)
|
195 |
+
await message.reply_text("Uhm...that didn't work...")
|
196 |
|
197 |
+
return log_message
|
|
|
|
|
|
|
|
|
198 |
|
|
|
|
|
|
|
|
|
|
|
199 |
|
200 |
+
@connection_status
|
201 |
+
@loggable
|
202 |
+
@check_admin(permission="can_restrict_members", is_both=True)
|
203 |
+
async def temp_ban(update: Update, context: ContextTypes.DEFAULT_TYPE) -> str:
|
204 |
+
chat = update.effective_chat
|
205 |
+
user = update.effective_user
|
206 |
+
message = update.effective_message
|
207 |
+
log_message = ""
|
208 |
+
bot, args = context.bot, context.args
|
209 |
+
user_id, reason = await extract_user_and_text(message, context, args)
|
210 |
|
211 |
if not user_id:
|
212 |
+
await message.reply_text("I doubt that's a user.")
|
213 |
+
return log_message
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
214 |
|
215 |
+
try:
|
216 |
+
member = await chat.get_member(user_id)
|
217 |
+
except BadRequest as excp:
|
218 |
+
if excp.message != "User not found":
|
219 |
+
raise
|
220 |
+
await message.reply_text("I can't seem to find this user.")
|
221 |
+
return log_message
|
222 |
+
if user_id == bot.id:
|
223 |
+
await message.reply_text("I'm not gonna BAN myself, are you crazy?")
|
224 |
+
return log_message
|
225 |
+
|
226 |
+
if await is_user_ban_protected(chat, user_id, member):
|
227 |
+
await message.reply_text("I don't feel like it.")
|
228 |
+
return log_message
|
229 |
|
230 |
if not reason:
|
231 |
+
await message.reply_text("You haven't specified a time to ban this user for!")
|
232 |
+
return log_message
|
233 |
|
234 |
split_reason = reason.split(None, 1)
|
235 |
+
|
236 |
time_val = split_reason[0].lower()
|
237 |
reason = split_reason[1] if len(split_reason) > 1 else ""
|
238 |
+
bantime = await extract_time(message, time_val)
|
|
|
239 |
|
240 |
if not bantime:
|
241 |
+
return log_message
|
242 |
+
|
243 |
+
log = (
|
244 |
+
f"<b>{html.escape(chat.title)}:</b>\n"
|
245 |
+
"#TEMP BANNED\n"
|
246 |
+
f"<b>Admin:</b> {mention_html(user.id, html.escape(user.first_name))}\n"
|
247 |
+
f"<b>User:</b> {mention_html(member.user.id, html.escape(member.user.first_name))}\n"
|
248 |
+
f"<b>Time:</b> {time_val}"
|
249 |
+
)
|
250 |
+
if reason:
|
251 |
+
log += "\n<b>Reason:</b> {}".format(reason)
|
252 |
|
253 |
try:
|
254 |
+
await chat.ban_member(user_id, until_date=bantime)
|
255 |
+
await bot.send_sticker(
|
256 |
+
chat.id,
|
257 |
+
BAN_STICKER,
|
258 |
+
message_thread_id=message.message_thread_id if chat.is_forum else None,
|
259 |
+
) # banhammer marie sticker
|
260 |
+
await bot.sendMessage(
|
261 |
+
chat.id,
|
262 |
+
f"Banned! User {mention_html(member.user.id, html.escape(member.user.first_name))} "
|
263 |
+
f"will be banned for {time_val}.",
|
264 |
+
parse_mode=ParseMode.HTML,
|
265 |
+
message_thread_id=message.message_thread_id if chat.is_forum else None,
|
266 |
+
)
|
267 |
+
return log
|
268 |
+
|
269 |
+
except BadRequest as excp:
|
270 |
+
if excp.message == "Reply message not found":
|
271 |
+
# Do not reply
|
272 |
+
await message.reply_text(
|
273 |
+
f"Banned! User will be banned for {time_val}.",
|
274 |
+
quote=False,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
275 |
)
|
276 |
+
return log
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
277 |
else:
|
278 |
+
LOGGER.warning(update)
|
279 |
+
LOGGER.exception(
|
280 |
+
"ERROR banning user %s in chat %s (%s) due to %s",
|
281 |
+
user_id,
|
282 |
+
chat.title,
|
283 |
+
chat.id,
|
284 |
+
excp.message,
|
|
|
|
|
285 |
)
|
286 |
+
await message.reply_text("Well damn, I can't ban that user.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
287 |
|
288 |
+
return log_message
|
|
|
|
|
|
|
|
|
|
|
289 |
|
290 |
|
291 |
+
@connection_status
|
292 |
+
@loggable
|
293 |
+
@check_admin(permission="can_restrict_members", is_both=True)
|
294 |
+
async def kick(update: Update, context: ContextTypes.DEFAULT_TYPE) -> str:
|
295 |
+
chat = update.effective_chat
|
296 |
+
user = update.effective_user
|
297 |
+
message = update.effective_message
|
298 |
+
log_message = ""
|
299 |
+
bot, args = context.bot, context.args
|
300 |
+
user_id, reason = await extract_user_and_text(message, context, args)
|
301 |
|
302 |
if not user_id:
|
303 |
+
await message.reply_text("I doubt that's a user.")
|
304 |
+
return log_message
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
305 |
|
306 |
try:
|
307 |
+
member = await chat.get_member(user_id)
|
308 |
+
except BadRequest as excp:
|
309 |
+
if excp.message != "User not found":
|
310 |
+
raise
|
311 |
+
|
312 |
+
await message.reply_text("I can't seem to find this user.")
|
313 |
+
return log_message
|
314 |
+
if user_id == bot.id:
|
315 |
+
await message.reply_text("Yeahhh I'm not gonna do that.")
|
316 |
+
return log_message
|
317 |
+
|
318 |
+
if await is_user_ban_protected(chat, user_id):
|
319 |
+
await message.reply_text("I really wish I could kick this user....")
|
320 |
+
return log_message
|
321 |
+
|
322 |
+
res = chat.unban_member(user_id) # unban on current user = kick
|
323 |
+
if res:
|
324 |
+
await bot.send_sticker(
|
325 |
+
chat.id,
|
326 |
+
BAN_STICKER,
|
327 |
+
message_thread_id=message.message_thread_id if chat.is_forum else None,
|
328 |
+
) # banhammer marie sticker
|
329 |
+
await bot.sendMessage(
|
330 |
+
chat.id,
|
331 |
+
f"Capitain I have kicked, {mention_html(member.user.id, html.escape(member.user.first_name))}.",
|
332 |
+
parse_mode=ParseMode.HTML,
|
333 |
+
message_thread_id=message.message_thread_id if chat.is_forum else None,
|
334 |
+
)
|
335 |
+
log = (
|
336 |
+
f"<b>{html.escape(chat.title)}:</b>\n"
|
337 |
+
f"#KICKED\n"
|
338 |
+
f"<b>Admin:</b> {mention_html(user.id, html.escape(user.first_name))}\n"
|
339 |
+
f"<b>User:</b> {mention_html(member.user.id, html.escape(member.user.first_name))}"
|
340 |
)
|
341 |
+
if reason:
|
342 |
+
log += f"\n<b>Reason:</b> {reason}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
343 |
|
344 |
+
return log
|
345 |
|
346 |
+
else:
|
347 |
+
await message.reply_text("Well damn, I can't kick that user.")
|
|
|
|
|
|
|
|
|
|
|
348 |
|
349 |
+
return log_message
|
350 |
|
|
|
|
|
351 |
|
352 |
+
@check_admin(permission="can_restrict_members", is_bot=True)
|
353 |
+
async def kickme(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
354 |
+
user_id = update.effective_message.from_user.id
|
355 |
+
if await is_user_admin(update.effective_chat, user_id):
|
356 |
+
await update.effective_message.reply_text(
|
357 |
+
"I wish I could... but you're an admin."
|
358 |
+
)
|
359 |
return
|
360 |
|
361 |
+
res = await update.effective_chat.unban_member(
|
362 |
+
user_id
|
363 |
+
) # unban on current user = kick
|
364 |
+
# BUG: parsing not working
|
365 |
+
if res:
|
366 |
+
await update.effective_message.reply_text(
|
367 |
+
html.escape("You got the Devil's Kiss, Now die in peace"), parse_mode="html"
|
368 |
)
|
369 |
+
else:
|
370 |
+
await update.effective_message.reply_text("Huh? I can't :/")
|
|
|
|
|
371 |
|
|
|
|
|
|
|
|
|
372 |
|
373 |
+
@connection_status
|
374 |
+
@loggable
|
375 |
+
@check_admin(permission="can_restrict_members", is_both=True)
|
376 |
+
async def unban(update: Update, context: ContextTypes.DEFAULT_TYPE) -> str:
|
377 |
+
message = update.effective_message
|
378 |
+
user = update.effective_user
|
379 |
+
chat = update.effective_chat
|
380 |
+
log_message = ""
|
381 |
+
bot, args = context.bot, context.args
|
382 |
+
user_id, reason = await extract_user_and_text(message, context, args)
|
383 |
|
384 |
+
if message.from_user.id == 1087968824:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
385 |
try:
|
386 |
+
chat_title = message.reply_to_message.sender_chat.title
|
387 |
+
except AttributeError:
|
388 |
+
chat_title = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
389 |
|
390 |
+
await message.reply_text(
|
391 |
+
text="You are an anonymous admin.",
|
392 |
+
reply_markup=InlineKeyboardMarkup(
|
393 |
+
[
|
394 |
+
[
|
395 |
+
InlineKeyboardButton(
|
396 |
+
text="Click to prove Admin.",
|
397 |
+
callback_data=f"bans_{chat.id}=unban={user_id}={reason}={chat_title}",
|
398 |
+
),
|
399 |
+
],
|
400 |
+
]
|
401 |
+
),
|
402 |
)
|
|
|
|
|
403 |
|
404 |
+
return log_message
|
405 |
|
406 |
+
if not user_id:
|
407 |
+
await message.reply_text("I doubt that's a user.")
|
408 |
+
return log_message
|
409 |
|
410 |
+
if user_id == bot.id:
|
411 |
+
await message.reply_text("How would I unban myself if I wasn't here...?")
|
412 |
+
return log_message
|
|
|
|
|
413 |
|
414 |
+
if user_id is not None and user_id < 0:
|
415 |
+
CHAT_SENDER = True
|
416 |
+
chat_sender = message.reply_to_message.sender_chat
|
|
|
|
|
417 |
else:
|
418 |
+
CHAT_SENDER = False
|
419 |
try:
|
420 |
+
member = await chat.get_member(user_id)
|
421 |
+
|
422 |
+
if isinstance(member, ChatMemberAdministrator):
|
423 |
+
await message.reply_text(
|
424 |
+
"This person is an admin here, Are you drunk???"
|
425 |
+
)
|
426 |
+
return log_message
|
427 |
+
|
428 |
+
except BadRequest as excp:
|
429 |
+
raise
|
430 |
+
if excp.message != "User not found":
|
431 |
+
raise
|
432 |
+
await message.reply_text("I can't seem to find this user.")
|
433 |
+
return log_message
|
434 |
+
|
435 |
+
if await is_user_in_chat(chat, user_id):
|
436 |
+
await message.reply_text("Isn't this person already here??")
|
437 |
+
return log_message
|
438 |
+
|
439 |
+
log = (
|
440 |
+
f"<b>{html.escape(chat.title)}:</b>\n"
|
441 |
+
f"#UNBANNED\n"
|
442 |
+
f"<b>Admin:</b> {mention_html(user.id, html.escape(user.first_name))}\n"
|
443 |
+
)
|
444 |
+
|
445 |
+
if CHAT_SENDER:
|
446 |
+
log += f"<b>User:</b> {mention_username(chat_sender.id, html.escape(chat_sender.title))}"
|
447 |
+
await chat.unban_sender_chat(chat_sender.id)
|
448 |
+
await message.reply_text("Yeah, this channel can speak again.")
|
449 |
else:
|
450 |
+
log += f"<b>User:</b> {mention_html(member.user.id, html.escape(member.user.first_name))}"
|
451 |
+
await chat.unban_member(user_id)
|
452 |
+
await message.reply_text("Yeah, this user can join!")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
453 |
|
454 |
+
if reason:
|
455 |
+
log += f"\n<b>Reason:</b> {reason}"
|
456 |
|
457 |
+
return log
|
458 |
|
|
|
|
|
|
|
|
|
|
|
459 |
|
460 |
+
@connection_status
|
461 |
+
@gloggable
|
462 |
+
@check_admin(permission="can_restrict_members", is_bot=True)
|
463 |
+
async def selfunban(context: ContextTypes.DEFAULT_TYPE, update: Update) -> str:
|
464 |
+
message = update.effective_message
|
465 |
+
user = update.effective_user
|
466 |
+
bot, args = context.bot, context.args
|
467 |
+
if user.id not in DRAGONS:
|
|
|
|
|
468 |
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
469 |
|
470 |
try:
|
471 |
+
chat_id = int(args[0])
|
472 |
+
except:
|
473 |
+
await message.reply_text("Give a valid chat ID.")
|
474 |
+
return
|
475 |
|
476 |
+
chat = await bot.getChat(chat_id)
|
|
|
|
|
477 |
|
478 |
try:
|
479 |
+
member = await chat.get_member(user.id)
|
480 |
+
except BadRequest as excp:
|
481 |
+
if excp.message == "User not found":
|
482 |
+
await message.reply_text("I can't seem to find this user.")
|
483 |
+
return
|
484 |
+
else:
|
485 |
+
raise
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
486 |
|
487 |
+
if await is_user_in_chat(chat, user.id):
|
488 |
+
await message.reply_text("Aren't you already in the chat??")
|
489 |
+
return
|
|
|
|
|
490 |
|
491 |
+
await chat.unban_member(user.id)
|
492 |
+
await message.reply_text("Yep, I have unbanned you.")
|
493 |
|
494 |
+
log = (
|
495 |
+
f"<b>{html.escape(chat.title)}:</b>\n"
|
496 |
+
f"#UNBANNED\n"
|
497 |
+
f"<b>User:</b> {mention_html(member.user.id, html.escape(member.user.first_name))}"
|
498 |
+
)
|
|
|
|
|
|
|
|
|
|
|
499 |
|
500 |
+
return log
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
501 |
|
|
|
|
|
|
|
|
|
502 |
|
503 |
+
@loggable
|
504 |
+
async def bans_callback(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
505 |
+
query = update.callback_query
|
506 |
+
bot = context.bot
|
507 |
+
chat = update.effective_chat
|
508 |
+
message = update.effective_message
|
509 |
+
args = context.args
|
510 |
+
log_message = ""
|
511 |
+
splitter = query.data.replace("bans_", "").split("=")
|
512 |
|
513 |
+
admin_user = query.from_user
|
514 |
+
member = await chat.get_member(admin_user.id)
|
|
|
515 |
|
516 |
+
if splitter[1] == "ban":
|
517 |
+
# workaround for checking user admin status
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
518 |
try:
|
519 |
+
user_id = int(splitter[2])
|
520 |
+
except ValueError:
|
521 |
+
user_id = splitter[2]
|
522 |
+
reason = splitter[3]
|
523 |
+
chat_name = splitter[4]
|
524 |
+
|
525 |
+
if not (
|
526 |
+
(
|
527 |
+
member.can_restrict_members
|
528 |
+
if isinstance(member, ChatMemberAdministrator)
|
529 |
+
else None
|
530 |
)
|
531 |
+
or member.status == "creator"
|
532 |
+
) and (admin_user.id not in DRAGONS):
|
533 |
+
await query.answer(
|
534 |
+
"Sorry son, but you're not worthy to wield the banhammer.",
|
535 |
+
show_alert=True,
|
536 |
)
|
537 |
+
return log_message
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
538 |
|
539 |
+
if user_id == bot.id:
|
540 |
+
await message.edit_text("Oh yeah, ban myself, noob!")
|
541 |
+
return log_message
|
542 |
|
543 |
+
if isinstance(user_id, str):
|
544 |
+
await message.edit_text("I doubt that's a user.")
|
545 |
+
return log_message
|
|
|
|
|
546 |
|
547 |
+
if user_id < 0:
|
548 |
+
CHAT_SENDER = True
|
549 |
+
else:
|
550 |
+
CHAT_SENDER = False
|
551 |
+
try:
|
552 |
+
member = await chat.get_member(user_id)
|
553 |
+
except BadRequest as excp:
|
554 |
+
if excp.message == "User not found.":
|
555 |
+
raise
|
556 |
+
elif excp == "Invalid user_id specified":
|
557 |
+
await message.edit_text("I Doubt that's a user.")
|
558 |
+
await message.edit_text("Can't find this person here.")
|
559 |
+
|
560 |
+
return log_message
|
561 |
+
|
562 |
+
if (
|
563 |
+
await is_user_ban_protected(chat, user_id, member)
|
564 |
+
and admin_user not in DEV_USERS
|
565 |
+
):
|
566 |
+
if user_id == OWNER_ID:
|
567 |
+
await message.edit_text(
|
568 |
+
"Trying to put me against a God level disaster huh?"
|
569 |
+
)
|
570 |
+
elif user_id in DEV_USERS:
|
571 |
+
await message.edit_text("I can't act against our own.")
|
572 |
+
elif user_id in DRAGONS:
|
573 |
+
await message.edit_text(
|
574 |
+
"Fighting this Dragon here will put me and my people's at risk.",
|
575 |
+
)
|
576 |
+
else:
|
577 |
+
await message.edit_text(
|
578 |
+
"This user has immunity and cannot be banned."
|
579 |
+
)
|
580 |
+
return log_message
|
581 |
+
|
582 |
+
log = (
|
583 |
+
f"<b>{html.escape(chat.title)}:</b>\n"
|
584 |
+
f"#BANNED\n"
|
585 |
+
f"<b>Admin:</b> {mention_html(admin_user.id, html.escape(admin_user.first_name))}\n"
|
586 |
+
)
|
587 |
+
|
588 |
+
reply = f"<code>❕</code><b>Ban Event</b>\n"
|
589 |
+
|
590 |
+
if CHAT_SENDER:
|
591 |
+
log += f"<b>Channel:</b> {html.escape(chat_name)}"
|
592 |
+
reply += f"<code> </code><b>• Channel:</b> {html.escape(chat_name)}"
|
593 |
|
594 |
+
else:
|
595 |
+
log += f"<b>User:</b> {mention_html(member.user.id, html.escape(member.user.first_name))}"
|
596 |
+
reply += f"<code> </code><b>• User:</b> {mention_html(member.user.id, html.escape(member.user.first_name))}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
597 |
|
|
|
|
|
|
|
|
|
|
|
598 |
if reason:
|
599 |
+
log += "\n<b>Reason:</b> {}".format(reason)
|
600 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
601 |
try:
|
602 |
+
if CHAT_SENDER:
|
603 |
+
await chat.ban_sender_chat(sender_chat_id=user_id)
|
604 |
+
else:
|
605 |
+
await chat.ban_member(user_id)
|
606 |
+
|
607 |
+
await bot.send_sticker(
|
608 |
+
chat.id,
|
609 |
+
BAN_STICKER,
|
610 |
+
message_thread_id=message.message_thread_id if chat.is_forum else None,
|
611 |
+
) # banhammer marie sticker
|
612 |
+
|
613 |
+
if reason:
|
614 |
+
reply += f"\n<code> </code><b>• Reason:</b> \n{html.escape(reason)}"
|
615 |
+
await bot.sendMessage(
|
616 |
+
chat.id,
|
617 |
+
reply,
|
618 |
+
parse_mode=ParseMode.HTML,
|
619 |
+
message_thread_id=message.message_thread_id if chat.is_forum else None,
|
620 |
)
|
621 |
+
await query.answer(f"Done Banned User.")
|
622 |
+
return log
|
623 |
+
|
624 |
+
except BadRequest as excp:
|
625 |
+
if excp.message == "Reply message not found":
|
626 |
+
# Do not reply
|
627 |
+
await message.edit_text("Banned!")
|
628 |
+
return log
|
629 |
+
else:
|
630 |
+
LOGGER.warning(update)
|
631 |
+
LOGGER.exception(
|
632 |
+
"ERROR banning user %s in chat %s (%s) due to %s",
|
633 |
+
user_id,
|
634 |
+
chat.title,
|
635 |
+
chat.id,
|
636 |
+
excp.message,
|
637 |
+
)
|
638 |
+
await message.edit_text("Uhm...that didn't work...")
|
639 |
+
|
640 |
+
return log_message
|
641 |
+
|
642 |
+
elif splitter[1] == "unban":
|
643 |
+
try:
|
644 |
+
user_id = int(splitter[2])
|
645 |
+
except ValueError:
|
646 |
+
user_id = splitter[2]
|
647 |
+
reason = splitter[3]
|
648 |
+
|
649 |
+
if isinstance(user_id, str):
|
650 |
+
await message.edit_text("I doubt that's a user.")
|
651 |
+
return log_message
|
652 |
+
|
653 |
+
if user_id == bot.id:
|
654 |
+
await message.edit_text("How would i unban myself if i wasn't here...?")
|
655 |
+
return log_message
|
656 |
+
|
657 |
+
if user_id < 0:
|
658 |
+
CHAT_SENDER = True
|
659 |
+
chat_title = splitter[4]
|
660 |
+
else:
|
661 |
+
CHAT_SENDER = False
|
662 |
+
|
663 |
+
try:
|
664 |
+
member = await chat.get_member(user_id)
|
665 |
+
except BadRequest as excp:
|
666 |
+
if excp.message != "User not found":
|
667 |
+
raise
|
668 |
+
await message.edit_text("I can't seem to find this user.")
|
669 |
+
return log_message
|
670 |
+
|
671 |
+
if await is_user_in_chat(chat, user_id):
|
672 |
+
await message.edit_text("Isn't this person already here??")
|
673 |
+
return log_message
|
674 |
+
|
675 |
+
log = (
|
676 |
+
f"<b>{html.escape(chat.title)}:</b>\n"
|
677 |
+
f"#UNBANNED\n"
|
678 |
+
f"<b>Admin:</b> {mention_html(admin_user.id, html.escape(admin_user.first_name))}\n"
|
679 |
+
)
|
680 |
+
|
681 |
+
if CHAT_SENDER:
|
682 |
+
log += f"<b>User:</b> {html.escape(chat_title)}"
|
683 |
+
await chat.unban_sender_chat(user_id)
|
684 |
+
await message.reply_text("Yeah, this channel can speak again.")
|
685 |
+
else:
|
686 |
+
log += f"<b>User:</b> {mention_html(member.user.id, html.escape(member.user.first_name))}"
|
687 |
+
await chat.unban_member(user_id)
|
688 |
+
await message.reply_text("Yeah, this user can join!")
|
689 |
|
690 |
+
if reason:
|
691 |
+
log += f"\n<b>Reason:</b> {reason}"
|
|
|
|
|
|
|
|
|
692 |
|
693 |
+
return log
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
694 |
|
695 |
|
696 |
+
# <================================================ HELP =======================================================>
|
697 |
|
698 |
|
699 |
__help__ = """
|
700 |
+
» /kickme: kicks the user who issued the command
|
701 |
|
702 |
+
➠ *Admins only:*
|
703 |
+
» /ban <userhandle>: bans a user/channel. (via handle, or reply)
|
704 |
|
705 |
+
» /sban <userhandle>: Silently ban a user. Deletes command, Replied message and doesn't reply. (via handle, or reply)
|
706 |
|
707 |
+
» /tban <userhandle> x(m/h/d): bans a user for `x` time. (via handle, or reply). `m` = `minutes`, `h` = `hours`, `d` = `days`.
|
708 |
|
709 |
+
» /unban <userhandle>: unbans a user/channel. (via handle, or reply)
|
710 |
|
711 |
+
» /kick <userhandle>: kicks a user out of the group, (via handle, or reply)
|
712 |
|
713 |
+
➠ NOTE:
|
714 |
+
Banning or UnBanning channels only work if you reply to their message, so don't use their username to ban/unban.
|
715 |
+
"""
|
716 |
|
717 |
+
# <================================================ HANDLER =======================================================>
|
718 |
+
BAN_HANDLER = CommandHandler(["ban", "sban"], ban, block=False)
|
719 |
+
TEMPBAN_HANDLER = CommandHandler(["tban"], temp_ban, block=False)
|
720 |
+
KICK_HANDLER = CommandHandler("kick", kick, block=False)
|
721 |
+
UNBAN_HANDLER = CommandHandler("unban", unban, block=False)
|
722 |
+
ROAR_HANDLER = CommandHandler("roar", selfunban, block=False)
|
723 |
+
KICKME_HANDLER = DisableAbleCommandHandler(
|
724 |
+
"kickme", kickme, filters=filters.ChatType.GROUPS, block=False
|
725 |
+
)
|
726 |
+
BAN_CALLBACK_HANDLER = CallbackQueryHandler(
|
727 |
+
bans_callback, block=False, pattern=r"bans_"
|
728 |
+
)
|
729 |
|
730 |
+
function(BAN_HANDLER)
|
731 |
+
function(TEMPBAN_HANDLER)
|
732 |
+
function(KICK_HANDLER)
|
733 |
+
function(UNBAN_HANDLER)
|
734 |
+
function(ROAR_HANDLER)
|
735 |
+
function(KICKME_HANDLER)
|
736 |
+
function(BAN_CALLBACK_HANDLER)
|
737 |
+
|
738 |
+
__mod_name__ = "BAN"
|
739 |
+
__handlers__ = [
|
740 |
+
BAN_HANDLER,
|
741 |
+
TEMPBAN_HANDLER,
|
742 |
+
KICK_HANDLER,
|
743 |
+
UNBAN_HANDLER,
|
744 |
+
ROAR_HANDLER,
|
745 |
+
KICKME_HANDLER,
|
746 |
+
BAN_CALLBACK_HANDLER,
|
747 |
+
]
|
748 |
# <================================================ END =======================================================>
|