コード例 #1
0
ファイル: lydia.py プロジェクト: zeuslord224/Nana-Remix
async def remove_chat(_, message):
    chat_id = message.chat.id
    is_chat = sql.is_chat(chat_id)
    if not is_chat:
        await message.reply("AI isn't enabled here in the first place!")
    else:
        sql.rem_chat(chat_id)
        await message.reply('AI disabled successfully!')
コード例 #2
0
ファイル: lydia.py プロジェクト: zeuslord224/Nana-Remix
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)
            reply_text = re.sub(r'[rl]', 'w', rep)
            reply_text = re.sub(r'[rl]', 'w', rep)
            reply_text = re.sub(r'[RL]', 'W', reply_text)
            reply_text = re.sub(r'[RL]', 'W', reply_text)
            reply_text = re.sub(r'n([aeiouaeiou])', r'ny\1', reply_text)
            reply_text = re.sub(r'r([aeiouaeiou])', r'w\1', reply_text)
            reply_text = re.sub(r'n([aeiou])', r'ny\1', reply_text)
            reply_text = re.sub(r'N([aeiouAEIOU])', r'Ny\1', reply_text)
            reply_text = re.sub(r'N([aeiouAEIOU])', r'Ny\1', reply_text)
            reply_text = re.sub(
                r'\!+',
                ' ' + random.choice(meme_strings.faces),
                reply_text,
            )
            reply_text = re.sub(
                r'!+',
                ' ' + random.choice(meme_strings.faces),
                reply_text,
            )
            reply_text = reply_text.replace('ove', 'uv')
            reply_text = reply_text.replace('ove', 'uv')
            reply_text = reply_text.replace('.', ',,.')
            reply_text += ' ' + random.choice(meme_strings.faces)
            await asyncio.sleep(0.3)
            await message.reply_text(reply_text.lower(), quote=True)
        except CFError as e:
            await client.send_message(
                Owner,
                f'Chatbot error: {e} occurred in {chat_id}!',
            )
コード例 #3
0
ファイル: lydia.py プロジェクト: zeuslord224/Nana-Remix
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 message.reply('AI successfully enabled for this chat!')
    else:
        await message.reply('AI is already enabled for this chat!')
コード例 #4
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)
            reply_text = re.sub(r"[rl]", "w", rep)
            reply_text = re.sub(r"[rl]", "w", rep)
            reply_text = re.sub(r"[RL]", "W", reply_text)
            reply_text = re.sub(r"[RL]", "W", reply_text)
            reply_text = re.sub(r"n([aeiouaeiou])", r"ny\1", reply_text)
            reply_text = re.sub(r"r([aeiouaeiou])", r"w\1", reply_text)
            reply_text = re.sub(r"n([aeiou])", r"ny\1", reply_text)
            reply_text = re.sub(r"N([aeiouAEIOU])", r"Ny\1", reply_text)
            reply_text = re.sub(r"N([aeiouAEIOU])", r"Ny\1", reply_text)
            reply_text = re.sub(r"\!+",
                                " " + random.choice(meme_strings.faces),
                                reply_text)
            reply_text = re.sub(r"!+", " " + random.choice(meme_strings.faces),
                                reply_text)
            reply_text = reply_text.replace("ove", "uv")
            reply_text = reply_text.replace("ove", "uv")
            reply_text = reply_text.replace(".", ",,.")
            reply_text += " " + random.choice(meme_strings.faces)
            await asyncio.sleep(0.3)
            await message.reply_text(reply_text.lower(), quote=True)
        except CFError as e:
            await client.send_message(
                Owner, f"Chatbot error: {e} occurred in {chat_id}!")