1
0
Fork 0
forked from swee/MeowNex

Merge pull request 'Prepare for contribution' (#1) from swee/MeowNex:main into main

Reviewed-on: #1
This commit is contained in:
10KB/s 2024-12-13 12:59:39 -08:00
commit 3af087af81
5 changed files with 86 additions and 144 deletions

16
dashboard.html Normal file
View file

@ -0,0 +1,16 @@
<title>MeowNexUS IRC - Dashboard</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://swee.codes/style.css" type="text/css">
<body>
<center>
<h1>MeowNexUS IRC</h1>
<noscript>Requires JS, sorry.<br></noscript>
<a class="softcard" style="display: inline-block;" title="Commands run" href="#"><span id="run">...</span><br><img src="https://swee.codes/icons/up.svg"></a>
<a class="softcard" style="display: inline-block;" title="Commands refused" href="#"><span id="blocked">...</span><br><img src="https://swee.codes/icons/down.svg"></a>
<a class="softcard" style="display: inline-block;" title="Links parsed" href="#"><span id="links">...</span><br><img width="25px" src="https://swee.codes/icons/links.svg"></a>
<br>
<br>
<a class="download" style="background: #027ef9;" title="Refresh stats" onclick="refresh();"><img src="https://swee.codes/icons/refresh.svg"></a>
</center>
<script src="script.js"></script>
</body>

View file

@ -1,32 +1,27 @@
var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'))
var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
return new bootstrap.Tooltip(tooltipTriggerEl)
})
const delay = ms => new Promise(res => setTimeout(res, ms));
// Fetching the run value for the first time
fetch ("run.txt")
.then(x => x.text())
.then(y => document.getElementById("run").innerHTML = y);
fetch ("block.txt")
.then(x => x.text())
.then(y => document.getElementById("blocked").innerHTML = y);
async function reboot(){
document.getElementById("rebooticon").innerHTML = "<i class=\"fas fa-power-off fa-fade\"></i>"
fetch ("reboot.run")
.then(x => x.text())
.then(y => document.getElementById("rebooticon").innerHTML = y);
await delay(2000)
document.getElementById("rebooticon").innerHTML = "<i class=\"fas fa-power-off\"></i>"
}
async function refresh(){
document.getElementById("refresh").innerHTML = "<i class=\"fas fa-sync fa-spin\"></i>"
document.getElementById("run").innerHTML = "<span class=\"spinner-grow\"></span>"
document.getElementById("blocked").innerHTML = "<span class=\"spinner-grow\"></span>"
fetch ("run.txt")
.then(x => x.text())
.then(y => document.getElementById("run").innerHTML = y)
.then(y => document.getElementById("run").innerHTML = y);
// Fetching the block value for the first time
fetch ("block.txt")
.then(x => x.text())
.then(y => document.getElementById("blocked").innerHTML = y);
await delay(2000)
document.getElementById("refresh").innerHTML = "<i class=\"fas fa-refresh\"></i>"
.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);
async function refresh(){
// Refresh the HTML to show the spinners
document.getElementById("run").innerHTML = "..."
document.getElementById("blocked").innerHTML = "..."
document.getElementById("links").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)
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);
}

View file

@ -1,30 +0,0 @@
from flask import Flask
from flask import send_file
from flask import request
from flask import redirect
import os
from pathlib import Path
from time import sleep as wait
app = Flask(__name__)
@app.route('/')
def index():
return send_file("sweebot.html", mimetype='text/html')
@app.route('/run.txt')
def run():
wait(2)
return send_file(str(Path.home()) + "/run.txt", mimetype='text/html')
@app.route('/block.txt')
def block():
wait(2)
return send_file(str(Path.home()) + "/block.txt", mimetype='text/html')
@app.route('/script.js')
def script():
return send_file("script.js", mimetype='application/javascript')
if __name__ == '__main__':
# run() method of Flask class runs the application
# on the local development server.
app.run(host='0.0.0.0',port=2001)

View file

