blacklist_chat.py 2.3 KB

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