forked from swee/MeowNex
Update sweebot.py
This commit is contained in:
parent
be7202d5a5
commit
e079fb10cd
1 changed files with 38 additions and 3 deletions
41
sweebot.py
41
sweebot.py
|
@ -14,10 +14,19 @@ from urllib.parse import urlparse, parse_qs
|
||||||
from requests import get, exceptions as rex
|
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
|
||||||
|
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
|
run = 0
|
||||||
block = 0
|
block = 0
|
||||||
parsed = 0
|
parsed = 0
|
||||||
|
lastquery = "None yet."
|
||||||
# Dashboard thread
|
# Dashboard thread
|
||||||
from flask import Flask, send_file, redirect as redir
|
from flask import Flask, send_file, redirect as redir
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
@ -37,6 +46,9 @@ def parses():
|
||||||
@app.route('/script.js')
|
@app.route('/script.js')
|
||||||
def script_js():
|
def script_js():
|
||||||
return send_file("script.js", mimetype='application/javascript')
|
return send_file("script.js", mimetype='application/javascript')
|
||||||
|
@app.route('/lastquery.txt')
|
||||||
|
def lastquery_txt():
|
||||||
|
return str(lastquery)
|
||||||
@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")
|
||||||
|
@ -254,6 +266,7 @@ logs = {} # {channel: [line, line]} max 10 lines
|
||||||
happiness = 5
|
happiness = 5
|
||||||
global times
|
global times
|
||||||
times = 0
|
times = 0
|
||||||
|
ai_storage = {}
|
||||||
emoticons = {";3": "I think you forgot to press shift", ":#": "Wait no, don't hold shift THAT long!"}
|
emoticons = {";3": "I think you forgot to press shift", ":#": "Wait no, don't hold shift THAT long!"}
|
||||||
def irci2():
|
def irci2():
|
||||||
irc2.connect_irc(
|
irc2.connect_irc(
|
||||||
|
@ -517,8 +530,30 @@ while True:
|
||||||
irc.send_irc(channel, nick + ": Permission denied.")
|
irc.send_irc(channel, nick + ": Permission denied.")
|
||||||
block+=1
|
block+=1
|
||||||
run-=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":
|
elif command[0] == "$socket":
|
||||||
if perms == "full":
|
if perms == "full":
|
||||||
if len(command) > 1:
|
if len(command) > 1:
|
||||||
|
|
Loading…
Reference in a new issue