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