chatbot.py 1.9 KB

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