Spaces:
Running
Running
Update main.py
Browse files
main.py
CHANGED
@@ -7,6 +7,7 @@
|
|
7 |
# All rights reserved. See COPYING, AUTHORS.
|
8 |
#
|
9 |
|
|
|
10 |
import re
|
11 |
import asyncio
|
12 |
import logging
|
@@ -42,6 +43,96 @@ def has_code_entity(message):
|
|
42 |
return True
|
43 |
return False
|
44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
@bot.on_message(filters.command("start") & filters.private)
|
46 |
async def start_command(client, message):
|
47 |
reply_markup = InlineKeyboardMarkup( # type: ignore
|
@@ -323,9 +414,50 @@ async def markdown_code(client, message):
|
|
323 |
try:
|
324 |
if is_blocked_markdown_code(message.text.markdown or ""):
|
325 |
logging.info(f"is_blocked_markdown_code: Blocked message from {message.from_user.first_name} in {message.chat.title}")
|
326 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
327 |
except AttributeError:
|
328 |
pass
|
|
|
329 |
if check_anti_word_by_ryzenth(message.text):
|
330 |
logging.info(f"check_anti_word_by_ryzenth: Blocked message from {message.from_user.first_name} in {message.chat.title}")
|
331 |
return await message.delete()
|
|
|
7 |
# All rights reserved. See COPYING, AUTHORS.
|
8 |
#
|
9 |
|
10 |
+
|
11 |
import re
|
12 |
import asyncio
|
13 |
import logging
|
|
|
43 |
return True
|
44 |
return False
|
45 |
|
46 |
+
@bot.on_callback_query(filters.regex(r"^unwarn_(\d+)$"))
|
47 |
+
async def unwarn_button(client, callback_query):
|
48 |
+
user_id = int(callback_query.match.group(1))
|
49 |
+
chat_id = callback_query.message.chat.id
|
50 |
+
from_user = callback_query.from_user
|
51 |
+
try:
|
52 |
+
member = await client.get_chat_member(chat_id, from_user.id)
|
53 |
+
if member.status.value not in ("administrator", "creator"):
|
54 |
+
await callback_query.answer("❌ Hanya admin yang bisa menghapus peringatan!", show_alert=True)
|
55 |
+
return
|
56 |
+
except Exception:
|
57 |
+
await callback_query.answer("⚠️ Gagal memverifikasi status admin.", show_alert=True)
|
58 |
+
return
|
59 |
+
|
60 |
+
await db.warns.delete_one({"chat_id": chat_id, "user_id": user_id})
|
61 |
+
await callback_query.answer(f"✅ Peringatan untuk <code>{user_id}</code> telah dihapus.", show_alert=True)
|
62 |
+
|
63 |
+
@bot.on_callback_query(filters.regex(r"^warn_(\d+)$"))
|
64 |
+
async def warn_button(client, callback_query):
|
65 |
+
user_id = int(callback_query.match.group(1))
|
66 |
+
chat_id = callback_query.message.chat.id
|
67 |
+
from_user = callback_query.from_user
|
68 |
+
try:
|
69 |
+
member = await client.get_chat_member(chat_id, from_user.id)
|
70 |
+
if member.status.value not in ("administrator", "creator"):
|
71 |
+
await callback_query.answer("❌ Hanya admin yang bisa memberikan peringatan!", show_alert=True)
|
72 |
+
return
|
73 |
+
except Exception:
|
74 |
+
await callback_query.answer("⚠️ Gagal memverifikasi status admin.", show_alert=True)
|
75 |
+
return
|
76 |
+
|
77 |
+
warn_data = await db.warns.find_one({"chat_id": chat_id, "user_id": user_id})
|
78 |
+
warn_count = 1
|
79 |
+
|
80 |
+
if warn_data:
|
81 |
+
warn_count = warn_data.get("count", 0) + 1
|
82 |
+
await db.warns.update_one(
|
83 |
+
{"chat_id": chat_id, "user_id": user_id},
|
84 |
+
{"$set": {"count": warn_count}},
|
85 |
+
upsert=True
|
86 |
+
)
|
87 |
+
else:
|
88 |
+
await db.warns.insert_one({"chat_id": chat_id, "user_id": user_id, "count": warn_count})
|
89 |
+
|
90 |
+
if warn_count >= 3:
|
91 |
+
try:
|
92 |
+
await client.ban_chat_member(
|
93 |
+
chat_id,
|
94 |
+
user_id,
|
95 |
+
reply_markup=InlineKeyboardMarkup(
|
96 |
+
[
|
97 |
+
[
|
98 |
+
InlineKeyboardButton(
|
99 |
+
"Unban", callback_data=f"unban_{user_id}"
|
100 |
+
)
|
101 |
+
]
|
102 |
+
]
|
103 |
+
)
|
104 |
+
)
|
105 |
+
await callback_query.message.reply_text(
|
106 |
+
f"🚫 User <code>{user_id}</code> telah dihapus setelah 3 kali peringatan."
|
107 |
+
)
|
108 |
+
await db.warns.delete_one({"chat_id": chat_id, "user_id": user_id})
|
109 |
+
except Exception as e:
|
110 |
+
await callback_query.message.reply_text(f"Gagal menghapus user: {e}")
|
111 |
+
else:
|
112 |
+
await callback_query.answer(f"⚠️ Peringatan ke {warn_count} diberikan.", show_alert=True)
|
113 |
+
|
114 |
+
@bot.on_callback_query(filters.regex(r"^unban_(\d+)$"))
|
115 |
+
async def unban_button(client, callback_query):
|
116 |
+
user_id = int(callback_query.match.group(1))
|
117 |
+
chat_id = callback_query.message.chat.id
|
118 |
+
from_user = callback_query.from_user
|
119 |
+
try:
|
120 |
+
member = await client.get_chat_member(chat_id, from_user.id)
|
121 |
+
if member.status.value not in ("administrator", "creator"):
|
122 |
+
await callback_query.answer("❌ Hanya admin yang bisa menghapus larangan!", show_alert=True)
|
123 |
+
return
|
124 |
+
except Exception:
|
125 |
+
await callback_query.answer("⚠️ Gagal memverifikasi status admin.", show_alert=True)
|
126 |
+
return
|
127 |
+
|
128 |
+
try:
|
129 |
+
await client.unban_chat_member(chat_id, user_id)
|
130 |
+
await callback_query.message.reply_text(
|
131 |
+
f"✅ User <code>{user_id}</code> telah dihapus dari larangan."
|
132 |
+
)
|
133 |
+
except Exception as e:
|
134 |
+
await callback_query.message.reply_text(f"Gagal menghapus larangan: {e}")
|
135 |
+
|
136 |
@bot.on_message(filters.command("start") & filters.private)
|
137 |
async def start_command(client, message):
|
138 |
reply_markup = InlineKeyboardMarkup( # type: ignore
|
|
|
414 |
try:
|
415 |
if is_blocked_markdown_code(message.text.markdown or ""):
|
416 |
logging.info(f"is_blocked_markdown_code: Blocked message from {message.from_user.first_name} in {message.chat.title}")
|
417 |
+
warn = await db.warns.find_one({"chat_id": message.chat.id, "user_id": message.from_user.id})
|
418 |
+
if warn:
|
419 |
+
warn_count = warn.get("count", 0) + 1
|
420 |
+
await db.warns.update_one(
|
421 |
+
{"chat_id": message.chat.id, "user_id": message.from_user.id},
|
422 |
+
{"$set": {"count": warn_count}},
|
423 |
+
upsert=True
|
424 |
+
)
|
425 |
+
if warn_count >= 3:
|
426 |
+
await client.ban_chat_member(
|
427 |
+
message.chat.id,
|
428 |
+
message.from_user.id,
|
429 |
+
reply_markup=InlineKeyboardMarkup(
|
430 |
+
[
|
431 |
+
[
|
432 |
+
InlineKeyboardButton(
|
433 |
+
"Unban", callback_data=f"unban_{message.from_user.id}"
|
434 |
+
)
|
435 |
+
]
|
436 |
+
]
|
437 |
+
)
|
438 |
+
)
|
439 |
+
await message.reply_text(
|
440 |
+
f"🚫 User <code>{message.from_user.id}</code> telah dihapus setelah 3 kali peringatan."
|
441 |
+
)
|
442 |
+
await db.warns.delete_one({"chat_id": message.chat.id, "user_id": message.from_user.id})
|
443 |
+
else:
|
444 |
+
await db.warns.insert_one({"chat_id": message.chat.id, "user_id": message.from_user.id, "count": 1})
|
445 |
+
await message.reply_text(
|
446 |
+
f"⚠️ Peringatan pertama untuk <code>{message.from_user.id}</code>.",
|
447 |
+
reply_markup=InlineKeyboardMarkup(
|
448 |
+
[
|
449 |
+
[
|
450 |
+
InlineKeyboardButton(
|
451 |
+
"Unwarn", callback_data=f"unwarn_{message.from_user.id}"
|
452 |
+
)
|
453 |
+
]
|
454 |
+
]
|
455 |
+
)
|
456 |
+
)
|
457 |
+
await message.delete()
|
458 |
except AttributeError:
|
459 |
pass
|
460 |
+
|
461 |
if check_anti_word_by_ryzenth(message.text):
|
462 |
logging.info(f"check_anti_word_by_ryzenth: Blocked message from {message.from_user.first_name} in {message.chat.title}")
|
463 |
return await message.delete()
|