admin_misc.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. import os
  21. from pyrogram import filters
  22. from wbb import app
  23. from wbb.core.decorators.permissions import adminsOnly
  24. __MODULE__ = "Admin Miscs"
  25. __HELP__ = """
  26. /set_chat_title - Change The Name Of A Group/Channel.
  27. /set_chat_photo - Change The PFP Of A Group/Channel.
  28. /set_user_title - Change The Administrator Title Of An Admin.
  29. """
  30. @app.on_message(filters.command("set_chat_title") & ~filters.private)
  31. @adminsOnly("can_change_info")
  32. async def set_chat_title(_, message):
  33. if len(message.command) < 2:
  34. return await message.reply_text("**Usage:**\n/set_chat_title NEW NAME")
  35. old_title = message.chat.title
  36. new_title = message.text.split(None, 1)[1]
  37. await message.chat.set_title(new_title)
  38. await message.reply_text(
  39. f"Successfully Changed Group Title From {old_title} To {new_title}"
  40. )
  41. @app.on_message(filters.command("set_user_title") & ~filters.private)
  42. @adminsOnly("can_change_info")
  43. async def set_user_title(_, message):
  44. if not message.reply_to_message:
  45. return await message.reply_text(
  46. "Reply to user's message to set his admin title"
  47. )
  48. if not message.reply_to_message.from_user:
  49. return await message.reply_text(
  50. "I can't change admin title of an unknown entity"
  51. )
  52. chat_id = message.chat.id
  53. from_user = message.reply_to_message.from_user
  54. if len(message.command) < 2:
  55. return await message.reply_text(
  56. "**Usage:**\n/set_user_title NEW ADMINISTRATOR TITLE"
  57. )
  58. title = message.text.split(None, 1)[1]
  59. await app.set_administrator_title(chat_id, from_user.id, title)
  60. await message.reply_text(
  61. f"Successfully Changed {from_user.mention}'s Admin Title To {title}"
  62. )
  63. @app.on_message(filters.command("set_chat_photo") & ~filters.private)
  64. @adminsOnly("can_change_info")
  65. async def set_chat_photo(_, message):
  66. if not message.reply_to_message:
  67. return await message.reply_text(
  68. "Reply to a photo to set it as chat_photo"
  69. )
  70. if (
  71. not message.reply_to_message.photo
  72. and not message.reply_to_message.document
  73. ):
  74. return await message.reply_text(
  75. "Reply to a photo to set it as chat_photo"
  76. )
  77. photo = await message.reply_to_message.download()
  78. await message.chat.set_photo(photo)
  79. await message.reply_text("Successfully Changed Group Photo")
  80. os.remove(photo)