blacklist_chat.py 2.4 KB

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