pmpermit.py 6.5 KB

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