lydia.py 1.3 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"
  9. CoffeeHouseAPI = API(str(LYDIA_API))
  10. api_ = LydiaAI(CoffeeHouseAPI)
  11. is_chat = False
  12. ses = None
  13. @app.on_message(filters.command('addchatbot'))
  14. async def add_chat(_, message):
  15. global is_chat, api_, ses
  16. if not is_chat:
  17. ses = api_.create_session()
  18. is_chat = True
  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 is_chat
  25. if not is_chat:
  26. await message.reply_text("ChatBot Is Already Off")
  27. else:
  28. await message.reply_text('ChatBot Turned Off!')
  29. @app.on_message(~filters.edited & ~filters.private)
  30. async def chat_bot(_, message):
  31. global api_, is_chat, ses
  32. if not is_chat:
  33. return
  34. if not message.reply_to_message:
  35. return
  36. if not message.reply_to_message.from_user.id == BOT_ID:
  37. return
  38. query = message.text
  39. rep = api_.think_thought(text=query, session_id=ses.id)
  40. await message.reply_text(rep)