blacklist_chat.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. """
  2. MIT License
  3. Copyright (c) present TheHamkerCat
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in all
  11. copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  18. SOFTWARE.
  19. """
  20. from pyrogram import filters
  21. from pyrogram.types import Message
  22. from wbb import SUDOERS, app
  23. from wbb.core.decorators.errors import capture_err
  24. from wbb.utils.dbfunctions import (
  25. blacklist_chat,
  26. blacklisted_chats,
  27. whitelist_chat,
  28. )
  29. __MODULE__ = "Blacklist Chat"
  30. __HELP__ = """
  31. **THIS MODULE IS ONLY FOR DEVS**
  32. Use this module to make the bot leave some chats
  33. in which you don't want it to be in.
  34. /blacklist_chat [CHAT_ID] - Blacklist a chat.
  35. /whitelist_chat [CHAT_ID] - Whitelist a chat.
  36. /blacklisted - Show blacklisted chats.
  37. """
  38. @app.on_message(
  39. filters.command("blacklist_chat")
  40. & SUDOERS
  41. )
  42. @capture_err
  43. async def blacklist_chat_func(_, message: Message):
  44. if len(message.command) != 2:
  45. return await message.reply_text(
  46. "**Usage:**\n/blacklist_chat [CHAT_ID]"
  47. )
  48. chat_id = int(message.text.strip().split()[1])
  49. if chat_id in await blacklisted_chats():
  50. return await message.reply_text("Chat is already blacklisted.")
  51. blacklisted = await blacklist_chat(chat_id)
  52. if blacklisted:
  53. return await message.reply_text(
  54. "Chat has been successfully blacklisted"
  55. )
  56. await message.reply_text("Something wrong happened, check logs.")
  57. @app.on_message(
  58. filters.command("whitelist_chat")
  59. & SUDOERS
  60. )
  61. @capture_err
  62. async def whitelist_chat_func(_, message: Message):
  63. if len(message.command) != 2:
  64. return await message.reply_text(
  65. "**Usage:**\n/whitelist_chat [CHAT_ID]"
  66. )
  67. chat_id = int(message.text.strip().split()[1])
  68. if chat_id not in await blacklisted_chats():
  69. return await message.reply_text("Chat is already whitelisted.")
  70. whitelisted = await whitelist_chat(chat_id)
  71. if whitelisted:
  72. return await message.reply_text(
  73. "Chat has been successfully whitelisted"
  74. )
  75. await message.reply_text("Something wrong happened, check logs.")
  76. @app.on_message(
  77. filters.command("blacklisted_chats")
  78. & SUDOERS
  79. )
  80. @capture_err
  81. async def blacklisted_chats_func(_, message: Message):
  82. text = ""
  83. for count, chat_id in enumerate(await blacklisted_chats(), 1):
  84. try:
  85. title = (await app.get_chat(chat_id)).title
  86. except Exception:
  87. title = "Private"
  88. text += f"**{count}. {title}** [`{chat_id}`]\n"
  89. if text == "":
  90. return await message.reply_text("No blacklisted chats found.")
  91. await message.reply_text(text)