示例#1
0
async def on_new_message(event):
    if event.chat_id in Config.UB_BLACK_LIST_CHAT:
        return
    if Config.LYDIA_API is None:
        return
    reply = await event.get_reply_message()
    if reply is not None and reply.from_id != borg.uid:
        return
    if not event.media:
        user_id = event.from_id
        chat_id = event.chat_id
        s = get_s(user_id, chat_id)
        if s is not None:
            session_id = s.session_id
            session_expires = s.session_expires
            query = event.text
            # Check if the session is expired
            # If this method throws an exception at this point,
            # then there's an issue with the API, Auth or Server.
            if session_expires < time():
                # re-generate session
                session = lydia.create_session()
                logger.info(session)
                session_id = session.id
                session_expires = session.expires
                logger.info(
                    add_s(user_id, chat_id, session_id, session_expires))
            # Try to think a thought.
            try:
                async with event.client.action(event.chat_id, "typing"):
                    await asyncio.sleep(1)
                    output = lydia.think_thought(session_id, query)
                    await event.reply(output)
            except cf.exception.CoffeeHouseError as e:
                logger.info(str(e))
示例#2
0
async def on_new_message(event):
    if event.chat_id in Config.UB_BLACK_LIST_CHAT:
        return
    if Config.LYDIA_API is None:
        return
    if not event.media:
        user_id = event.from_id
        chat_id = event.chat_id
        s = get_s(user_id, chat_id)
        if s is not None:
            session_id = s.session_id
            session_expires = s.session_expires
            query = event.text
            # Check if the session is expired
            # If this method throws an exception at this point,
            # then there's an issue with the API, Auth or Server.
            if session_expires < time():
                # re-generate session
                session = api_client.create_session()
                logger.info(session)
                session_id = session.id
                session_expires = session.expires
                logger.info(add_s(user_id, chat_id, session_id, session_expires))
            # Try to think a thought.
            try:
                async with event.client.action(event.chat_id, "round"):
                    await asyncio.sleep(0.1)
                    output = api_client.think_thought(session_id, query)
                    await event.reply ("🤖: " +output+ "                                                                                                  { Run By The Users Of @thanktelegram )")
            except cf.exception.CoffeeHouseError as e:
                logger.info(str(e))
示例#3
0
async def lydia_disable_enable(event):
    if event.fwd_from:
        return
    if Config.LYDIA_API is None:
        await event.edit(
            "please add required `LYDIA_API` env var,get it from coffeehouse.intellivoid.net"
        )
        return
    else:
        api_key = Config.LYDIA_API
        api_client = API(api_key)
        lydia = LydiaAI(api_client)

    input_str = event.pattern_match.group(1)

    if event.reply_to_msg_id is not None or input_str == "list" or event.is_private:
        reply_msg = None
        user_id = None
        chat_id = event.chat_id
        if event.is_private:
            user_id = event.chat_id
        if event.reply_to_msg_id is not None:
            reply_msg = await event.get_reply_message()
            user_id = reply_msg.from_id
        await event.edit("Processing...")
        if input_str == "enable":
            session = lydia.create_session()
            logger.info(session)
            logger.info(add_s(user_id, chat_id, session.id, session.expires))
            await event.edit(f"Hello there {user_id}!")
        elif input_str == "disable":
            logger.info(remove_s(user_id, chat_id))
            await event.edit(f"No, no, no, i am out.")
        elif input_str == "list":
            lsts = get_all_s()
            if len(lsts) > 0:
                output_str = "AI enabled users:\n\n"
                for lydia_ai in lsts:
                    output_str += f"[user](tg://user?id={lydia_ai.user_id}) in chat `{lydia_ai.chat_id}`\n"
            else:
                output_str = "no Lydia AI enabled users / chats. Start by replying `.enableai` to any user in any chat!"
            if len(output_str) > Config.MAX_MESSAGE_SIZE_LIMIT:
                with io.BytesIO(str.encode(output_str)) as out_file:
                    out_file.name = "lydia_ai.text"
                    await borg.send_file(event.chat_id,
                                         out_file,
                                         force_document=True,
                                         allow_cache=False,
                                         caption="Lydia AI enabled users",
                                         reply_to=event)
            else:
                await event.edit(output_str)
        else:
            await event.edit(
                "Reply To User Message to Add / Delete them from Lydia Auto-Chat."
            )
    else:
        await event.edit(
            "Reply To A User's Message to Add / Delete them from Lydia Auto-Chat."
        )
