blacklist_chat.py 2.4 KB

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