pmpermit.py 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. """
  2. MIT License
  3. Copyright (c) 2021 TheHamkerCat
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in all
  11. copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  18. SOFTWARE.
  19. """
  20. from wbb import app, app2, BOT_ID, USERBOT_ID, SUDOERS
  21. from pyrogram import filters
  22. from wbb.utils.dbfunctions import is_pmpermit_approved, approve_pmpermit, disapprove_pmpermit
  23. from wbb.modules.chatbot import active_chats_ubot
  24. flood = {}
  25. @app2.on_message(filters.private & ~filters.edited & ~filters.me & ~filters.bot & ~filters.user(SUDOERS))
  26. async def pmpermit_func(_, message):
  27. user_id = message.from_user.id
  28. async for m in app2.iter_history(user_id, limit=10):
  29. if m.reply_markup:
  30. await m.delete()
  31. if await is_pmpermit_approved(user_id):
  32. return
  33. if str(user_id) in flood:
  34. flood[str(user_id)] += 1
  35. else:
  36. flood[str(user_id)] = 1
  37. if flood[str(user_id)] > 5:
  38. await app2.block_user(user_id)
  39. await message.reply_text("SPAM DETECTED, USER BLOCKED.")
  40. return
  41. results = await app2.get_inline_bot_results(BOT_ID, "pmpermit")
  42. await app2.send_inline_bot_result(
  43. user_id,
  44. results.query_id,
  45. results.results[0].id,
  46. hide_via=True
  47. )
  48. @app2.on_message(filters.command("approve", prefixes=".") & filters.user(SUDOERS) & ~filters.via_bot)
  49. async def pm_approve(_, message):
  50. if not message.reply_to_message:
  51. await message.edit("Reply to a user's message to approve.")
  52. return
  53. user_id = message.reply_to_message.from_user.id
  54. if await is_pmpermit_approved(user_id):
  55. await message.edit("User is already approved to pm")
  56. return
  57. await approve_pmpermit(user_id)
  58. await message.edit("User is approved to pm")
  59. @app2.on_message(filters.command("disapprove", prefixes=".") & filters.user(SUDOERS) & ~filters.via_bot)
  60. async def pm_disapprove(_, message):
  61. if not message.reply_to_message:
  62. await message.edit("Reply to a user's message to approve.")
  63. return
  64. user_id = message.reply_to_message.from_user.id
  65. if not await is_pmpermit_approved(user_id):
  66. await message.edit("User is already disapproved to pm")
  67. return
  68. await disapprove_pmpermit(user_id)
  69. await message.edit("User is disapproved to pm")
  70. @app2.on_message(filters.command("block", prefixes=".") & filters.user(SUDOERS) & ~filters.via_bot)
  71. async def block_user_func(_, message):
  72. if not message.reply_to_message:
  73. await message.edit("Reply to a user's message to approve.")
  74. return
  75. user_id = message.reply_to_message.from_user.id
  76. await app2.block_user(user_id)
  77. await message.edit("Successfully blocked the user")
  78. @app2.on_message(filters.command("unblock", prefixes=".") & filters.user(SUDOERS) & ~filters.via_bot)
  79. async def unblock_user_func(_, message):
  80. if not message.reply_to_message:
  81. await message.edit("Reply to a user's message to approve.")
  82. return
  83. user_id = message.reply_to_message.from_user.id
  84. await app2.unblock_user(user_id)
  85. await message.edit("Successfully Unblocked the user")
  86. """ CALLBACK QUERY HANDLER """
  87. @app.on_callback_query(filters.regex("pmpermit"))
  88. async def pmpermit_cq(_, cq):
  89. global active_chats_ubot
  90. user_id = cq.from_user.id
  91. if user_id == USERBOT_ID:
  92. await cq.answer("It's For The Other Person.")
  93. return
  94. data = cq.data.split(None, 1)[1]
  95. if data == "to_scam_you":
  96. async for m in app2.iter_history(user_id, limit=10):
  97. if m.reply_markup:
  98. await m.delete()
  99. await app2.send_message(user_id, "Blocked, Go scam someone else.")
  100. await app2.block_user(user_id)
  101. elif data == "approve_me":
  102. await app2.send_message(user_id, "I'm busy right now, will approve you shortly, DO NOT SPAM.")
  103. elif data == "chitchats":
  104. await approve_pmpermit(user_id)
  105. active_chats_ubot.append(user_id)
  106. await app2.send_message(user_id, "Hello")