pmpermit.py 5.9 KB

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