async def _(event): if event.is_group: pass else: return global api_client msg = str(event.text) chat = event.chat is_chat = sql.is_chat(chat.id) if not is_chat: return if msg: if not await check_message(event): return sesh, exp = sql.get_ses(chat.id) query = msg try: if int(exp) < time(): ses = api_client.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: rep = api_client.think_thought(sesh, query) except Exception: # await event.reply(e) return async with tbot.action(event.chat_id, 'typing'): await asyncio.sleep(2) await event.reply(rep)
async def _(event): if event.is_group: pass else: return global api_client msg = str(event.text) chat = event.chat is_chat = sql.is_chat(chat.id) if not is_chat: return if msg: if not await check_message(event): return sesh, exp = sql.get_ses(chat.id) query = msg try: if int(exp) < time(): ses = api_client.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: async with tbot.action(event.chat, 'typing'): rep = api_client.think_thought(sesh, query) await event.reply(rep) except CFError as e: await tbot.send_message( OWNER_ID, f"Chatbot error: {e} occurred in {chat.id}!")