forked from swee/MeowNex
Update sweebot.py
This commit is contained in:
parent
78445c2d1f
commit
159f884a21
1 changed files with 27 additions and 3 deletions
30
sweebot.py
30
sweebot.py
|
@ -15,6 +15,7 @@ from requests import get, exceptions as rex
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
from googleapiclient.discovery import build
|
from googleapiclient.discovery import build
|
||||||
from characterai import pycai
|
from characterai import pycai
|
||||||
|
import uuid
|
||||||
CAItoken = environ["CAItoken"]
|
CAItoken = environ["CAItoken"]
|
||||||
CAImodel = environ["CAIchara"]
|
CAImodel = environ["CAIchara"]
|
||||||
try:
|
try:
|
||||||
|
@ -28,8 +29,9 @@ block = 0
|
||||||
parsed = 0
|
parsed = 0
|
||||||
lastquery = "None yet."
|
lastquery = "None yet."
|
||||||
# Dashboard thread
|
# 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__)
|
app = Flask(__name__)
|
||||||
|
responses_ai = {} # {uuid: response}
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
def index_html():
|
def index_html():
|
||||||
|
@ -52,6 +54,13 @@ def lastquery_txt():
|
||||||
@app.route('/docs/config')
|
@app.route('/docs/config')
|
||||||
def config_docs():
|
def config_docs():
|
||||||
return redir("https://git.swee.codes/swee/MeowNex/src/branch/main/docs/config.md")
|
return redir("https://git.swee.codes/swee/MeowNex/src/branch/main/docs/config.md")
|
||||||
|
@app.route('/response/<uuid>')
|
||||||
|
def ai_response_truncate(uuidd):
|
||||||
|
if uuidd in responses_ai:
|
||||||
|
res = responses_ai[uuidd]
|
||||||
|
return f'<title>AI response {uuidd}</title>\n<meta name="viewport" content="width=device-width, initial-scale=1.0">\n<link rel="stylesheet" href="https://swee.codes/style.css" type="text/css">\n<body><center><h1>AI response {uuidd}</h1><br><br>' + f"<textarea class=code width=100% spellcheck=\"false\" autocapitalize=\"off\" autocomplete=\"off\" autocorrect=\"off\" readonly=\"true\">{res}</textarea>"
|
||||||
|
else:
|
||||||
|
abrt(404)
|
||||||
threading.Thread(target=app.run, daemon=True, kwargs={"port": 2005}).start()
|
threading.Thread(target=app.run, daemon=True, kwargs={"port": 2005}).start()
|
||||||
|
|
||||||
# YouTube API
|
# YouTube API
|
||||||
|
@ -543,8 +552,23 @@ while True:
|
||||||
)
|
)
|
||||||
aimsg = aiconnector.send_message(CAImodel, new.chat_id, chatquery)
|
aimsg = aiconnector.send_message(CAImodel, new.chat_id, chatquery)
|
||||||
ai_storage[channel] = new.chat_id
|
ai_storage[channel] = new.chat_id
|
||||||
multiline(aimsg.text, channel)
|
randomname = str(uuid.uuid4())
|
||||||
lastquery = f"<p>Channel: {channel}</p><p>Request:</p><br><br>{chatquery}<hr><p>Response</p><br><br>{aimsg.text}"
|
responses_ai[randomname] = aimsg.text
|
||||||
|
mtline = ""
|
||||||
|
lastquery = f"<p>Channel: {channel}</p><p>Request:</p><br><br><textarea class=code width=100% spellcheck=\"false\" autocapitalize=\"off\" autocomplete=\"off\" autocorrect=\"off\" readonly=\"true\">{chatquery}</textarea><hr><p>Response</p><br><br><textarea class=code width=100% spellcheck=\"false\" autocapitalize=\"off\" autocomplete=\"off\" autocorrect=\"off\" readonly=\"true\">{aimsg.text}</textarea>"
|
||||||
|
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:
|
except:
|
||||||
multiline("Something went wrong while connecting to Character.AI.", channel)
|
multiline("Something went wrong while connecting to Character.AI.", channel)
|
||||||
print(traceback.format_exc())
|
print(traceback.format_exc())
|
||||||
|
|
Loading…
Reference in a new issue