chatbot.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. from wbb import app, arq
  2. from wbb.utils.errors import capture_err
  3. from wbb.utils.botinfo import BOT_ID
  4. from wbb.utils.filter_groups import chatbot_group
  5. from pyrogram import filters
  6. __MODULE__ = "ChatBot"
  7. __HELP__ = "/chatbot [ON|OFF] To Enable Or Disable ChatBot In Your Chat."
  8. active_chats = []
  9. # Enabled | Disable Chatbot
  10. @app.on_message(filters.command("chatbot") & ~filters.edited)
  11. @capture_err
  12. async def chatbot_status(_, message):
  13. global active_chats
  14. if len(message.command) != 2:
  15. await message.reply_text("/chatbot [ON|OFF]")
  16. return
  17. status = message.text.split(None, 1)[1]
  18. chat_id = message.chat.id
  19. if status == "ON" or status == "on" or status == "On":
  20. if chat_id not in active_chats:
  21. active_chats.append(chat_id)
  22. text = "Chatbot Enabled Reply To Any Message" \
  23. + "Of Mine To Get A Reply"
  24. await message.reply_text(text)
  25. return
  26. await message.reply_text("ChatBot Is Already Enabled.")
  27. return
  28. elif status == "OFF" or status == "off" or status == "Off":
  29. if chat_id in active_chats:
  30. active_chats.remove(chat_id)
  31. await message.reply_text("Chatbot Disabled!")
  32. return
  33. await message.reply_text("ChatBot Is Already Disabled.")
  34. return
  35. else:
  36. await message.reply_text("/chatbot [ON|OFF]")
  37. @app.on_message(filters.text & filters.reply & ~filters.bot &
  38. ~filters.via_bot & ~filters.forwarded, group=chatbot_group)
  39. @capture_err
  40. async def chatbot_talk(_, message):
  41. if message.chat.id not in active_chats:
  42. return
  43. if message.reply_to_message.from_user.id != BOT_ID:
  44. return
  45. query = message.text
  46. luna = await arq.luna(query)
  47. response = luna.response
  48. await message.reply_text(response)