pmpermit.py 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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, USERBOT_PREFIX
  21. from pyrogram import filters
  22. from wbb.utils.dbfunctions import is_pmpermit_approved, approve_pmpermit, disapprove_pmpermit
  23. from wbb.core.decorators.errors import capture_err
  24. import asyncio
  25. flood = {}
  26. @app2.on_message(filters.private & ~filters.edited & ~filters.me & ~filters.bot & ~filters.user(SUDOERS))
  27. @capture_err
  28. async def pmpermit_func(_, message):
  29. user_id = message.from_user.id
  30. if await is_pmpermit_approved(user_id):
  31. return
  32. async for m in app2.iter_history(user_id, limit=6):
  33. if m.reply_markup:
  34. await m.delete()
  35. if str(user_id) in flood:
  36. flood[str(user_id)] += 1
  37. else:
  38. flood[str(user_id)] = 1
  39. if flood[str(user_id)] > 5:
  40. await app2.block_user(user_id)
  41. await message.reply_text("SPAM DETECTED, USER BLOCKED.")
  42. return
  43. results = await app2.get_inline_bot_results(BOT_ID, f"pmpermit {user_id}")
  44. await app2.send_inline_bot_result(
  45. user_id,
  46. results.query_id,
  47. results.results[0].id,
  48. hide_via=True
  49. )
  50. @app2.on_message(filters.command("approve", prefixes=USERBOT_PREFIX) & filters.user(SUDOERS) & ~filters.via_bot)
  51. @capture_err
  52. async def pm_approve(_, message):
  53. if not message.reply_to_message:
  54. await edit_or_reply(message, text="Reply to a user's message to approve.")
  55. return
  56. user_id = message.reply_to_message.from_user.id
  57. if await is_pmpermit_approved(user_id):
  58. await edit_or_reply(message, text="User is already approved to pm")
  59. return
  60. await approve_pmpermit(user_id)
  61. m = await edit_or_reply(message, text="User is approved to pm")
  62. await asyncio.sleep(2)
  63. await m.delete()
  64. @app2.on_message(filters.command("disapprove", prefixes=USERBOT_PREFIX) & filters.user(SUDOERS) & ~filters.via_bot)
  65. async def pm_disapprove(_, message):
  66. if not message.reply_to_message:
  67. await edit_or_reply(message, text="Reply to a user's message to approve.")
  68. return
  69. user_id = message.reply_to_message.from_user.id
  70. if not await is_pmpermit_approved(user_id):
  71. await edit_or_reply(message, text="User is already disapproved to pm")
  72. async for m in app2.iter_history(user_id, limit=6):
  73. if m.reply_markup:
  74. try:
  75. await m.delete()
  76. except Exception:
  77. pass
  78. return
  79. await disapprove_pmpermit(user_id)
  80. await edit_or_reply(message, text="User is disapproved to pm")
  81. @app2.on_message(filters.command("block", prefixes=USERBOT_PREFIX) & filters.user(SUDOERS) & ~filters.via_bot)
  82. @capture_err
  83. async def block_user_func(_, message):
  84. if not message.reply_to_message:
  85. await edit_or_reply(message, text="Reply to a user's message to block.")
  86. return
  87. user_id = message.reply_to_message.from_user.id
  88. await app2.block_user(user_id)
  89. await edit_or_reply(message, text="Successfully blocked the user")
  90. @app2.on_message(filters.command("unblock", prefixes=USERBOT_PREFIX) & filters.user(SUDOERS) & ~filters.via_bot)
  91. async def unblock_user_func(_, message):
  92. if not message.reply_to_message:
  93. await edit_or_reply(message, text="Reply to a user's message to unblock.")
  94. return
  95. user_id = message.reply_to_message.from_user.id
  96. await app2.unblock_user(user_id)
  97. await edit_or_reply(message, text="Successfully Unblocked the user")
  98. """ CALLBACK QUERY HANDLER """
  99. flood2 = {}
  100. @app.on_callback_query(filters.regex("pmpermit"))
  101. async def pmpermit_cq(_, cq):
  102. user_id = cq.from_user.id
  103. data, victim = cq.data.split(None, 2)[1], cq.data.split(None, 2)[2]
  104. if data == "approve":
  105. if user_id != USERBOT_ID:
  106. await cq.answer("This Button Is Not For You")
  107. return
  108. await approve_pmpermit(int(victim))
  109. await app.edit_inline_text(cq.inline_message_id, "User Has Been Approved To PM.")
  110. return
  111. if user_id == USERBOT_ID:
  112. await cq.answer("It's For The Other Person.")
  113. return
  114. if data == "to_scam_you":
  115. async for m in app2.iter_history(user_id, limit=6):
  116. if m.reply_markup:
  117. await m.delete()
  118. await app2.send_message(user_id, "Blocked, Go scam someone else.")
  119. await app2.block_user(user_id)
  120. elif data == "approve_me":
  121. if str(user_id) in flood2:
  122. flood2[str(user_id)] += 1
  123. else:
  124. flood2[str(user_id)] = 1
  125. if flood2[str(user_id)] > 5:
  126. await app2.send_message(user_id, "SPAM DETECTED, USER BLOCKED.")
  127. await app2.block_user(user_id)
  128. return
  129. await app2.send_message(user_id, "I'm busy right now, will approve you shortly, DO NOT SPAM.")