forked from swee/MeowNex
Compare commits
85 commits
Author | SHA1 | Date | |
---|---|---|---|
c42fb303e1 | |||
0e7fba7f31 | |||
e3faae3ef7 | |||
19d9bebdac | |||
2c191b0262 | |||
30ba0acdd4 | |||
fb979adce6 | |||
e79a9b3aac | |||
159f884a21 | |||
78445c2d1f | |||
334fbea381 | |||
793a5ed08d | |||
8958941758 | |||
2a1e568111 | |||
edeadaca80 | |||
3d3ffd2367 | |||
5d87ef5c40 | |||
4ce0170f00 | |||
22f4824abb | |||
b80482f9ed | |||
fd433122dc | |||
e079fb10cd | |||
be7202d5a5 | |||
e1a7461369 | |||
c605ac2f4c | |||
fdcd44ef16 | |||
2a8f19f981 | |||
7578acff90 | |||
eb8e8e4aed | |||
e31069ccb7 | |||
b8c0350c1d | |||
6607cb4014 | |||
76c48571df | |||
37f93a5d94 | |||
62b6c04fc3 | |||
d9fcb5427c | |||
39bb76f3a5 | |||
3b63e14c2c | |||
5c8c219280 | |||
a1ee0b6cdf | |||
cdfd6b9d7b | |||
00e29ab908 | |||
d8ee864bae | |||
847994826d | |||
d0b488b863 | |||
c6258e1094 | |||
8b70a73199 | |||
16ebb8fed4 | |||
0e0567446e | |||
c40890918f | |||
34ba0c15f5 | |||
d43bf24270 | |||
5e0235919a | |||
d784694262 | |||
124dd1dcba | |||
8382731ef0 | |||
36c136dcc3 | |||
2f36c10042 | |||
4021636f70 | |||
6227e6f097 | |||
94120b0a69 | |||
4ac94fb1bf | |||
eb28603287 | |||
c357314230 | |||
5f353aa6e9 | |||
b8aadb83ad | |||
3ee06823b9 | |||
34f8e736a1 | |||
1d93c75057 | |||
33d0043f13 | |||
9becc678d3 | |||
cac9148ebb | |||
ab9ef3dda8 | |||
c985451d2a | |||
b74e79bef1 | |||
ead0d55ac6 | |||
fc1024958a | |||
635f99985f | |||
00b364287c | |||
8676242d11 | |||
a262545322 | |||
8b54fa9c7b | |||
e3cfd9087e | |||
773fcd1b5e | |||
1e5d2fc29b |
11 changed files with 305 additions and 95 deletions
10
.forgejo/workflows/build.yml
Normal file
10
.forgejo/workflows/build.yml
Normal file
|
@ -0,0 +1,10 @@
|
|||
name: Check syntax
|
||||
on: [push,workflow_dispatch]
|
||||
jobs:
|
||||
check:
|
||||
runs-on: debian-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-python@v5
|
||||
- run: python -m py_compile sweebot.py
|
||||
- run: jshint script.js
|
19
cc/give
19
cc/give
|
@ -1,21 +1,28 @@
|
|||
from sys import argv
|
||||
import sqlite3
|
||||
import re
|
||||
conn = sqlite3.connect("/home/sweebotirc/sbirc.db")
|
||||
database = conn.cursor()
|
||||
def getperms(cloak: str):
|
||||
def getperms(mask: str):
|
||||
try:
|
||||
database.execute("SELECT * FROM users WHERE username = '"+ cloak + "';")
|
||||
database.execute(f"SELECT * FROM users;")
|
||||
output = database.fetchall()
|
||||
return output[0][1]
|
||||
except:
|
||||
for i in output:
|
||||
if re.match(i[0].replace("*", ".+"), mask):
|
||||
return i[1]
|
||||
return ''
|
||||
if getperms(argv[2]) == "full":
|
||||
except:
|
||||
print(traceback.format_exc())
|
||||
return ''
|
||||
if argv[2] == "full":
|
||||
if len(argv) == 5:
|
||||
if argv[3] == argv[2]:
|
||||
print(argv[1] + ": You wanna give yourself permissions!?")
|
||||
else:
|
||||
perms = getperms(argv[3])
|
||||
if perms != "":
|
||||
if argv[4] in perms:
|
||||
print("The specified user already has these permissions.")
|
||||
elif perms != "":
|
||||
database.execute("UPDATE users SET perms = '" + perms + "," + argv[4] + "' WHERE username = '" + argv[3] + "';")
|
||||
print(argv[1] + ": Successfully appended '" + argv[4] + "' to the permissions of " + argv[3])
|
||||
else:
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/python3
|
||||
from random import choice
|
||||
opinions = ["Oreos are better than Chips Ahoy!", "Human baka, be furry!", "Cereal goes before milk!", "Cereal goes before milk, but what if I pour cereal before bowl? Answer: Chaos!", "Protogens don't run on swap, 1TB of physical RAM!", "Generative AI sucks."]
|
||||
opinions = ["Oreos are better than Chips Ahoy!", "Human baka, be furry!", "Cereal goes before milk!", "Cereal goes before milk, but what if I pour cereal before bowl? Answer: Chaos!", "Protogens don't run on swap, 1TB of physical RAM!", "Generative AI sucks.", "Y'know, we've all fought about cereal going before milk, but nobody discussed about if choccy powder goes before milk!! ;-;"]
|
||||
print(choice(opinions))
|
|
@ -1,4 +1,7 @@
|
|||
#!/usr/bin/python3
|
||||
import sweecrypt
|
||||
from sys import argv
|
||||
print(sweecrypt.decrypt(" ".join(argv[3:])))
|
||||
if argv[3][:2] == "-s":
|
||||
print(sweecrypt.decrypt(" ".join(argv[4:]), int(argv[3][2:])))
|
||||
else:
|
||||
print(sweecrypt.decrypt(" ".join(argv[3:])))
|
|
@ -1,4 +1,7 @@
|
|||
#!/usr/bin/python3
|
||||
import sweecrypt
|
||||
from sys import argv
|
||||
print(sweecrypt.encrypt(" ".join(argv[3:])))
|
||||
if argv[3][:2] == "-s":
|
||||
print(sweecrypt.encrypt(" ".join(argv[4:]), int(argv[3][2:])))
|
||||
else:
|
||||
print(sweecrypt.encrypt(" ".join(argv[3:])))
|
|
@ -11,6 +11,11 @@
|
|||
<br>
|
||||
<br>
|
||||
<a class="download" style="background: #027ef9;" title="Refresh stats" onclick="refresh();"><img src="https://swee.codes/icons/refresh.svg"></a>
|
||||
<hr>
|
||||
<h1>Last AI Request:</h1>
|
||||
<br>
|
||||
<br>
|
||||
<div width="100%" id="aichat">...</div>
|
||||
</center>
|
||||
<script src="script.js"></script>
|
||||
</body>
|
||||
|
|
22
docs/config.md
Normal file
22
docs/config.md
Normal file
|
@ -0,0 +1,22 @@
|
|||
Configure the bot for the channel. Requires the "full" perms. (will be allowed by chanops soon)
|
||||
|
||||
|
||||
Use +FLAG to enable a disabled-by-default, and -FLAG vice versa.
|
||||
|
||||
|
||||
Available flags:
|
||||
* multiline - be able to print multiline output (enabled default)
|
||||
* colonthree - make the bot say ":3" when someone's message starts with ":3" (enabled default)
|
||||
* :3c - oh weawwy? :3c (DISABLED default, overriden by colonthree)
|
||||
* links - parse titles of links sent by users (DISABLED default)
|
||||
* sed - parse sed expressions without the need of $sed command (DISABLED default)
|
||||
* config - placeholder, do not modify.
|
||||
|
||||
---
|
||||
|
||||
Syntax:
|
||||
```
|
||||
$config [FLAG] [FLAG] - Apply one or more flags
|
||||
$config clear - Clear all flags
|
||||
$config - list all flags in the channel
|
||||
```
|
12
helps/config
12
helps/config
|
@ -1,11 +1 @@
|
|||
Configure the bot for the channel. Requires the "full" perms. (will be allowed by chanops soon)
|
||||
Use +FLAG to enable a disabled-by-default, and -FLAG vice versa.
|
||||
Available flags:
|
||||
multiline - be able to print multiline output (enabled default)
|
||||
colonthree - make the bot say ":3" when someone's message starts with ":3" (enabled default)
|
||||
links - parse titles of links sent by users (DISABLED default)
|
||||
(the config flag is a placeholder, do not change it)
|
||||
syntax:
|
||||
> $config [FLAG] [FLAG] - Apply one or more flags
|
||||
> $config clear - Clear all flags
|
||||
> $config - list all flags in the channel
|
||||
Documentation for $config can now be found in https://irc-bot.swee.codes/docs/config
|
|
@ -1 +1 @@
|
|||
Pulls the latest version of sweeBot from its Git repository. requires the "git" permissions.
|
||||
Pulls the latest version of MeowNexUS IRC from its Git repository. requires the "git" permissions.
|
16
script.js
16
script.js
|
@ -1,3 +1,4 @@
|
|||
/*jshint esversion: 8 */
|
||||
// Fetching the run value for the first time
|
||||
fetch ("run.txt")
|
||||
.then(x => x.text())
|
||||
|
@ -9,19 +10,26 @@ fetch ("block.txt")
|
|||
fetch ("link.txt")
|
||||
.then(x => x.text())
|
||||
.then(y => document.getElementById("links").innerHTML = y);
|
||||
fetch ("lastquery.txt")
|
||||
.then(x => x.text())
|
||||
.then(y => document.getElementById("aichat").innerHTML = y);
|
||||
async function refresh(){
|
||||
// Refresh the HTML to show the spinners
|
||||
document.getElementById("run").innerHTML = "..."
|
||||
document.getElementById("blocked").innerHTML = "..."
|
||||
document.getElementById("links").innerHTML = "..."
|
||||
document.getElementById("run").innerHTML = "...";
|
||||
document.getElementById("blocked").innerHTML = "...";
|
||||
document.getElementById("links").innerHTML = "...";
|
||||
document.getElementById("aichat").innerHTML = "...";
|
||||
// Then fetch the values the same way as on the first part of the script.
|
||||
fetch ("run.txt")
|
||||
.then(x => x.text())
|
||||
.then(y => document.getElementById("run").innerHTML = y)
|
||||
.then(y => document.getElementById("run").innerHTML = y);
|
||||
fetch ("block.txt")
|
||||
.then(x => x.text())
|
||||
.then(y => document.getElementById("blocked").innerHTML = y);
|
||||
fetch ("link.txt")
|
||||
.then(x => x.text())
|
||||
.then(y => document.getElementById("links").innerHTML = y);
|
||||
fetch ("lastquery.txt")
|
||||
.then(x => x.text())
|
||||
.then(y => document.getElementById("aichat").innerHTML = y);
|
||||
}
|
298
sweebot.py
298
sweebot.py
|
@ -1,4 +1,4 @@
|
|||
__version__ = "0.0.2 Funni update" + ". https://git.swee.codes/MeowNex"
|
||||
__version__ = "0.0.2 Funni update" + ". https://git.swee.codes/swee/MeowNex"
|
||||
import socket
|
||||
import subprocess
|
||||
from time import sleep, time, ctime
|
||||
|
@ -10,16 +10,28 @@ from random import choice, randint as random, randrange
|
|||
import traceback
|
||||
import threading
|
||||
from pathlib import Path
|
||||
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
|
||||
import uuid
|
||||
CAItoken = environ["CAItoken"]
|
||||
CAImodel = 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
|
||||
from flask import Flask, send_file, abort as abrt, redirect as redir
|
||||
app = Flask(__name__)
|
||||
responses_ai = {} # {uuid: response}
|
||||
|
||||
@app.route('/')
|
||||
def index_html():
|
||||
|
@ -36,22 +48,52 @@ 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")
|
||||
@app.route('/response/<uuidd>')
|
||||
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><div class=code width="100%" style="word-wrap: break-word;white-space: pre;text-align: left;">' + res
|
||||
else:
|
||||
abrt(404)
|
||||
threading.Thread(target=app.run, daemon=True, kwargs={"port": 2005}).start()
|
||||
|
||||
|
||||
# YouTube API
|
||||
DEVELOPER_KEY = environ["ytapi"]
|
||||
headers = {
|
||||
'User-Agent': 'SweeBot IRC ' + __version__
|
||||
'User-Agent': 'MeowNexUS IRC ' + __version__
|
||||
}
|
||||
def get_yt_id(url):
|
||||
query = urlparse(url)
|
||||
# youtu.be already contains the ID in the path
|
||||
if query.hostname == 'youtu.be': return query.path[1:]
|
||||
if query.hostname in {'www.youtube.com', 'youtube.com', 'music.youtube.com'}:
|
||||
# URLs that have the ID in the path instead of the query.
|
||||
integrated_in_url = ["watch", "embed", "v", "shorts"]
|
||||
try:
|
||||
# The regular /watch path, which stores the ID in the query.
|
||||
if query.path == '/watch': return parse_qs(query.query)['v'][0]
|
||||
# Alternatively, it will get the ID in the path if the path was in the list above.
|
||||
elif query.path.split('/')[1] in integrated_in_url: return query.path.split('/')[2]
|
||||
except:
|
||||
return None
|
||||
class config:
|
||||
def __init__(self):
|
||||
self.conn = sqlite3.connect(environ["SBconfig"])
|
||||
self.database = self.conn.cursor()
|
||||
def perms(self, cloak: str):
|
||||
def perms(self, mask: str):
|
||||
try:
|
||||
self.database.execute(f"SELECT * FROM users WHERE username = ?;", [cloak])
|
||||
self.database.execute(f"SELECT * FROM users;")
|
||||
output = self.database.fetchall()
|
||||
return output[0][1]
|
||||
for i in output:
|
||||
if re.match(i[0].replace("*", ".+"), mask):
|
||||
return i[1]
|
||||
return ''
|
||||
except:
|
||||
print(traceback.format_exc())
|
||||
return ''
|
||||
|
@ -121,6 +163,11 @@ def humanbytes(B):
|
|||
return '{0:.2f}GB'.format(B / GB)
|
||||
elif TB <= B:
|
||||
return '{0:.2f}TB'.format(B / TB)
|
||||
def rplce(text, old, new, n):
|
||||
parts = text.split(old)
|
||||
if len(parts) <= n:
|
||||
return text # Not enough occurrences to replace
|
||||
return old.join(parts[:n]) + new + old.join(parts[n:])
|
||||
def replace_color_codes(text):
|
||||
def replacer(match):
|
||||
code = match.group(0)
|
||||
|
@ -171,7 +218,7 @@ class bot_irc:
|
|||
|
||||
self.irc_socket.send(
|
||||
bytes(
|
||||
"USER " + bot_nick + " " + bot_nick + " " + bot_nick + " :SweeBot, a very cool bot made by Swee :3\n",
|
||||
"USER " + bot_nick + " " + bot_nick + " " + bot_nick + " :MeowNexUS, a very cool bot made by Swee :3\n",
|
||||
"UTF-8",
|
||||
)
|
||||
)
|
||||
|
@ -224,9 +271,12 @@ pats = ["-w-", "Meep...", "Prr!"]
|
|||
meows_happy = ['Meow!', 'Nyaa~', 'Mrow.', 'Prr! :3', "Mrrp?", "Mreow.", "!woeM", "3: !rrP", "~aayN", "Mew!", "Moew!"]
|
||||
meows_upset = ['Hiss!', "!ssiH", "Grrr..."]
|
||||
my_self = ["MeowNexUS", "MeowNexU5", "MeowN3xUS"]
|
||||
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(
|
||||
server_irc, port_irc, channel_irc, "sweeB0t", botpass_irc, botnickpass_irc + "/B"
|
||||
|
@ -304,8 +354,9 @@ while True:
|
|||
channel = text.split("PRIVMSG")[1].split(" ")[1]
|
||||
nick = text.split(" ")[0][1:].split("!")[0]
|
||||
username = text.split(" ")[0][1:].split("@")[1]
|
||||
mask = text.split(" ")[0][1:]
|
||||
try:
|
||||
perms = sbconfig.perms(username)
|
||||
perms = sbconfig.perms(mask)
|
||||
except:
|
||||
perms = ""
|
||||
print(command)
|
||||
|
@ -313,15 +364,65 @@ while True:
|
|||
print(nick)
|
||||
print(username)
|
||||
print(perms)
|
||||
cont = " ".join(command)
|
||||
if not channel in logs:
|
||||
logs[channel] = [{"nick": nick, "content": cont}]
|
||||
else:
|
||||
logs[channel].append({"nick": nick, "content": cont})
|
||||
if len(logs[channel]) > 128: logs[channel] = logs[channel][::-1][:128][::-1]
|
||||
#open("log-text-"+channel, "a").write(" ".join(command) + "\n")
|
||||
#open("log-name-"+channel, "a").write(nick + "\n")
|
||||
except:
|
||||
#print(traceback.format_exc())
|
||||
pass
|
||||
print(traceback.format_exc())
|
||||
def replased(expression):
|
||||
if channel in logs:
|
||||
try:
|
||||
if expression.split("/")[0].lower() != "s": raise IndexError()
|
||||
find = expression.split("/")[1]
|
||||
replace = expression.split("/")[2]
|
||||
user = None
|
||||
repeat = False
|
||||
index = 1
|
||||
try:
|
||||
extraflags = expression.split("/")[3:]
|
||||
for i in extraflags:
|
||||
if i.strip() == "":
|
||||
pass
|
||||
elif i.lower() == "g":
|
||||
repeat = True
|
||||
elif i.strip().isdigit():
|
||||
print(f"index = {int(i)}")
|
||||
index = int(i)
|
||||
else:
|
||||
print(f"user = {i.lower()}")
|
||||
user = i.lower()
|
||||
except: pass
|
||||
cache = None
|
||||
for i in logs[channel][::-1]:
|
||||
if find in i["content"] and (user == None or i["nick"].lower() == user):
|
||||
cache = i
|
||||
break
|
||||
if cache == None:
|
||||
raise Exception("The specified text couldn't be found")
|
||||
else:
|
||||
if repeat:
|
||||
cache["content"] = cache["content"].replace(find, replace)
|
||||
else:
|
||||
cache["content"] = rplce(cache["content"], find, replace, index)
|
||||
cachenick = cache["nick"]
|
||||
cachecontent = cache["content"]
|
||||
multiline(f"[RPL] <{cachenick}> {cachecontent}", channel)
|
||||
except IndexError:
|
||||
irc.send_irc(channel, nick + ": [ERR] Sed expression might be incorrectly written!")
|
||||
except Exception as ex:
|
||||
irc.send_irc(channel, nick + ": [ERR] " + str(ex))
|
||||
else:
|
||||
irc.send_irc(channel, nick + ": [!!!] No logs saved in " + channel)
|
||||
try:
|
||||
#if True:
|
||||
if "PRIVMSG" in text and not nick in my_self:
|
||||
if "PRIVMSG" in text and command[0][0] == "$":
|
||||
logs[channel] = logs[channel][:-1]
|
||||
run+=1
|
||||
if command[0] == "$ping":
|
||||
if random(1,2) == 1:
|
||||
|
@ -353,9 +454,9 @@ while True:
|
|||
|
||||
elif command[0] == "$whoami":
|
||||
if perms != "":
|
||||
irc.send_irc(channel, nick + ": " + username + " (Your cloak has permissions, use the 'perms' command to see)")
|
||||
irc.send_irc(channel, nick + ": " + mask + " (Your hostmask has permissions, use the 'perms' command to see)")
|
||||
else:
|
||||
irc.send_irc(channel, nick + ": " + username)
|
||||
irc.send_irc(channel, nick + ": " + mask)
|
||||
|
||||
elif command[0] == "$welcome":
|
||||
name = nick if not len(command) > 1 else " ".join(command[1:])
|
||||
|
@ -367,9 +468,9 @@ while True:
|
|||
elif command[0] == "$perms":
|
||||
if len(command) == 2:
|
||||
if sbconfig.perms(command[1]) != "":
|
||||
irc.send_irc(channel, nick + ": permissions of cloak " + command[1] + ": " + sbconfig.perms(command[1]))
|
||||
irc.send_irc(channel, nick + ": permissions of hostmask " + command[1] + ": " + sbconfig.perms(command[1]))
|
||||
else:
|
||||
irc.send_irc(channel, nick + ": The cloak " + command[1] + " Doesn't have permissions.")
|
||||
irc.send_irc(channel, nick + ": The hostmask wildcard " + command[1] + " Doesn't have permissions.")
|
||||
else:
|
||||
if perms != "":
|
||||
irc.send_irc(channel, nick + ": " + perms)
|
||||
|
@ -392,8 +493,7 @@ while True:
|
|||
ossystem("git fetch")
|
||||
ossystem("git pull")
|
||||
irc.send_irc(channel, nick + ": Pulled from Git, restarting bot...")
|
||||
sleep(1)
|
||||
ossystem("sudo systemctl restart sweebot")
|
||||
restart()
|
||||
else:
|
||||
irc.send_irc(channel, nick + ": Permission denied.")
|
||||
block+=1
|
||||
|
@ -440,7 +540,45 @@ 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:])
|
||||
if channel in ai_storage:
|
||||
aimsg = aiconnector.send_message(CAImodel, ai_storage[channel], chatquery)
|
||||
else:
|
||||
new, answer = aiconnector.new_chat(
|
||||
CAImodel, me.id
|
||||
)
|
||||
aimsg = aiconnector.send_message(CAImodel, new.chat_id, chatquery)
|
||||
ai_storage[channel] = new.chat_id
|
||||
randomname = str(uuid.uuid4())
|
||||
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) > 256:
|
||||
mtline += "\n" + i[:256] + "..."
|
||||
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())
|
||||
|
||||
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:
|
||||
|
@ -458,14 +596,24 @@ while True:
|
|||
|
||||
elif command[0] == "$patpat" or command[0] == "$headpat":
|
||||
if len(command) == 2:
|
||||
for i in range(0,int(command[1])):
|
||||
happiness += (1 if happiness != 10 else 0)
|
||||
if int(command[1]) < 50:
|
||||
for i in range(0,int(command[1])):
|
||||
happiness += (1 if happiness != 10 else 0)
|
||||
else:
|
||||
happiness = 10
|
||||
elif len(command) == 1:
|
||||
happiness += (1 if happiness != 10 else 0)
|
||||
multiline(choice(pats) + " (Emotion: Upset " +
|
||||
("#" * int(happiness)) +
|
||||
("-" * int(10-happiness)) + " Happy)",
|
||||
channel)
|
||||
if len(command) != 2 or int(command[1]) < 50:
|
||||
multiline(choice(pats) + " (Emotion: Upset " +
|
||||
("#" * int(happiness)) +
|
||||
("-" * int(10-happiness)) + " Happy)",
|
||||
channel)
|
||||
else:
|
||||
multiline("Okay that's enough!!" + " (Emotion: Upset " +
|
||||
("#" * int(happiness)) +
|
||||
("-" * int(10-happiness)) + " Happy)",
|
||||
channel)
|
||||
|
||||
elif command[0] == "$emotion":
|
||||
multiline("Emotion: Upset " +
|
||||
("#" * int(happiness)) +
|
||||
|
@ -473,14 +621,23 @@ while True:
|
|||
channel)
|
||||
elif command[0] == "$bap":
|
||||
if len(command) == 2:
|
||||
for i in range(0,int(command[1])):
|
||||
happiness -= (1 if happiness != 0 else 0)
|
||||
if int(command[1]) < 50:
|
||||
for i in range(0,int(command[1])):
|
||||
happiness -= (1 if happiness != 0 else 0)
|
||||
else:
|
||||
happiness = 0
|
||||
elif len(command) == 1:
|
||||
happiness -= (1 if happiness != 0 else 0)
|
||||
multiline(choice(baps) + " (Emotion: Upset " +
|
||||
("#" * int(happiness)) +
|
||||
("-" * int(10-happiness)) + " Happy)",
|
||||
channel)
|
||||
if len(command) != 2 or int(command[1]) < 50:
|
||||
multiline(choice(baps) + " (Emotion: Upset " +
|
||||
("#" * int(happiness)) +
|
||||
("-" * int(10-happiness)) + " Happy)",
|
||||
channel)
|
||||
else:
|
||||
multiline("Okay that's enough!!" + " (Emotion: Upset " +
|
||||
("#" * int(happiness)) +
|
||||
("-" * int(10-happiness)) + " Happy)",
|
||||
channel)
|
||||
elif command[0] == "$meow":
|
||||
if random(1,100) > (happiness*10):
|
||||
multiline(choice(meows_upset), channel)
|
||||
|
@ -505,7 +662,7 @@ while True:
|
|||
|
||||
|
||||
elif command[0] == "$version":
|
||||
irc.send_irc(channel, "This is SweeBot " + __version__)
|
||||
irc.send_irc(channel, "This is MeowNexUS IRC " + __version__)
|
||||
|
||||
elif command[0] == "$figlet":
|
||||
if not sbconfig.cflagexist(channel, "-multiline"):
|
||||
|
@ -563,14 +720,10 @@ while True:
|
|||
|
||||
|
||||
elif command[0] == "$sed":
|
||||
if len(command) > 1:
|
||||
try:
|
||||
#if True:
|
||||
raise Exception("WorkInProgress!!!")
|
||||
except:
|
||||
print(traceback.format_exc())
|
||||
if len(command) == 2:
|
||||
replased(" ".join(command[1:]))
|
||||
else:
|
||||
irc.send_irc(channel, nick + ": What to correct?")
|
||||
irc.send_irc(channel, nick + ": [???] This command takes only one argument.")
|
||||
|
||||
|
||||
elif command[0] == "$config":
|
||||
|
@ -626,7 +779,7 @@ while True:
|
|||
comm = command
|
||||
com.append("cc/" + comm[0][1:])
|
||||
com.append(nick)
|
||||
com.append(username)
|
||||
com.append(perms)
|
||||
comm.pop(0)
|
||||
for i in comm:
|
||||
com.append(i)
|
||||
|
@ -642,46 +795,55 @@ while True:
|
|||
elif command[0] == ":3":
|
||||
if not sbconfig.cflagexist(channel, "-colonthree"):
|
||||
irc.send_irc(channel, ":3")
|
||||
elif ":3c" in command:
|
||||
elif command[0] in emoticons:
|
||||
if not sbconfig.cflagexist(channel, "-colonthree"):
|
||||
multiline(channel, choice(threes))
|
||||
irc.send_irc(channel, emoticons[command[0]])
|
||||
elif ":3c" in command:
|
||||
if sbconfig.cflagexist(channel, "+:3c") or not sbconfig.cflagexist(channel, "-colonthree"):
|
||||
multiline(choice(threes), channel)
|
||||
elif command[0][:2].lower() == "s/":
|
||||
logs[channel] = logs[channel][:-1]
|
||||
if sbconfig.cflagexist(channel, "+sed"):
|
||||
replased(" ".join(command))
|
||||
# try to parse and find a link
|
||||
|
||||
if sbconfig.cflagexist(channel, "+links"):
|
||||
try:
|
||||
for i in command:
|
||||
if i[:8] == "https://":
|
||||
parse = urlparse(i)
|
||||
if parse.scheme in ["http", "https"]:
|
||||
try:
|
||||
e = get(i, headers=headers, timeout=10)
|
||||
header = e.headers
|
||||
content_type = header.get('content-type').split(";")[0]
|
||||
content_len = header.get('Content-length')
|
||||
if content_type in allowedparse:
|
||||
if e.ok:
|
||||
soup = BeautifulSoup(e.text, 'html.parser')
|
||||
multiline("(" + nick + ") " + (" ".join(soup.title.string.splitlines())[:100] if soup.title != None else "[No title provided]"), channel)
|
||||
else:
|
||||
multiline("(" + nick + ") [HTTP " + str(e.status_code) + "]", channel)
|
||||
if parse.hostname in ["youtube.com", "youtu.be", "www.youtube.com", "m.youtube.com", "youtube-nocookie.com"] and get_yt_id(i) != None:
|
||||
try:
|
||||
video_id = get_yt_id(i)
|
||||
youtube = build('youtube', 'v3', developerKey=DEVELOPER_KEY)
|
||||
request = youtube.videos().list(part='snippet,statistics', id=video_id)
|
||||
details = request.execute()
|
||||
title = details['items'][0]['snippet']['title']
|
||||
channel_yt = details['items'][0]['snippet']['channelTitle']
|
||||
views = details['items'][0]['statistics']['viewCount']
|
||||
multiline(f"({nick}) [▶️ YouTube] {title} | Author: {channel_yt} | {views} Views", channel)
|
||||
except Exception as ex:
|
||||
multiline("(" + nick + ") [YouTube Error, is it a valid YouTube URL?]", channel)
|
||||
print(traceback.format_exc())
|
||||
else:
|
||||
multiline("(" + nick + ") [" + humanbytes(content_len) + " " + str(content_type) + "]", channel)
|
||||
parsed += 1
|
||||
e = get(i, headers=headers, timeout=10)
|
||||
header = e.headers
|
||||
content_type = header.get('content-type').split(";")[0]
|
||||
content_len = header.get('Content-length')
|
||||
if content_type in allowedparse:
|
||||
if e.ok:
|
||||
soup = BeautifulSoup(e.text, 'html.parser')
|
||||
multiline("(" + nick + ") " + (" ".join(soup.title.string.splitlines())[:100] if soup.title != None else "[No title provided]"), channel)
|
||||
else:
|
||||
multiline("(" + nick + ") [HTTP " + str(e.status_code) + "]", channel)
|
||||
else:
|
||||
multiline("(" + nick + ") [" + humanbytes(content_len) + " " + str(content_type) + "]", channel)
|
||||
parsed += 1
|
||||
except rex.SSLError as ex:
|
||||
multiline("(" + nick + ") [SSL Error: " + str(ex.message) + "]", channel)
|
||||
except Exception as ex:
|
||||
multiline("(" + nick + ") [Request error: " + str(ex.message) + "]", channel)
|
||||
elif i[:7] == "http://":
|
||||
e = get(i, headers=headers, timeout=10)
|
||||
header = e.headers
|
||||
content_type = header.get('content-type').split(";")[0]
|
||||
content_len = header.get('Content-length')
|
||||
if content_type in allowedparse:
|
||||
if e.ok:
|
||||
soup = BeautifulSoup(e.text, 'html.parser')
|
||||
multiline("(" + nick + ") " + (" ".join(soup.title.string.splitlines())[:100] if soup.title != None else "[No title provided]"), channel)
|
||||
else:
|
||||
multiline("(" + nick + ") [HTTP " + str(e.status_code) + "]", channel)
|
||||
else:
|
||||
multiline("(" + nick + ") [" + humanbytes(content_len) + " " + str(content_type) + "]", channel)
|
||||
parsed += 1
|
||||
except:
|
||||
print(traceback.format_exc())
|
||||
elif "JOIN" in text and "#nixsanctuary" in text:
|
||||
|
|
Loading…
Reference in a new issue