admin_misc.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 wbb import SUDOERS, app
  22. from wbb.core.decorators.errors import capture_err
  23. from wbb.modules.admin import member_permissions
  24. import os
  25. __MODULE__ = "Admin Miscs"
  26. __HELP__ = """
  27. /set_chat_title - Change The Name Of A Group/Channel.
  28. /set_chat_photo - Change The PFP Of A Group/Channel.
  29. /set_user_title - Change The Administrator Title Of An Admin.
  30. """
  31. @app.on_message(filters.command("set_chat_title") & ~filters.private)
  32. @capture_err
  33. async def set_chat_title(_, message):
  34. try:
  35. chat_id = message.chat.id
  36. user_id = message.from_user.id
  37. if user_id not in SUDOERS:
  38. permissions = await member_permissions(chat_id, user_id)
  39. if "can_change_info" not in permissions:
  40. await message.reply_text("You Don't Have Enough Permissions.")
  41. return
  42. if len(message.command) < 2:
  43. await message.reply_text("**Usage:**\n/set_chat_title NEW NAME")
  44. return
  45. old_title = message.chat.title
  46. new_title = message.text.split(None, 1)[1]
  47. await message.chat.set_title(new_title)
  48. await message.reply_text(f"Successfully Changed Group Title From {old_title} To {new_title}")
  49. except Exception as e:
  50. print(e)
  51. await message.reply_text(e)
  52. @app.on_message(filters.command("set_user_title") & ~filters.private)
  53. @capture_err
  54. async def set_user_title(_, message):
  55. try:
  56. chat_id = message.chat.id
  57. user_id = message.from_user.id
  58. from_user = message.reply_to_message.from_user
  59. if user_id not in SUDOERS:
  60. permissions = await member_permissions(chat_id, user_id)
  61. if "can_change_info" not in permissions:
  62. await message.reply_text("You Don't Have Enough Permissions.")
  63. return
  64. if len(message.command) < 2:
  65. await message.reply_text("**Usage:**\n/set_user_title NEW ADMINISTRATOR TITLE")
  66. return
  67. title = message.text.split(None, 1)[1]
  68. await app.set_administrator_title(chat_id, from_user.id, title)
  69. await message.reply_text(f"Successfully Changed {from_user.mention}'s Admin Title To {title}")
  70. except Exception as e:
  71. print(e)
  72. await message.reply_text(e)
  73. @app.on_message(filters.command("set_chat_photo") & ~filters.private)
  74. @capture_err
  75. async def set_chat_photo(_, message):
  76. try:
  77. chat_id = message.chat.id
  78. user_id = message.from_user.id
  79. if user_id not in SUDOERS:
  80. permissions = await member_permissions(chat_id, user_id)
  81. if "can_change_info" not in permissions:
  82. await message.reply_text("You Don't Have Enough Permissions.")
  83. return
  84. if not message.reply_to_message:
  85. await message.reply_text("Reply to a photo to set it as chat_photo")
  86. return
  87. if not message.reply_to_message.photo and not message.reply_to_message.document:
  88. await message.reply_text("Reply to a photo to set it as chat_photo")
  89. return
  90. photo = await message.reply_to_message.download()
  91. await message.chat.set_photo(photo)
  92. await message.reply_text("Successfully Changed Group Photo")
  93. os.remove(photo)
  94. except Exception as e:
  95. print(e)
  96. await message.reply_text(e)