blacklist_chat.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. from pyrogram import filters
  2. from pyrogram.types import Message
  3. from wbb import SUDOERS, app
  4. from wbb.core.decorators.errors import capture_err
  5. from wbb.utils.dbfunctions import (
  6. blacklist_chat,
  7. blacklisted_chats,
  8. whitelist_chat,
  9. )
  10. __MODULE__ = "群组访问黑名单"
  11. __HELP__ = """
  12. **此功能仅供超级管理员使用**
  13. /blacklist_chat [群组 ID] - 将群组加入访问黑名单。
  14. /whitelist_chat [群组 ID] - 将群组移出访问黑名单。
  15. /blacklisted_chats - 查看群组访问黑名单。
  16. """
  17. @app.on_message(filters.command("blacklist_chat") & SUDOERS)
  18. @capture_err
  19. async def blacklist_chat_func(_, message: Message):
  20. if len(message.command) != 2:
  21. return await message.reply_text(
  22. "**用法:**\n/blacklist_chat [群组 ID]"
  23. )
  24. chat_id = int(message.text.strip().split()[1])
  25. if chat_id in await blacklisted_chats():
  26. return await message.reply_text("该群组已在访问黑名单中。")
  27. blacklisted = await blacklist_chat(chat_id)
  28. if blacklisted:
  29. return await message.reply_text(
  30. "已将该群组加入访问黑名单。"
  31. )
  32. await message.reply_text("操作失败,请检查运行日志。")
  33. @app.on_message(filters.command("whitelist_chat") & SUDOERS)
  34. @capture_err
  35. async def whitelist_chat_func(_, message: Message):
  36. if len(message.command) != 2:
  37. return await message.reply_text(
  38. "**用法:**\n/whitelist_chat [群组 ID]"
  39. )
  40. chat_id = int(message.text.strip().split()[1])
  41. if chat_id not in await blacklisted_chats():
  42. return await message.reply_text("该群组不在访问黑名单中。")
  43. whitelisted = await whitelist_chat(chat_id)
  44. if whitelisted:
  45. return await message.reply_text(
  46. "已将该群组移出访问黑名单。"
  47. )
  48. await message.reply_text("操作失败,请检查运行日志。")
  49. @app.on_message(filters.command("blacklisted_chats") & SUDOERS)
  50. @capture_err
  51. async def blacklisted_chats_func(_, message: Message):
  52. text = ""
  53. for count, chat_id in enumerate(await blacklisted_chats(), 1):
  54. try:
  55. title = (await app.get_chat(chat_id)).title
  56. except Exception:
  57. title = "未知群组"
  58. text += f"**{count}. {title}** [`{chat_id}`]\n"
  59. if text == "":
  60. return await message.reply_text("群组访问黑名单为空。")
  61. await message.reply_text(text)