Fix a bug with $help, add sweeBot dashboard
This commit is contained in:
parent
04804ddd12
commit
a64c3b0d05
4 changed files with 85 additions and 1 deletions
32
script.js
Normal file
32
script.js
Normal file
|
@ -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 = "<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)
|
||||
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>"
|
||||
}
|
34
sweebot-dashboard.py
Normal file
34
sweebot-dashboard.py
Normal file
|
@ -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 "<i class=\"fas fa-check\"></i>"
|
||||
|
||||
|
||||
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)
|
18
sweebot.html
Normal file
18
sweebot.html
Normal file
|
@ -0,0 +1,18 @@
|
|||
<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-danger" data-bs-toggle="tooltip" title="Restart bot" onclick="reboot();" id="rebooticon"><i class="fas fa-power-off"></i></a>
|
||||
<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>
|
|
@ -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")
|
||||
|
|
Loading…
Reference in a new issue