blacklist_chat.py 2.3 KB

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