lydia.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. from coffeehouse.api import API
  2. from coffeehouse.lydia import LydiaAI
  3. from pyrogram import filters
  4. from wbb import app
  5. from wbb.utils.botinfo import BOT_ID
  6. from wbb import LYDIA_API
  7. __MODULE__ = 'Lydia'
  8. __HELP__ = "Lydia AI Chatbot\n /addchatbot - To Turn On Lydia\n /rmchatbot - To Turn Off Lydia"
  9. CoffeeHouseAPI = API(str(LYDIA_API))
  10. api_ = LydiaAI(CoffeeHouseAPI)
  11. chats = []
  12. ses = None
  13. @app.on_message(filters.command('addchatbot'))
  14. async def add_chat(_, message):
  15. global chats, api_, ses
  16. if message.chat.id not in chats:
  17. ses = api_.create_session()
  18. chats.append(message.chat.id)
  19. await message.reply_text('ChatBot enabled!')
  20. else:
  21. await message.reply_text('ChatBot Is Already Enabled')
  22. @app.on_message(filters.command('rmchatbot'))
  23. async def remove_chat(_, message):
  24. global chats
  25. if message.chat.id not in chats:
  26. await message.reply_text("ChatBot Is Already Off")
  27. else:
  28. chats.remove(message.chat.id)
  29. await message.reply_text('ChatBot Turned Off!')
  30. @app.on_message(~filters.edited & ~filters.private & filters.text & filters.reply & ~filters.forwarded)
  31. async def chat_bot(_, message):
  32. global api_, chats, ses
  33. if message.chat.id not in chats:
  34. return
  35. if not message.reply_to_message.from_user.id == BOT_ID:
  36. return
  37. await app.send_chat_action(message.chat.id, "typing")
  38. query = message.text
  39. rep = api_.think_thought(text=query, session_id=ses.id)
  40. await message.reply_text(rep)