blacklist_chat.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. async def blacklist_chat_func(_, message: Message):
  18. if len(message.command) != 2:
  19. await message.reply_text("**Usage:**\n/blacklist_chat [CHAT_ID]")
  20. return
  21. chat_id = int(message.text.strip().split()[1])
  22. if chat_id in await blacklisted_chats():
  23. await message.reply_text("Chat is already blacklisted.")
  24. return
  25. blacklisted = await blacklist_chat(chat_id)
  26. if blacklisted:
  27. await message.reply_text("Chat has been successfully blacklisted")
  28. return
  29. await message.reply_text("Something wrong happened, check logs.")
  30. @app.on_message(filters.command("whitelist_chat") & filters.user(SUDOERS))
  31. async def whitelist_chat_func(_, message: Message):
  32. if len(message.command) != 2:
  33. await message.reply_text("**Usage:**\n/whitelist_chat [CHAT_ID]")
  34. return
  35. chat_id = int(message.text.strip().split()[1])
  36. if chat_id not in await blacklisted_chats():
  37. await message.reply_text("Chat is already whitelisted.")
  38. return
  39. whitelisted = await whitelist_chat(chat_id)
  40. if whitelisted:
  41. await message.reply_text("Chat has been successfully whitelisted")
  42. return
  43. await message.reply_text("Something wrong happened, check logs.")
  44. @app.on_message(filters.command("blacklisted_chats") & filters.user(SUDOERS))
  45. async def blacklisted_chats_func(_, message: Message):
  46. text = ""
  47. for count, chat_id in enumerate(await blacklisted_chats(), 1):
  48. title = (await app.get_chat(chat_id)).title
  49. text += f"**{count}. {title}** [`{chat_id}`]\n"
  50. await message.reply_text(text)