示例#4
0
async def lydia_disable_enable(event):
    if event.fwd_from:
        return
    if Config.LYDIA_API is None:
        await event.edit("please add required `LYDIA_API` env var")
        return
    if event.reply_to_msg_id is not None:
        input_str = event.pattern_match.group(1)
        reply_msg = await event.get_reply_message()
        user_id = reply_msg.from_id
        chat_id = event.chat_id
        await event.edit("Processing...")
        if input_str == "ena":
            # Create a new chat session (Like a conversation)
            session = lydia.create_session()
            logger.info(session)
            # logger.info("Session ID: {0}".format(session.id))
            # logger.info("Session Available: {0}".format(str(session.available)))
            # logger.info("Session Language: {0}".format(str(session.language)))
            # logger.info("Session Expires: {0}".format(str(session.expires)))
            logger.info(add_s(user_id, chat_id, session.id, session.expires))
            await event.edit(
                f"Lydia AI turned on for [user](tg://user?id={user_id}) in chat: `{chat_id}`"
            )
        elif input_str == "del":
            logger.info(remove_s(user_id, chat_id))
            await event.edit(
                f"Lydia AI turned off for [user](tg://user?id={user_id}) in chat: `{chat_id}`"
            )
        elif input_str == "lst":
            lsts = get_all_s()
            if len(lsts) > 0:
                output_str = "Lydia AI enabled users:\n\n"
                for lydia_ai in lsts:
                    output_str += f"[user](tg://user?id={lydia_ai.user_id}) in chat `{lydia_ai.chat_id}`\n"
            else:
                output_str = "no Lydia AI enabled users / chats. Start by replying `.enacf` to any user in any chat!"
            if len(output_str) > Config.MAX_MESSAGE_SIZE_LIMIT:
                with io.BytesIO(str.encode(output_str)) as out_file:
                    out_file.name = "lydia_ai.text"
                    await event.client.send_file(
                        event.chat_id,
                        out_file,
                        force_document=True,
                        allow_cache=False,
                        caption="Lydia AI enabled users",
                        reply_to=event)
            else:
                await event.edit(output_str)
        else:
            await event.edit(
                "Reply To User Message to Add / Delete them from Lydia Auto-Chat."
            )
    else:
        await event.edit(
            "Reply To A User's Message to Add / Delete them from Lydia Auto-Chat."
        )
示例#5
0
async def lydia_disable_enable(event):
    if event.fwd_from:
        return
    if Config.LYDIA_API is None:
        await event.edit("please add required `LYDIA_API` env var")
        return
    if event.reply_to_msg_id is not None:
        input_str = event.pattern_match.group(1)
        reply_msg = await event.get_reply_message()
        user_id = reply_msg.from_id
        chat_id = event.chat_id
        await event.edit("Processing...")
        if input_str == "e":
            session = api_client.create_session()
            logger.info(session)
            logger.info(add_s(user_id, chat_id, session.id, session.expires))
            await event.edit(
                f"[Hi ☺� , How are you](tg://user?id={user_id})")
        elif input_str == "d":
            logger.info(remove_s(user_id, chat_id))
            await event.edit(
                f"[🥺 Bye , have to go...](tg://user?id={user_id})")
        elif input_str == "l":
            lsts = get_all_s()
            if len(lsts) > 0:
                output_str = "AI enabled users:\n\n"
                for lydia_ai in lsts:
                    output_str += f"[user](tg://user?id={lydia_ai.user_id}) in chat `{lydia_ai.chat_id}`\n"
            else:
                output_str = "no Lydia AI enabled users / chats. Start by replying `.enacf` to any user in any chat!"
            if len(output_str) > Config.MAX_MESSAGE_SIZE_LIMIT:
                with io.BytesIO(str.encode(output_str)) as out_file:
                    out_file.name = "lydia_ai.text"
                    await borg.send_file(event.chat_id,
                                         out_file,
                                         force_document=True,
                                         allow_cache=False,
                                         caption="Lydia AI enabled users",
                                         reply_to=event)
            else:
                await event.edit(output_str)
        else:
            await event.edit(
                "Reply To User Message to Add / Delete them from Lydia Auto-Chat."
            )
    else:
        await event.edit(
            "Reply To A User's Message to Add / Delete them from Lydia Auto-Chat."
        )