antiflood.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. from wbb import app
  2. from wbb.utils.filter_groups import antiflood_group
  3. from wbb.utils.errors import capture_err
  4. from wbb.utils.dbfunctions import (
  5. is_antiflood_on,
  6. antiflood_on,
  7. antiflood_off
  8. )
  9. from wbb.modules.admin import list_admins, member_permissions
  10. from pyrogram import filters
  11. tdb = []
  12. @app.on_message(group=antiflood_group)
  13. async def antiflood_check(_, message):
  14. global tdb
  15. if not is_antiflood_on:
  16. return
  17. chat_id = message.chat.id
  18. user_id = message.from_user.id
  19. admins = await list_admins(chat_id)
  20. # ignore admins
  21. if user_id in admins:
  22. return
  23. for chat in tdb:
  24. if chat['chat_id'] == chat_id:
  25. for user in chat['user_ids']:
  26. if user == user_id:
  27. chat['user_ids'][user]['messages'] == \
  28. ((chat['user_ids'][user]['messages'] + 1)) \
  29. if chat['user_ids'][user]['messages'] else 1
  30. if chat['user_ids'][user]['messages'] > 7:
  31. await message.chat.restrict_member(
  32. user_id,
  33. permissions=ChatPermissions()
  34. )
  35. await message.reply_text(f"Yeah i don't like spam, Muted!")
  36. return
  37. if not tdb:
  38. tdb.append(
  39. {
  40. "chat_id": chat_id,
  41. "user_ids": [
  42. {
  43. user_id: {
  44. "messages": 1
  45. }
  46. }
  47. ]
  48. }
  49. )
  50. return
  51. @app.on_message(filters.command("flood"))
  52. @capture_err
  53. async def captcha_state(_, message):
  54. usage = "**Usage:**\n/flood [ON|OFF]"
  55. if len(message.command) != 2:
  56. await message.reply_text(usage)
  57. return
  58. user_id = message.from_user.id
  59. chat_id = message.chat.id
  60. permissions = await member_permissions(chat_id, user_id)
  61. if "can_restrict_members" not in permissions:
  62. await message.reply_text("You don't have enough permissions.")
  63. return
  64. state = message.text.split(None, 1)[1].strip()
  65. state = state.lower()
  66. if state == "on":
  67. await antiflood_on(chat_id)
  68. await message.reply_text("Muting members on 7 consecutive messages.")
  69. elif state == "off":
  70. await antiflood_off(chat_id)
  71. await message.reply_text("Disabled Antiflood")
  72. else:
  73. await message.reply_text(usage)