Skip to content

Commit

Permalink
One4uBot: Update latest version from coffeehouse api
Browse files Browse the repository at this point in the history
Signed-off-by: MoveAngel <[email protected]>
  • Loading branch information
MoveAngel committed Mar 1, 2020
1 parent 6f38135 commit 75c4324
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions userbot/modules/lydia.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
Userbot module to use an AI To respond to people
"""

import coffeehouse
from coffeehouse.lydia import LydiaAI
from coffeehouse.api import API
import asyncio
from userbot import LYDIA_API_KEY

Expand All @@ -22,23 +23,23 @@

# Non-SQL Mode
ACC_LYDIA = {}
SESSION_ID = {}

if LYDIA_API_KEY:
api_key = LYDIA_API_KEY
api_client = coffeehouse.API(api_key)
api_client = API(api_key)
lydia = LydiaAI(api_client)

@register(outgoing=True, pattern="^.repcf$")
async def repcf(event):
if event.fwd_from:
return
await event.edit("Processing...")
try:
session = api_client.create_session()
session = lydia.create_session()
session_id = session.id
reply = await event.get_reply_message()
msg = reply.text
text_rep = session.think_thought((session_id, msg))
text_rep = session.think_thought(msg)
await event.edit("**Lydia says**: {0}".format(text_rep))
except Exception as e:
await event.edit(str(e))
Expand All @@ -52,10 +53,9 @@ async def addcf(event):
await event.edit("Processing...")
reply_msg = await event.get_reply_message()
if reply_msg:
session = api_client.create_session()
session = lydia.create_session()
session_id = session.id
ACC_LYDIA.update({str(event.chat_id) + " " + str(reply_msg.from_id): session})
SESSION_ID.update({str(event.chat_id) + " " + str(reply_msg.from_id): session_id})
ACC_LYDIA.update({(event.chat_id & reply_msg.from_id): session})
await event.edit("Lydia successfully enabled for user: {} in chat: {}".format(str(reply_msg.from_id), str(event.chat_id)))
else:
await event.edit("Reply to a user to activate Lydia AI on them")
Expand All @@ -69,8 +69,7 @@ async def remcf(event):
await event.edit("Processing...")
reply_msg = await event.get_reply_message()
try:
del ACC_LYDIA[str(event.chat_id) + " " + str(reply_msg.from_id)]
del SESSION_ID[str(event.chat_id) + " " + str(reply_msg.from_id)]
del ACC_LYDIA[event.chat_id & reply_msg.from_id]
await event.edit("Lydia successfully disabled for user: {} in chat: {}".format(str(reply_msg.from_id), str(event.chat_id)))
except KeyError:
await event.edit("This person does not have Lydia activated on him/her.")
Expand All @@ -79,8 +78,7 @@ async def remcf(event):
async def user(event):
user_text = event.text
try:
session = ACC_LYDIA[str(event.chat_id) + " " + str(event.from_id)]
session_id = SESSION_ID[str(event.chat_id) + " " + str(event.from_id)]
session = ACC_LYDIA[event.chat_id & event.from_id]
msg = event.text
async with event.client.action(event.chat_id, "typing"):
text_rep = session.think_thought((session_id, msg))
Expand Down

0 comments on commit 75c4324

Please sign in to comment.