blacklist_chat.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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__ = "Blacklist Chat"
  11. __HELP__ = """
  12. **THIS MODULE IS ONLY FOR DEVS**
  13. Use this module to make the bot leave some chats
  14. in which you don't want it to be in.
  15. /blacklist_chat [CHAT_ID] - Blacklist a chat.
  16. /whitelist_chat [CHAT_ID] - Whitelist a chat.
  17. /blacklisted - Show blacklisted chats.
  18. """
  19. @app.on_message(
  20. filters.command("blacklist_chat")
  21. & SUDOERS
  22. & ~filters.edited
  23. )
  24. @capture_err
  25. async def blacklist_chat_func(_, message: Message):
  26. if len(message.command) != 2:
  27. return await message.reply_text(
  28. "**Usage:**\n/blacklist_chat [CHAT_ID]"
  29. )
  30. chat_id = int(message.text.strip().split()[1])
  31. if chat_id in await blacklisted_chats():
  32. return await message.reply_text("Chat is already blacklisted.")
  33. blacklisted = await blacklist_chat(chat_id)
  34. if blacklisted:
  35. return await message.reply_text(
  36. "Chat has been successfully blacklisted"
  37. )
  38. await message.reply_text("Something wrong happened, check logs.")
  39. @app.on_message(
  40. filters.command("whitelist_chat")
  41. & SUDOERS
  42. & ~filters.edited
  43. )
  44. @capture_err
  45. async def whitelist_chat_func(_, message: Message):
  46. if len(message.command) != 2:
  47. return await message.reply_text(
  48. "**Usage:**\n/whitelist_chat [CHAT_ID]"
  49. )
  50. chat_id = int(message.text.strip().split()[1])
  51. if chat_id not in await blacklisted_chats():
  52. return await message.reply_text("Chat is already whitelisted.")
  53. whitelisted = await whitelist_chat(chat_id)
  54. if whitelisted:
  55. return await message.reply_text(
  56. "Chat has been successfully whitelisted"
  57. )
  58. await message.reply_text("Something wrong happened, check logs.")
  59. @app.on_message(
  60. filters.command("blacklisted_chats")
  61. & SUDOERS
  62. & ~filters.edited
  63. )
  64. @capture_err
  65. async def blacklisted_chats_func(_, message: Message):
  66. text = ""
  67. for count, chat_id in enumerate(await blacklisted_chats(), 1):
  68. try:
  69. title = (await app.get_chat(chat_id)).title
  70. except Exception:
  71. title = "Private"
  72. text += f"**{count}. {title}** [`{chat_id}`]\n"
  73. if text == "":
  74. return await message.reply_text("No blacklisted chats found.")
  75. await message.reply_text(text)