diff --git a/cogs/example.py b/cogs/example.py new file mode 100644 index 0000000..422e3af --- /dev/null +++ b/cogs/example.py @@ -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)) + diff --git a/cogs/web/__pycache__/web.cpython-39.pyc b/cogs/web/__pycache__/web.cpython-39.pyc new file mode 100644 index 0000000..48d32dc Binary files /dev/null and b/cogs/web/__pycache__/web.cpython-39.pyc differ diff --git a/cogs/web/config.toml b/cogs/web/config.toml new file mode 100644 index 0000000..492958e --- /dev/null +++ b/cogs/web/config.toml @@ -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" diff --git a/cogs/web/web.py b/cogs/web/web.py new file mode 100644 index 0000000..e9ebc00 --- /dev/null +++ b/cogs/web/web.py @@ -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)) + diff --git a/config.toml b/config.toml index 03a179a..b1358e4 100644 --- a/config.toml +++ b/config.toml @@ -14,4 +14,4 @@ key = "/path/to/private.key" [bot] -cogs=["cogs.example", "cogs.web"] +cogs=["cogs.example", "cogs.web.web"] diff --git a/main.py b/main.py index 187610a..a8536d2 100644 --- a/main.py +++ b/main.py @@ -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)