Exemplo n.º 1
0
async def _(event):
    if event.is_group:
        if not await can_change_info(message=event):
            return
    else:
        return    
    global api_client
    chat = event.chat
    
    send = await event.get_sender()
    user = await tbot.get_entity(send)
    is_chat = sql.is_chat(chat.id)
    if not is_chat:
        ses = api_client.create_session()
        ses_id = str(ses.id)
        expires = str(ses.expires)
        sql.set_ses(chat.id, ses_id, expires)
        if not event.chat_id in en_chats:            
            en_chats.append(event.chat_id)
        await event.reply("English AI successfully enabled for this chat!")
        return
    if not event.chat_id in en_chats:            
        en_chats.append(event.chat_id)
        await event.reply("English only AI activated!")
    await event.reply("AI is already enabled for this chat!")
    return ""
Exemplo n.º 2
0
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)
            await event.reply(rep)
        except CFError as e:
            print(e)
Exemplo n.º 3
0
async def _(event):
    if event.is_group:
        if not await can_change_info(message=event):
            return
    else:
        return
    chat = event.chat
    send = await event.get_sender()
    user = await tbot.get_entity(send)
    is_chat = sql.is_chat(chat.id)
    if not is_chat:
        await event.reply("AI isn't enabled here in the first place!")
        return ""
    sql.rem_chat(chat.id)
    await event.reply("AI disabled successfully!")
Exemplo n.º 4
0
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.startswith("/") or msg.startswith("@"):
        return
    if msg:   
        if not await check_message(event):
            return
        if event.chat_id in en_chats:
            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)
                    await event.reply(rep)
            except CFError as e:
                print(e)
        else:
            u = msg.split()
            emj = extract_emojis(msg)
            msg = msg.replace(emj, "")
            if (      
                [(k) for k in u if k.startswith("@")]
                and [(k) for k in u if k.startswith("#")]
                and [(k) for k in u if k.startswith("/")]
                and re.findall(r"\[([^]]+)]\(\s*([^)]+)\s*\)", msg) != []
            ):

                h = " ".join(filter(lambda x: x[0] != "@", u))
                km = re.sub(r"\[([^]]+)]\(\s*([^)]+)\s*\)", r"", h)
                tm = km.split()
                jm = " ".join(filter(lambda x: x[0] != "#", tm))
                hm = jm.split()
                rm = " ".join(filter(lambda x: x[0] != "/", hm))
            elif [(k) for k in u if k.startswith("@")]:

                rm = " ".join(filter(lambda x: x[0] != "@", u))
            elif [(k) for k in u if k.startswith("#")]:
                rm = " ".join(filter(lambda x: x[0] != "#", u))
            elif [(k) for k in u if k.startswith("/")]:
                rm = " ".join(filter(lambda x: x[0] != "/", u))
            elif re.findall(r"\[([^]]+)]\(\s*([^)]+)\s*\)", msg) != []:
                rm = re.sub(r"\[([^]]+)]\(\s*([^)]+)\s*\)", r"", msg)
            else:
                rm = msg
                #print (rm)
                lan = translator.detect(rm)
            msg = rm
            test = msg
            if not "en" in lan and not lan == "":
                msg = translator.translate(test, lang_tgt="en")
            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)
                    pro = rep
                    if not "en" in lan and not lan == "":
                        pro = translator.translate(rep, lang_tgt=lan[0])
                    if event.chat_id in ws_chats:                    
                        answer = pro
                        try:
                            tts = gTTS(answer, tld="com", lang=lan[0])
                            tts.save("results.mp3")
                        except AssertionError:
                            return
                        except ValueError:
                            return
                        except RuntimeError:
                            return
                        except gTTSError:
                            return
                        with open("results.mp3", "r"):
                            await tbot.send_file(
                                event.chat_id,
                                "results.mp3",
                                voice_note=True,
                                reply_to=event.id,
                            )
                        os.remove("results.mp3")          
                    else:     
                        await event.reply(pro)
            except CFError as e:
                print(e)