randydev commited on
Commit
880c36c
·
verified ·
1 Parent(s): 17cc00b

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +24 -19
main.py CHANGED
@@ -43,10 +43,10 @@ def has_code_entity(message):
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.matches[0].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)
@@ -58,12 +58,12 @@ async def unwarn_button(client, callback_query):
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.matches[0].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)
@@ -89,32 +89,29 @@ async def warn_button(client, callback_query):
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.matches[0].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)
@@ -395,10 +392,18 @@ async def block_inline_via_bot(client, message):
395
  logging.info(f"check_anti_word_by_ryzenth: Blocked message from {message.from_user.first_name} in {message.chat.title}")
396
  return await message.delete()
397
 
 
 
 
 
 
 
 
 
398
 
399
  @bot.on_message(
400
  filters.group
401
- & ~filters.command(["delmodbot", "addmodbot", "delmoduser", "addmoduser", "start"])
402
  & ~filters.via_bot,
403
  group=-1
404
  )
@@ -444,7 +449,7 @@ async def markdown_code(client, message):
444
  [
445
  [
446
  InlineKeyboardButton(
447
- "Unban", callback_data=f"unban_{message.from_user.id}"
448
  )
449
  ]
450
  ]
@@ -459,7 +464,7 @@ async def markdown_code(client, message):
459
  [
460
  [
461
  InlineKeyboardButton(
462
- "Unwarn", callback_data=f"unwarn_{message.from_user.id}"
463
  )
464
  ]
465
  ]
@@ -486,7 +491,7 @@ async def markdown_code(client, message):
486
  [
487
  [
488
  InlineKeyboardButton(
489
- "Unban", callback_data=f"unban_{message.from_user.id}"
490
  )
491
  ]
492
  ]
@@ -501,7 +506,7 @@ async def markdown_code(client, message):
501
  [
502
  [
503
  InlineKeyboardButton(
504
- "Unwarn", callback_data=f"unwarn_{message.from_user.id}"
505
  )
506
  ]
507
  ]
 
43
  return True
44
  return False
45
 
46
+ @bot.on_callback_query(filters.regex(r"^unwarn_(\d+)_(\d+)$"))
47
  async def unwarn_button(client, callback_query):
48
  user_id = int(callback_query.matches[0].group(1))
49
+ chat_id = int(callback_query.matches[0].group(2))
50
  from_user = callback_query.from_user
51
  try:
52
  member = await client.get_chat_member(chat_id, from_user.id)
 
58
  return
59
 
60
  await db.warns.delete_one({"chat_id": chat_id, "user_id": user_id})
61
+ await callback_query.message.edit_text(f"✅ Peringatan untuk <code>{user_id}</code> telah dihapus.")
62
 
63
+ @bot.on_callback_query(filters.regex(r"^warn_(\d+)_(\d+)$"))
64
  async def warn_button(client, callback_query):
65
  user_id = int(callback_query.matches[0].group(1))
66
+ chat_id = int(callback_query.matches[0].group(2))
67
  from_user = callback_query.from_user
68
  try:
69
  member = await client.get_chat_member(chat_id, from_user.id)
 
89
 
90
  if warn_count >= 3:
91
  try:
92
+ await client.ban_chat_member(chat_id, user_id)
93
+ await callback_query.message.reply_text(
94
+ f"🚫 User <code>{user_id}</code> telah dihapus setelah 3 kali peringatan.",
95
  reply_markup=InlineKeyboardMarkup(
96
  [
97
  [
98
  InlineKeyboardButton(
99
+ "Unban", callback_data=f"unban_{user_id}_{chat_id}"
100
  )
101
  ]
102
  ]
103
  )
104
  )
 
 
 
105
  await db.warns.delete_one({"chat_id": chat_id, "user_id": user_id})
106
  except Exception as e:
107
  await callback_query.message.reply_text(f"Gagal menghapus user: {e}")
108
  else:
109
  await callback_query.answer(f"⚠️ Peringatan ke {warn_count} diberikan.", show_alert=True)
110
 
111
+ @bot.on_callback_query(filters.regex(r"^unban_(\d+)_(\d+)$"))
112
  async def unban_button(client, callback_query):
113
  user_id = int(callback_query.matches[0].group(1))
114
+ chat_id = int(callback_query.matches[0].group(2))
115
  from_user = callback_query.from_user
116
  try:
117
  member = await client.get_chat_member(chat_id, from_user.id)
 
392
  logging.info(f"check_anti_word_by_ryzenth: Blocked message from {message.from_user.first_name} in {message.chat.title}")
393
  return await message.delete()
394
 
395
+ DISABLED_COMMANDS = [
396
+ "delmodbot",
397
+ "addmodbot",
398
+ "delmoduser",
399
+ "addmoduser",
400
+ "start",
401
+ "delwarn",
402
+ ]
403
 
404
  @bot.on_message(
405
  filters.group
406
+ & ~filters.command(DISABLED_COMMANDS)
407
  & ~filters.via_bot,
408
  group=-1
409
  )
 
449
  [
450
  [
451
  InlineKeyboardButton(
452
+ "Unban", callback_data=f"unban_{message.from_user.id}_{message.chat.id}"
453
  )
454
  ]
455
  ]
 
464
  [
465
  [
466
  InlineKeyboardButton(
467
+ "Unwarn", callback_data=f"unwarn_{message.from_user.id}_{message.chat.id}"
468
  )
469
  ]
470
  ]
 
491
  [
492
  [
493
  InlineKeyboardButton(
494
+ "Unban", callback_data=f"unban_{message.from_user.id}_{message.chat.id}"
495
  )
496
  ]
497
  ]
 
506
  [
507
  [
508
  InlineKeyboardButton(
509
+ "Unwarn", callback_data=f"unwarn_{message.from_user.id}_{message.chat.id}"
510
  )
511
  ]
512
  ]