コード例 #1
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")
コード例 #2
0
ファイル: chat_bot.py プロジェクト: shreyansh000/Chatbot
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"
        )
コード例 #3
0
ファイル: chat_bot.py プロジェクト: thakorrohan22/Chatbot
def add_user(client, message):
    if not message.reply_to_message:
        message.edit_text(
            "Reply to someone to enable chatbot for that person!")
        return
    user_id = message.reply_to_message.from_user.id
    is_user = db.is_user(user_id)
    if not is_user:
        ses = api_client.create_session()
        ses_id = str(ses.id)
        expires = str(ses.expires)
        db.set_ses(user_id, ses_id, expires)
        message.edit_text("AI enabled for user successfully!")
        LOGGER.info(f"AI enabled for user - {user_id}")
    else:
        message.edit_text("AI is already enabled for this user!")