admin_misc.py 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. import os
  21. from pyrogram import filters
  22. from wbb import app
  23. from wbb.core.decorators.permissions import adminsOnly
  24. __MODULE__ = "群资料管理"
  25. __HELP__ = """
  26. /set_chat_title - 修改群组或频道名称。
  27. /set_chat_photo - 回复图片,将其设为群头像。
  28. /set_user_title - 回复管理员消息,修改其管理员头衔。
  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("**用法:**\n/set_chat_title 新群名称")
  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"群名称已从“{old_title}”修改为“{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. "请回复该管理员的消息。"
  47. )
  48. if not message.reply_to_message.from_user:
  49. return await message.reply_text(
  50. "无法修改匿名身份或未知实体的管理员头衔。"
  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. "**用法:**\n/set_user_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"{from_user.mention} 的管理员头衔已修改为“{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. reply = message.reply_to_message
  67. if not reply:
  68. return await message.reply_text(
  69. "请回复要设为群头像的图片。"
  70. )
  71. file = reply.document or reply.photo
  72. if not file:
  73. return await message.reply_text(
  74. "请回复图片或图片文件。"
  75. )
  76. if file.file_size > 5000000:
  77. return await message.reply("文件不能超过 5 MB。")
  78. photo = await reply.download()
  79. await message.chat.set_photo(photo)
  80. await message.reply_text("群头像已更新。")
  81. os.remove(photo)