From 159f884a21d79390fe2223c597c0ff5c58b655db Mon Sep 17 00:00:00 2001 From: swee Date: Mon, 30 Dec 2024 16:06:48 -0800 Subject: [PATCH] Update sweebot.py --- sweebot.py | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/sweebot.py b/sweebot.py index 32d7f8a..bc3d659 100644 --- a/sweebot.py +++ b/sweebot.py @@ -15,6 +15,7 @@ from requests import get, exceptions as rex from bs4 import BeautifulSoup from googleapiclient.discovery import build from characterai import pycai +import uuid CAItoken = environ["CAItoken"] CAImodel = environ["CAIchara"] try: @@ -28,8 +29,9 @@ block = 0 parsed = 0 lastquery = "None yet." # Dashboard thread -from flask import Flask, send_file, redirect as redir +from flask import Flask, send_file, abort as abrt, redirect as redir app = Flask(__name__) +responses_ai = {} # {uuid: response} @app.route('/') def index_html(): @@ -52,6 +54,13 @@ def lastquery_txt(): @app.route('/docs/config') def config_docs(): return redir("https://git.swee.codes/swee/MeowNex/src/branch/main/docs/config.md") +@app.route('/response/') +def ai_response_truncate(uuidd): + if uuidd in responses_ai: + res = responses_ai[uuidd] + return f'AI response {uuidd}\n\n\n

AI response {uuidd}



' + f"" + else: + abrt(404) threading.Thread(target=app.run, daemon=True, kwargs={"port": 2005}).start() # YouTube API @@ -543,8 +552,23 @@ while True: ) aimsg = aiconnector.send_message(CAImodel, new.chat_id, chatquery) ai_storage[channel] = new.chat_id - multiline(aimsg.text, channel) - lastquery = f"

Channel: {channel}

Request:



{chatquery}

Response



{aimsg.text}" + randomname = str(uuid.uuid4()) + responses_ai[randomname] = aimsg.text + mtline = "" + lastquery = f"

Channel: {channel}

Request:




Response



" + broke = False + for num, i in enumerate(aimsg.text.split("\n")): + if num == 5: + broke = True + break + elif len(i) > 75: + mtline += "\n" + i[:75] + "..." + broke = True + else: + mtline += "\n" + i + if broke: + mtline += f"\nView full response: https://irc-bot.swee.codes/response/{randomname}" + multiline(mtline, channel) except: multiline("Something went wrong while connecting to Character.AI.", channel) print(traceback.format_exc())