pmpermit.py 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. import asyncio
  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. if await is_pmpermit_approved(user_id):
  29. return
  30. async for m in app2.iter_history(user_id, limit=6):
  31. if m.reply_markup:
  32. await m.delete()
  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, f"pmpermit {user_id}")
  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=USERBOT_PREFIX) & 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. m = await message.edit("User is approved to pm")
  59. await asyncio.sleep(2)
  60. await m.delete()
  61. @app2.on_message(filters.command("disapprove", prefixes=USERBOT_PREFIX) & filters.user(SUDOERS) & ~filters.via_bot)
  62. async def pm_disapprove(_, message):
  63. if not message.reply_to_message:
  64. await message.edit("Reply to a user's message to approve.")
  65. return
  66. user_id = message.reply_to_message.from_user.id
  67. if not await is_pmpermit_approved(user_id):
  68. await message.edit("User is already disapproved to pm")
  69. async for m in app2.iter_history(user_id, limit=6):
  70. if m.reply_markup:
  71. try:
  72. await m.delete()
  73. except Exception:
  74. pass
  75. return
  76. await disapprove_pmpermit(user_id)
  77. await message.edit("User is disapproved to pm")
  78. @app2.on_message(filters.command("block", prefixes=USERBOT_PREFIX) & filters.user(SUDOERS) & ~filters.via_bot)
  79. async def block_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.block_user(user_id)
  85. await message.edit("Successfully blocked the user")
  86. @app2.on_message(filters.command("unblock", prefixes=USERBOT_PREFIX) & filters.user(SUDOERS) & ~filters.via_bot)
  87. async def unblock_user_func(_, message):
  88. if not message.reply_to_message:
  89. await message.edit("Reply to a user's message to approve.")
  90. return
  91. user_id = message.reply_to_message.from_user.id
  92. await app2.unblock_user(user_id)
  93. await message.edit("Successfully Unblocked the user")
  94. """ CALLBACK QUERY HANDLER """
  95. @app.on_callback_query(filters.regex("pmpermit"))
  96. async def pmpermit_cq(_, cq):
  97. user_id = cq.from_user.id
  98. data, victim = cq.data.split(None, 2)[1], int(cq.data.split(None, 2)[2])
  99. if data == "approve":
  100. if user_id != USERBOT_ID:
  101. await cq.answer("This Button Is Not For You")
  102. return
  103. await approve_pmpermit(victim)
  104. await app.edit_inline_text(cq.inline_message_id, "User Has Been Approved To PM.")
  105. return
  106. if user_id == USERBOT_ID:
  107. await cq.answer("It's For The Other Person.")
  108. return
  109. if data == "to_scam_you":
  110. async for m in app2.iter_history(user_id, limit=6):
  111. if m.reply_markup:
  112. await m.delete()
  113. await app2.send_message(user_id, "Blocked, Go scam someone else.")
  114. await app2.block_user(user_id)
  115. elif data == "approve_me":
  116. await app2.send_message(user_id, "I'm busy right now, will approve you shortly, DO NOT SPAM.")