@ -1,17 +0,0 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SweeBot dashboard</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://kit.fontawesome.com/30bde606c1.js" crossorigin="anonymous"></script>
<body class="container text-white bg-dark">
<center>
<h1>SweeBot Dashboard</h1>
<a class="btn btn-success" data-bs-toggle="tooltip" title="Commands run" href="#"><h3 id="run"><span class="spinner-grow"></span></h3><i class="fas fa-comments"></i></a>
<a class="btn btn-danger" data-bs-toggle="tooltip" title="Commands refused" href="#"><h3 id="blocked"><span class="spinner-grow"></span></h3><i class="fas fa-ban"></i></a>
<br>
<br>
<a class="btn btn-primary" data-bs-toggle="tooltip" title="Refresh stats" onclick="refresh();" id="refresh"><i class="fas fa-sync"></i></a>
</center>
<script src="script.js"></script>
</body>

View file

@ -1,4 +1,4 @@
__version__ = "0.0.2 Funni update"
__version__ = "0.0.2 Funni update" + ". https://git.swee.codes/MeowNex"
import socket
import subprocess
from time import sleep, time, ctime
@ -16,21 +16,25 @@ from googleapiclient.discovery import build
run = 0
block = 0
parsed = 0
# Dashboard thread
from flask import Flask, send_file
app = Flask(__name__)
@app.route('/')
def index():
return send_file("sweebot.html", mimetype='text/html')
def index_html():
return send_file("dashboard.html", mimetype='text/html')
@app.route('/run.txt')
def run():
def runs():
return str(run)
@app.route('/block.txt')
def block():
def blocks():
return str(block)
@app.route('/link.txt')
def parses():
return str(parsed)
@app.route('/script.js')
def script():
def script_js():
return send_file("script.js", mimetype='application/javascript')
threading.Thread(target=app.run, daemon=True, kwargs={"port": 2005}).start()
@ -200,7 +204,7 @@ class bot_irc:
server_irc = "127.0.0.1" # Use 127.0.0.1 for local ZNC
port_irc = 6667 # NO SSL FOR YOU
port_irc = 5000 # NO SSL FOR YOU
channel_irc = ["##sweezero"]
botnick_irc = environ.get('SBnick')
botnickpass_irc =environ.get('SBuser')
@ -219,14 +223,10 @@ baps = ["T-T", "Ow!", "Beep!"]
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"]
happiness = 5
global times
times = 0
def update():
open(str(Path.home()) + "/run.txt", 'w').write(str(run))
open(str(Path.home()) + "/block.txt", 'w').write(str(block))
update()
def irci2():
irc2.connect_irc(
server_irc, port_irc, channel_irc, "sweeB0t", botpass_irc, botnickpass_irc + "/B"
@ -268,18 +268,24 @@ def restart():
irc2.irc_socket.close()
irc3.irc_socket.close()
exit(0)
def system(cmd, chan):
def system(cmd, chan, rstrip=False):
try:
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
outpp = ""
for line in iter(p.stdout.readline, b''):
if text != "" and text != " ":
multiline(line.rstrip(), chan)
if not rstrip:
multiline(line.rstrip(), chan)
else:
outpp += line.decode().rstrip() + " "
if rstrip:
multiline(outpp[:-1], chan)
p.stdout.close()
p.wait()
except FileNotFoundError:
multiline(cmd[0] + " not found", chan)
except:
multiline(traceback.format_exc())
multiline(traceback.format_exc(), chan)
irl2 = threading.Thread(target=irci2, daemon=True)
irl2.start()
irl3 = threading.Thread(target=irci3, daemon=True)
@ -314,10 +320,9 @@ while True:
pass
try:
#if True:
if "PRIVMSG" in text:
if "PRIVMSG" in text and not nick in my_self:
if "PRIVMSG" in text and command[0][0] == "$":
run+=1
update()
if command[0] == "$ping":
if random(1,2) == 1:
irc.send_irc(channel, nick + ": Pnog")
@ -330,7 +335,7 @@ while True:
irc.send_irc(channel, nick + ": Nice try")
block+=1
run-=1
update()
else:
try:
if path.isfile(cwd + "/helps/" + " ".join(command[1:])):
@ -344,7 +349,7 @@ while True:
irc.send_irc(channel, "tip, ping, whoami, perms, version, figlet, tdfiglet, cowsay, uptime, cc, joke, botsnack. (restart, join, part, shell, config, pull.) Use '$help (command)' for explanation.")
elif command[0] == "$tip":
system(["fortune"], channel)
system(["/usr/games/fortune", "debian-hints"], channel, True)
elif command[0] == "$whoami":
if perms != "":
@ -380,7 +385,7 @@ while True:
irc.send_irc(channel, nick + ": Permission denied.")
block+=1
run-=1
update()
elif command[0] == "$pull":
if perms == "full" or "git" in perms.split(","):
@ -393,7 +398,7 @@ while True:
irc.send_irc(channel, nick + ": Permission denied.")
block+=1
run-=1
update()
elif command[0] == "$join":
if perms == "full" or "join" in perms.split(","):
@ -412,7 +417,7 @@ while True:
irc.send_irc(channel, nick + ": Permission denied.")
block+=1
run-=1
update()
elif command[0] == "$part":
if perms == "full" or "part" in perms.split(","):
@ -434,7 +439,7 @@ while True:
irc.send_irc(channel, nick + ": Permission denied.")
block+=1
run-=1
update()
elif command[0] == "$socket":
if perms == "full":
@ -449,7 +454,7 @@ while True:
irc.send_irc(channel, nick + ": Permission denied.")
block+=1
run-=1
update()
elif command[0] == "$patpat" or command[0] == "$headpat":
if len(command) == 2:
@ -481,7 +486,8 @@ while True:
multiline(choice(meows_upset), channel)
else:
multiline(choice(meows_happy), channel)
elif command[0] == "$stats":
multiline(f"{nick}: {run} command(s) run, {block} refused, and {parsed} link(s) parsed, check out https://irc-bot.swee.codes", channel)
elif command[0] == "$shell":
if perms == "full":
#or "shell" in perms.split(",")
@ -496,7 +502,7 @@ while True:
irc.send_irc(channel, nick + ": Permission denied.")
block+=1
run-=1
update()
elif command[0] == "$version":
irc.send_irc(channel, "This is SweeBot " + __version__)
@ -556,45 +562,15 @@ while True:
multiline(f"\x01ACTION gives a hug to {name}\x01", channel)
#elif command[0] == "$sed":
# if len(command) > 1:
#try:
# if True:
# com = ['sed',"" + command[1] + ""]
# print(command[1])
# texte = open("log-text-"+channel).read().split("\n")
# texte.reverse()
# texte.pop(0)
# texte.pop(0)
# print(texte)
# texttoreplace = ""
# j = 0
# broken = False
# for i in texte:
# if command[1].split("/")[1] in i:
# texttoreplace = i
# broken = True
# break
# j+=1
# if not broken:
# irc.send_irc(channel, "Unable to correct: '" + command[1].split("/")[1] + "' not found in any chat message.")
# continue
# namee = open("log-name-"+channel).read().split("\n")
# namee.reverse()
# namee.pop(0)
# namee.pop(0)
# namee = namee[j]
# open("temp","w").write(texttoreplace)
# com.append("temp")
# print(com)
# result = subprocess.run(com, stdout=subprocess.PIPE)
# output = result.stdout.decode('utf-8').split("\n")
# irc.send_irc(channel, "Correction using sed: <" + namee + "> " + output[0])
# #except Exception as ex:
# #irc.send_irc(channel, nick + ": " + ex.__class__.__name__)
# else:
# irc.send_irc(channel, nick + ": What to correct?")
elif command[0] == "$sed":
if len(command) > 1:
try:
#if True:
raise Exception("WorkInProgress!!!")
except:
print(traceback.format_exc())
else:
irc.send_irc(channel, nick + ": What to correct?")
elif command[0] == "$config":
@ -628,7 +604,7 @@ while True:
irc.send_irc(channel, nick + ": Permission denied")
block+=1
run-=1
update()
else:
multiline("Configuration for " + channel + ": " + " ".join(sbconfig.chansettings(channel)), channel)
except ex:
@ -639,7 +615,7 @@ while True:
irc.send_irc(channel, nick + ": Nice try.")
block+=1
run-=1
update()
else:
if path.isfile("cc/" + command[0][1:]):
try:
@ -682,11 +658,12 @@ while True:
if content_type in allowedparse:
if e.ok:
soup = BeautifulSoup(e.text, 'html.parser')
multiline("(" + nick + ") " + (soup.title.string if soup.title != None else "[No title provided]"), channel)
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:
@ -699,11 +676,12 @@ while True:
if content_type in allowedparse:
if e.ok:
soup = BeautifulSoup(e.text, 'html.parser')
multiline("(" + nick + ") " + (soup.title.string if soup.title != None else "[No title provided]"), channel)
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: