chatbot.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. from wbb import app, LUNA_API
  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 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"))
  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.chat(active_chats) & filters.text
  38. & filters.reply
  39. & ~filters.bot)
  40. @capture_err
  41. async def chatbot_talk(_, message):
  42. if message.reply_to_message.from_user.id != BOT_ID:
  43. return
  44. query = message.text
  45. response = await fetch(f"{LUNA_API}{query}")
  46. response = response['response']
  47. await app.send_chat_action(message.chat.id, "typing")
  48. await message.reply_text(response)