chatbot.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. from wbb import app, app2, arq, BOT_ID, SUDOERS, USERBOT_ID, USERBOT_USERNAME
  2. from wbb.core.decorators.errors import capture_err
  3. from wbb.utils.filter_groups import chatbot_group
  4. from pyrogram import filters
  5. __MODULE__ = "ChatBot"
  6. __HELP__ = """
  7. /chatbot [ON|OFF] To Enable Or Disable ChatBot In Your Chat.
  8. .chatbot [ON|OFF] To Do The Same For Userbot."""
  9. active_chats_bot = []
  10. active_chats_ubot = []
  11. # Enabled | Disable Chatbot
  12. @app.on_message(filters.command("chatbot") & ~filters.edited)
  13. @capture_err
  14. async def chatbot_status(_, message):
  15. global active_chats_bot
  16. if len(message.command) != 2:
  17. await message.reply_text("**Usage**\n/chatbot [ON|OFF]")
  18. return
  19. status = message.text.split(None, 1)[1]
  20. chat_id = message.chat.id
  21. if status == "ON" or status == "on" or status == "On":
  22. if chat_id not in active_chats_bot:
  23. active_chats_bot.append(chat_id)
  24. text = "Chatbot Enabled Reply To Any Message " \
  25. + "Of Mine To Get A Reply"
  26. await message.reply_text(text)
  27. return
  28. await message.reply_text("ChatBot Is Already Enabled.")
  29. return
  30. elif status == "OFF" or status == "off" or status == "Off":
  31. if chat_id in active_chats_bot:
  32. active_chats_bot.remove(chat_id)
  33. await message.reply_text("Chatbot Disabled!")
  34. return
  35. await message.reply_text("ChatBot Is Already Disabled.")
  36. return
  37. else:
  38. await message.reply_text("**Usage**\n/chatbot [ON|OFF]")
  39. @app.on_message(filters.text & filters.reply & ~filters.bot &
  40. ~filters.via_bot & ~filters.forwarded, group=chatbot_group)
  41. @capture_err
  42. async def chatbot_talk(_, message):
  43. if message.chat.id not in active_chats_bot:
  44. return
  45. if not message.reply_to_message:
  46. return
  47. if message.reply_to_message.from_user.id != BOT_ID:
  48. return
  49. query = message.text
  50. luna = await arq.luna(query)
  51. response = luna.response
  52. await message.reply_text(response)
  53. """ FOR USERBOT """
  54. @app2.on_message(filters.command("chatbot", prefixes=".") & ~filters.edited & filters.user(SUDOERS))
  55. @capture_err
  56. async def chatbot_status_ubot(_, message):
  57. global active_chats_ubot
  58. if len(message.text.split()) != 2:
  59. await message.edit("**Usage**\n.chatbot [ON|OFF]")
  60. return
  61. status = message.text.split(None, 1)[1]
  62. chat_id = message.chat.id
  63. if status == "ON" or status == "on" or status == "On":
  64. if chat_id not in active_chats_ubot:
  65. active_chats_ubot.append(chat_id)
  66. text = "Chatbot Enabled Reply To Any Message " \
  67. + "Of Mine To Get A Reply"
  68. await message.edit(text)
  69. return
  70. await message.edit("ChatBot Is Already Enabled.")
  71. return
  72. elif status == "OFF" or status == "off" or status == "Off":
  73. if chat_id in active_chats_ubot:
  74. active_chats_bot.remove(chat_id)
  75. await message.edit("Chatbot Disabled!")
  76. return
  77. await message.edit("ChatBot Is Already Disabled.")
  78. return
  79. else:
  80. await message.edit("**Usage**\n/chatbot [ON|OFF]")
  81. @app2.on_message(~filters.me & ~filters.private & filters.text & ~filters.edited, group=chatbot_group)
  82. @capture_err
  83. async def chatbot_talk_ubot(_, message):
  84. if message.chat.id not in active_chats_ubot:
  85. return
  86. username = ("@" + str(USERBOT_USERNAME))
  87. query = message.text
  88. if message.reply_to_message:
  89. if message.reply_to_message.from_user.id != USERBOT_ID and username not in query:
  90. return
  91. else:
  92. if username not in query:
  93. return
  94. luna = await arq.luna(query)
  95. response = luna.response
  96. await message.reply_text(response)
  97. @app2.on_message(filters.text & filters.private & ~filters.me & ~filters.edited, group=(chatbot_group+1))
  98. @capture_err
  99. async def chatbot_talk_ubot_pm(_, message):
  100. if message.chat.id not in active_chats_ubot:
  101. return
  102. query = message.text
  103. await app2.send_chat_action(message.chat.id, "typing")
  104. luna = await arq.luna(query)
  105. response = luna.response
  106. await message.reply_text(response)
  107. await app2.send_chat_action(message.chat.id, "cancel")