Exemplo n.º 1
0
async def chat_bot(client, message):
    global api_
    chat_id = message.chat.id
    is_chat = sql.is_chat(chat_id)
    if not is_chat:
        return
    if message.text and not message.document:
        if not await check_message(client, message):
            return
        sesh, exp = sql.get_ses(chat_id)
        query = message.text
        try:
            if int(exp) < time():
                ses = api_.create_session()
                ses_id = str(ses.id)
                expires = str(ses.expires)
                sql.set_ses(chat_id, ses_id, expires)
                sesh, exp = sql.get_ses(chat_id)
        except ValueError:
            pass
        try:
            await client.send_chat_action(chat_id, action="typing")
            rep = api_.think_thought(sesh, query)
            await asyncio.sleep(0.3)
            await message.reply_text(rep)
        except CFError as e:
            await setbot.send_message(
                Owner, f"Chatbot error: {e} occurred in {chat_id}!")
Exemplo n.º 2
0
async def add_chat(_, message):
    global api_
    chat_id = message.chat.id
    is_chat = sql.is_chat(chat_id)
    if not is_chat:
        ses = api_.create_session()
        ses_id = str(ses.id)
        expires = str(ses.expires)
        sql.set_ses(chat_id, ses_id, expires)
        await edrep(message, text="`AI successfully enabled for this chat!`")
    else:
        await edrep(message, text="`AI is already enabled for this chat!`")

    await asyncio.sleep(5)
    await message.delete()