From a64c3b0d05c4bd1b9d42e3d559ba4fc04e466934 Mon Sep 17 00:00:00 2001 From: Swee Date: Tue, 10 Sep 2024 22:05:07 -0700 Subject: [PATCH] Fix a bug with $help, add sweeBot dashboard --- script.js | 32 ++++++++++++++++++++++++++++++++ sweebot-dashboard.py | 34 ++++++++++++++++++++++++++++++++++ sweebot.html | 18 ++++++++++++++++++ sweebot.py | 2 +- 4 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 script.js create mode 100644 sweebot-dashboard.py create mode 100644 sweebot.html diff --git a/script.js b/script.js new file mode 100644 index 0000000..078daad --- /dev/null +++ b/script.js @@ -0,0 +1,32 @@ +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)); +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) +fetch ("block.txt") +.then(x => x.text()) +.then(y => document.getElementById("blocked").innerHTML = y); +await delay(2000) +document.getElementById("refresh").innerHTML = "" +} \ No newline at end of file diff --git a/sweebot-dashboard.py b/sweebot-dashboard.py new file mode 100644 index 0000000..b664a45 --- /dev/null +++ b/sweebot-dashboard.py @@ -0,0 +1,34 @@ +from flask import Flask +from flask import send_file +from flask import request +from flask import redirect +import os +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("run.txt", mimetype='text/html') +@app.route('/block.txt') +def block(): + wait(2) + return send_file("block.txt", mimetype='text/html') +@app.route('/script.js') +def script(): + return send_file("script.js", mimetype='application/javascript') +@app.route('/reboot.run') +def reboot(): + os.system("systemctl --user restart sweebot") + wait(1) + return "" + + +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 new file mode 100644 index 0000000..c260f63 --- /dev/null +++ b/sweebot.html @@ -0,0 +1,18 @@ + +SweeBot dashboard + + + + +
+

SweeBot Dashboard

+

+

+ +
+
+ + +
+ + diff --git a/sweebot.py b/sweebot.py index 64883ce..5fcecf5 100644 --- a/sweebot.py +++ b/sweebot.py @@ -244,7 +244,7 @@ while True: update() else: if path.isfile("/home/swee/helps/" + " ".join(command[1:])): - output = open("/home/swee/helps/" + " ".join(command[1:])).read().split("\n") + output = open("/home/swee/helps/" + " ".join(command[1:])).read() multiline(output) else: irc.send_irc(channel, "Either the command isn't documented yet or it doesn't exist lol")