blacklist_chat.py 2.4 KB

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