purge_me.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 pyrogram.types import Message
  22. from wbb import USERBOT_ID, USERBOT_PREFIX, app2
  23. # Yeah i know this should've been in userbot.py,
  24. # But i wrote it here for some obvious reasons.
  25. __MODULE__ = "Userbot"
  26. __HELP__ = """
  27. `.alive`
  28. Send Alive Message.
  29. `.create (b|s|c) Title`
  30. create [basic|super]group & channel
  31. `.chatbot [ENABLE|DISABLE]`
  32. Enable chatbot in a chat.
  33. `.autocorrect [ENABLE|DISABLE]`
  34. This will autocorrect your messages on the go.
  35. `.purgeme [Number of messages to purge]`
  36. Purge your own messages.
  37. Ex: .purgeme 10
  38. `.eval [Lines of code]`
  39. Execute Python Code.
  40. `.lsTasks`
  41. List running tasks (eval)
  42. `.cancelTask [ID] or Reply to .eval message`
  43. Cancel a running task (eval)
  44. `.sh [Some shell code]`
  45. Execute Shell Code.
  46. `.approve`
  47. Approve a user to PM you.
  48. `.disapprove`
  49. Disapprove a user to PM you.
  50. `.block`
  51. Block a user.
  52. `.unblock`
  53. Unblock a user.
  54. `.anonymize`
  55. Change Name/PFP Randomly.
  56. `.impersonate [User_ID|Username|Reply]`
  57. Clone profile of a user.
  58. `.useradd`
  59. To add a user in sudoers.
  60. [Don't use it if you don't know what you're doing]
  61. `.userdel`
  62. To remove a user from sudoers.
  63. `.sudoers`
  64. To list sudo users.
  65. """
  66. @app2.on_message(
  67. filters.command("purgeme", prefixes=USERBOT_PREFIX)
  68. & filters.user(USERBOT_ID)
  69. )
  70. async def purge_me_func(_, message: Message):
  71. await message.delete()
  72. if len(message.command) != 2:
  73. return
  74. n = message.text.split(None, 1)[1].strip()
  75. if not n.isnumeric():
  76. return
  77. n = int(n)
  78. if n < 1:
  79. return
  80. chat_id = message.chat.id
  81. message_ids = [
  82. m.message_id
  83. async for m in app2.search_messages(
  84. chat_id, from_user=USERBOT_ID
  85. )
  86. ][
  87. :n
  88. ] # NOTE Don't use limit param here
  89. if len(message_ids) == 0:
  90. return
  91. # A list containing lists of 100 message chunks
  92. # because we can't delete more than 100 messages at once,
  93. # we have to do it in chunks of 100, i'll choose 99 just
  94. # to be safe.
  95. to_delete = list(
  96. (
  97. message_ids[i : i + 99]
  98. for i in range(0, len(message_ids), 99)
  99. )
  100. )
  101. for hundred_messages_or_less in to_delete:
  102. await app2.delete_messages(
  103. chat_id=chat_id,
  104. message_ids=hundred_messages_or_less,
  105. revoke=True,
  106. )