purge_me.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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, eor
  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. `.sh [Some shell code]`
  43. Execute Shell Code.
  44. `.approve`
  45. Approve a user to PM you.
  46. `.disapprove`
  47. Disapprove a user to PM you.
  48. `.block`
  49. Block a user.
  50. `.unblock`
  51. Unblock a user.
  52. `.anonymize`
  53. Change Name/PFP Randomly.
  54. `.impersonate [User_ID|Username|Reply]`
  55. Clone profile of a user.
  56. `.useradd`
  57. To add a user in sudoers.
  58. [Don't use it if you don't know what you're doing]
  59. `.userdel`
  60. To remove a user from sudoers.
  61. `.sudoers`
  62. To list sudo users.
  63. `.download [URL or reply to a file]`
  64. Download a file from TG or URL
  65. `.upload [URL or File Path]`
  66. Upload a file from local or URL
  67. `.parse_preview [REPLY TO A MESSAGE]`
  68. Parse a web_page(link) preview
  69. """
  70. @app2.on_message(
  71. filters.command("purgeme", prefixes=USERBOT_PREFIX)
  72. & filters.user(USERBOT_ID)
  73. )
  74. async def purge_me_func(_, message: Message):
  75. if len(message.command) != 2:
  76. return await message.delete()
  77. n = message.text.split(None, 1)[1].strip()
  78. if not n.isnumeric():
  79. return await eor(message, text="Invalid Args")
  80. n = int(n)
  81. if n < 1:
  82. return await eor(message, text="Need a number >=1")
  83. chat_id = message.chat.id
  84. message_ids = [
  85. m.message_id
  86. async for m in app2.search_messages(
  87. chat_id,
  88. from_user=int(USERBOT_ID),
  89. limit=n,
  90. )
  91. ]
  92. if not message_ids:
  93. return await eor(message, text="No messages found.")
  94. # A list containing lists of 100 message chunks
  95. # because we can't delete more than 100 messages at once,
  96. # we have to do it in chunks of 100, i'll choose 99 just
  97. # to be safe.
  98. to_delete = [
  99. message_ids[i : i + 99] for i in range(0, len(message_ids), 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. )