pmpermit.py 5.8 KB

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