anonymize.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. """
  2. MIT License
  3. Copyright (c) 2024 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 asyncio import gather
  21. from io import BytesIO
  22. from json import loads
  23. from os import remove
  24. from secrets import choice
  25. from traceback import format_exc
  26. from pyrogram import filters
  27. from pyrogram.types import Chat, Message
  28. from wbb import LOG_GROUP_ID, SUDOERS, USERBOT_ID, USERBOT_PREFIX
  29. from wbb import aiohttpsession as session
  30. from wbb import app, app2
  31. from wbb.modules.userbot import eor
  32. from wbb.utils.functions import extract_user
  33. @app2.on_message(
  34. filters.command("anonymize", prefixes=USERBOT_PREFIX)
  35. & ~filters.forwarded
  36. & ~filters.via_bot
  37. & SUDOERS
  38. )
  39. async def change_profile(_, message: Message):
  40. m = await eor(message, text="Anonymizing...")
  41. try:
  42. image_resp, name_resp = await gather(
  43. session.get("https://thispersondoesnotexist.com/image"),
  44. session.get(
  45. "https://raw.githubusercontent.com/dominictarr/"
  46. + "random-name/master/first-names.json"
  47. ),
  48. )
  49. image = BytesIO(await image_resp.read())
  50. image.name = "a.png"
  51. name = choice(loads(await name_resp.text()))
  52. await gather(
  53. app2.set_profile_photo(photo=image),
  54. app2.update_profile(first_name=name),
  55. )
  56. except Exception as e:
  57. e = format_exc()
  58. err = await app.send_message(LOG_GROUP_ID, text=f"`{e}`")
  59. return await m.edit(f"**Error**: {err.link}")
  60. await m.edit(f"[Anonymized.](tg://user?id={USERBOT_ID})")
  61. image.close()
  62. @app2.on_message(
  63. filters.command("impersonate", prefixes=USERBOT_PREFIX)
  64. & ~filters.forwarded
  65. & ~filters.via_bot
  66. & SUDOERS
  67. )
  68. async def impersonate(_, message: Message):
  69. user_id = await extract_user(message)
  70. if not user_id:
  71. return await eor(message, text="Can't impersonate an anonymous user.")
  72. if user_id == USERBOT_ID:
  73. return eor(message, text="Can't impersonate myself.")
  74. m = await eor(message, text="Processing...")
  75. try:
  76. user: Chat = await app2.get_chat(user_id)
  77. fname = user.first_name
  78. lname = user.last_name or ""
  79. bio = user.bio or ""
  80. pfp, _ = await gather(
  81. app2.download_media(user.photo.big_file_id),
  82. app2.update_profile(fname, lname, bio),
  83. )
  84. await app2.set_profile_photo(photo=pfp)
  85. remove(pfp)
  86. except Exception as e:
  87. e = format_exc()
  88. err = await app.send_message(LOG_GROUP_ID, text=f"`{e}`")
  89. return await m.edit(f"**Error**: {err.link}")
  90. await m.edit(f"[Done](tg://user?id={USERBOT_ID})")