Update sweebot.py
Some checks failed
Check syntax / check (push) Failing after 9s

This commit is contained in:
Nova Cat 2024-12-28 20:31:57 -08:00
parent be7202d5a5
commit e079fb10cd

View file

@ -14,10 +14,19 @@ from urllib.parse import urlparse, parse_qs
from requests import get, exceptions as rex
from bs4 import BeautifulSoup
from googleapiclient.discovery import build
from characterai import pycai
CAItoken = os.environ["CAItoken"]
CAImodel = os.environ["CAIchara"]
try:
cai = pycai.Client(CAItoken)
me = cai.get_me()
chats = []
except:
print(traceback.format_exc())
run = 0
block = 0
parsed = 0
lastquery = "None yet."
# Dashboard thread
from flask import Flask, send_file, redirect as redir
app = Flask(__name__)
@ -37,6 +46,9 @@ def parses():
@app.route('/script.js')
def script_js():
return send_file("script.js", mimetype='application/javascript')
@app.route('/lastquery.txt')
def lastquery_txt():
return str(lastquery)
@app.route('/docs/config')
def config_docs():
return redir("https://git.swee.codes/swee/MeowNex/src/branch/main/docs/config.md")
@ -254,6 +266,7 @@ logs = {} # {channel: [line, line]} max 10 lines
happiness = 5
global times
times = 0
ai_storage = {}
emoticons = {";3": "I think you forgot to press shift", ":#": "Wait no, don't hold shift THAT long!"}
def irci2():
irc2.connect_irc(
@ -518,7 +531,29 @@ while True:
block+=1
run-=1
elif command[0] == "$ai-chat":
try:
aiconnector = cai.connect()
chatquery = f"--Listen Up--\nYour happiness level is {happiness} (Maximum 10), your emotion level will impact the conversation's tone.\n--END Listen Up--\n--IRC recieve--\n<{nick}> " + " ".join(command[1:]
lastquery = chatquery
if channel in ai_storage:
aimsg = aiconnector.send_message(CAImodel, ai_storage[channel], chatquery)
else:
new, answer = await chat.new_chat(
CAImodel, me.id
)
aimsg = aiconnector.send_message(CAImodel, new.chat_id, chatquery)
ai_storage[channel] = new.chat_id
mulitline(aimsg, channel)
except:
multiline("Something went wrong while connecting to Character.AI.", channel)
elif command[0] == "$ai-clear":
if channel in ai_storage:
del ai_storage[channel]
multiline("Done.", channel)
else:
multiline(f"There is no existing AI conversation in {channel}", channel)
elif command[0] == "$socket":
if perms == "full":
if len(command) > 1: