Made web ui into a cog it doesnt work yet but it doesnt throw errors. All pages are 404. Tho the web responds to get calls wich is good

main
supopur 2 years ago
parent 63d82f5785
commit 6d8c1c066a

@ -0,0 +1,14 @@
import discord
from discord.ext import commands
class Greetings(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.slash_command(guild_ids=["823188238260633600"])
async def hello(self, ctx):
await ctx.send(f'Hello {ctx.author}')
def setup(bot):
bot.add_cog(Greetings(bot))

@ -0,0 +1,13 @@
#The webserver plugin cofiguration file.
[webserver]
#This will specify the ip adress of the machine that the server is running on. I would recomend to change it as some pages might 404 if you dont.
ip=0.0.0.0
#The port to listen on.
port=5000
#Section related to security and .key, .crt file locations. Its really recomended to use ssl if you are exposing the web interface to the internet.
[SSL]
userssl=False
crt="certs/certificate.crt"
key="certs/private.key"

@ -0,0 +1,37 @@
import sys
import discord
from discord.ext import commands
import quart
import toml
import logging
class WebServer(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.app = quart.Quart(__name__)
with open("config.toml", "r") as f:
config = toml.load(f)
logging.info("Starting Quart server...")
bot.loop.create_task(self.app.run_task(config["webserver"]["ip"], config["webserver"]["port"]))
@self.app.route('/', methods=['GET'])
async def index():
return await render_template('index.html')
@self.app.route('/configuration', methods=['GET'])
async def configuration():
return await render_template('configuration.html')
@self.app.route('/dashboard', methods=['GET'])
async def dashboard():
return await render_template('dashboard.html')
@self.app.route('/plugins', methods=['GET'])
async def plugins():
return await render_template('plugins.html')
def setup(bot):
bot.add_cog(WebServer(bot))

@ -14,4 +14,4 @@ key = "/path/to/private.key"
[bot]
cogs=["cogs.example", "cogs.web"]
cogs=["cogs.example", "cogs.web.web"]

@ -19,8 +19,9 @@ else:
logging.basicConfig(filename='latest.log', encoding='utf-8', level=logging.INFO)
logging.getLogger().addHandler(logging.StreamHandler())
try:
os.remove("latest.log")
except: pass
def log(level, log):
if level == "inf":
logging.info(log)
@ -80,34 +81,6 @@ async def stop(ctx):
sys.exit("Terminated.")
else:
await ctx.respond("https://media.tenor.com/Iv6oKRuAhVEAAAAC/hal9000-im-sorry-dave.gif")
log("inf", "Loading Quart...")
#webserver
app = quart.Quart(__name__)
log("inf", "Quart loaded.")
#The index.
@app.route('/', methods=['GET'])
async def index():
return await render_template('index.html')
@app.route('/configuration', methods=['GET'])
async def configuration():
return await render_template('configuration.html')
@app.route('/dashboard', methods=['GET'])
async def dashboard():
return await render_template('dashboard.html')
@app.route('/plugins', methods=['GET'])
async def plugins():
return await render_template('plugins.html')
@app.route('/stop', methods=['GET'])
async def stop():
sys.exit("Web terminated.")
bot.loop.create_task(app.run_task('0.0.0.0', 5000))
bot.run(token)

Loading…
Cancel
Save