purge_me.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. """
  2. MIT License
  3. Copyright (c) 2023 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, log, telegraph
  23. __MODULE__ = "Userbot"
  24. TEXT = """
  25. <code>alive</code> → Send Alive Message.<br>
  26. <code>create (b|s|c) Title</code> → create [basic|super]group & channel<br>
  27. <code>chatbot [ENABLE|DISABLE]</code> → Enable chatbot in a chat.<br>
  28. <code>autocorrect [ENABLE|DISABLE]</code> → This will autocorrect your messages on the go.<br>
  29. <code>purgeme [Number of messages to purge]</code> → Purge your own messages.<br>
  30. <code>eval [Lines of code]</code> → Execute Python Code.<br>
  31. <code>lsTasks</code> → List running tasks (eval)<br>
  32. <code>sh [Some shell code]</code> → Execute Shell Code.<br>
  33. <code>approve</code> → Approve a user to PM you.<br>
  34. <code>disapprove</code> → Disapprove a user to PM you.<br>
  35. <code>block</code> → Block a user.<br>
  36. <code>unblock</code> → Unblock a user.<br>
  37. <code>anonymize</code> → Change Name/PFP Randomly.<br>
  38. <code>impersonate [User_ID|Username|Reply]</code> → Clone profile of a user.<br>
  39. <code>useradd</code> → To add a user in sudoers. [UNSAFE]<br>
  40. <code>userdel</code> → To remove a user from sudoers.<br>
  41. <code>sudoers</code> → To list sudo users.<br>
  42. <code>download [URL or reply to a file]</code> → Download a file from TG or URL<br>
  43. <code>upload [URL or File Path]</code> → Upload a file from local or URL<br>
  44. <code>parse_preview [REPLY TO A MESSAGE]</code> → Parse a web_page(link) preview<br>
  45. <code>id</code> → Same as /id but for Ubot<br>
  46. <code>paste</code> → Paste shit on batbin.<br>
  47. <code>help</code> → Get link to this page.<br>
  48. <code>kang</code> → Kang stickers.<br>
  49. <code>dice</code> → Roll a dice.<br>
  50. """
  51. log.info("Pasting userbot commands on telegraph")
  52. __HELP__ = f"""**Commands:** {telegraph.create_page(
  53. "Userbot Commands",
  54. html_content=TEXT,
  55. )['url']}"""
  56. log.info("Done pasting userbot commands on telegraph")
  57. @app2.on_message(
  58. filters.command("help", prefixes=USERBOT_PREFIX) & filters.user(USERBOT_ID)
  59. )
  60. async def get_help(_, message: Message):
  61. await eor(
  62. message,
  63. text=__HELP__,
  64. disable_web_page_preview=True,
  65. )
  66. @app2.on_message(
  67. filters.command(["purgeme", "purge_me"], prefixes=USERBOT_PREFIX)
  68. & filters.user(USERBOT_ID)
  69. )
  70. async def purge_me_func(_, message: Message):
  71. if len(message.command) != 2:
  72. return await message.delete()
  73. n = message.text.split(None, 1)[1].strip()
  74. if not n.isnumeric():
  75. return await eor(message, text="Invalid Args")
  76. n = int(n)
  77. if n < 1:
  78. return await eor(message, text="Need a number >=1")
  79. chat_id = message.chat.id
  80. message_ids = [
  81. m.id
  82. async for m in app2.search_messages(
  83. chat_id,
  84. from_user=int(USERBOT_ID),
  85. limit=n,
  86. )
  87. ]
  88. if not message_ids:
  89. return await eor(message, text="No messages found.")
  90. # A list containing lists of 100 message chunks
  91. # because we can't delete more than 100 messages at once,
  92. # we have to do it in chunks of 100, i'll choose 99 just
  93. # to be safe.
  94. to_delete = [message_ids[i : i + 99] for i in range(0, len(message_ids), 99)]
  95. for hundred_messages_or_less in to_delete:
  96. await app2.delete_messages(
  97. chat_id=chat_id,
  98. message_ids=hundred_messages_or_less,
  99. revoke=True,
  100. )