diff --git a/dashboard.html b/dashboard.html new file mode 100644 index 0000000..ee936c6 --- /dev/null +++ b/dashboard.html @@ -0,0 +1,16 @@ +MeowNexUS IRC - Dashboard + + + +
+

MeowNexUS IRC

+ + ...
+ ...
+ ...
+
+
+ +
+ + diff --git a/script.js b/script.js index 078daad..54c44c9 100644 --- a/script.js +++ b/script.js @@ -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 = "" - fetch ("reboot.run") .then(x => x.text()) - .then(y => document.getElementById("rebooticon").innerHTML = y); - await delay(2000) - document.getElementById("rebooticon").innerHTML = "" -} -async function refresh(){ -document.getElementById("refresh").innerHTML = "" -document.getElementById("run").innerHTML = "" -document.getElementById("blocked").innerHTML = "" -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 = "" + .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); } \ No newline at end of file diff --git a/sweebot-dashboard.py b/sweebot-dashboard.py deleted file mode 100644 index bd55bae..0000000 --- a/sweebot-dashboard.py +++ /dev/null @@ -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) \ No newline at end of file diff --git a/sweebot.html b/sweebot.html deleted file mode 100644 index 48456ed..0000000 --- a/sweebot.html +++ /dev/null @@ -1,17 +0,0 @@ - -SweeBot dashboard - - - - -
-

SweeBot Dashboard

-

-

- -
-
- -
- - diff --git a/sweebot.py b/sweebot.py index 307d2a9..b28a759 100644 --- a/sweebot.py +++ b/sweebot.py @@ -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: