Esempio n. 1
0
async def chatbot(app: Client, message: Message) -> None:
    msg = message
    if not check_message(msg):
        return
    user_id = msg.from_user.id
    if user_id not in db.USERS:
        return
    sesh, exp = db.get_ses(user_id)
    query = msg.text
    if int(exp) < time():
        ses = api_client.create_session()
        ses_id = str(ses.id)
        expires = str(ses.expires)
        db.set_ses(user_id, ses_id, expires)
        sesh, exp = ses_id, expires

    try:
        await msg.reply_chat_action("typing")
        response = api_client.think_thought(sesh, query)
        await msg.reply_text(response)
    except CFError as e:
        await app.send_message(
            chat_id=msg.chat.id,
            text=f"An error occurred:\n`{e}`",
            parse_mode="md"
        )
Esempio n. 2
0
def chatbot_pvt(client, message):
    msg = message
    user_id = msg.from_user.id

    if not user_id in db.USERS:
        ses = api_client.create_session()
        ses_id = str(ses.id)
        expires = str(ses.expires)
        db.set_ses(user_id, ses_id, expires)

    sesh: str
    sesh, exp = db.get_ses(user_id)
    query = msg.text
    if int(exp) < time():
        ses = api_client.create_session()
        ses_id = str(ses.id)
        expires = str(ses.expires)
        db.set_ses(user_id, ses_id, expires)
        sesh, exp = ses_id, expires

    try:
        app.send_chat_action(msg.chat.id, "typing")
        response = api_client.think_thought(sesh, query)
        msg.reply_text(response)
    except CFError as e:
        app.send_message(chat_id=msg.chat.id,
                         text=f"An error occurred:\n`{e}`",
                         parse_mode="md")