diff --git a/cogs/web/__pycache__/web.cpython-39.pyc b/cogs/web/__pycache__/web.cpython-39.pyc deleted file mode 100644 index 812facb..0000000 Binary files a/cogs/web/__pycache__/web.cpython-39.pyc and /dev/null differ diff --git a/cogs/web/config.toml b/cogs/web/config.toml deleted file mode 100644 index 492958e..0000000 --- a/cogs/web/config.toml +++ /dev/null @@ -1,13 +0,0 @@ -#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/static/configuration.css b/cogs/web/static/configuration.css deleted file mode 100644 index fca533e..0000000 --- a/cogs/web/static/configuration.css +++ /dev/null @@ -1,88 +0,0 @@ -body { - font-family: Arial, sans-serif; - margin: 0; - padding: 0; - background-color: #2c3e50; - color: #fff; -} - -.logo { - width: 25; - height: 25; -} - -header { - background-color: #3e4982; - color: #fff; - padding: 20px; - text-align: center; -} - -header h1 { - margin: 0; -} - -.container { - display: flex; -} - -table { - font-family: Arial, Helvetica, sans-serif; - border-collapse: collapse; - width: 100%; -} - -table td, -#status th { - border: 1px solid #ddd; - padding: 8px; -} - -table tr:nth-child(even) { - background-color: #1c567d; -} - -table tr:hover { - background-color: #2980b9; -} - -table th { - padding-top: 12px; - padding-bottom: 12px; - text-align: left; - background-color: #04AA6D; - color: white; -} - -nav { - background-color: #34495e; - width: 200px; - padding: 20px; - text-align: center; -} - -nav ul { - list-style: none; - margin: 0; - padding: 0; -} - -nav li a { - color: #fff; - text-decoration: none; - padding: 10px 0; - display: block; -} - -nav li a:hover { - background-color: #2980b9; -} - -.selected { - background-color: #2980b9; -} - -main { - padding: 20px; - flex-grow: 1; -} \ No newline at end of file diff --git a/cogs/web/static/dashboard.css b/cogs/web/static/dashboard.css deleted file mode 100644 index b92a2c9..0000000 --- a/cogs/web/static/dashboard.css +++ /dev/null @@ -1,88 +0,0 @@ -body { - font-family: Arial, sans-serif; - margin: 0; - padding: 0; - background-color: #2c3e50; - color: #fff; -} - -.logo { - width: 25; - height: 25; -} - -header { - background-color: #3e4982; - color: #fff; - padding: 20px; - text-align: center; -} - -header h1 { - margin: 0; -} - -.container { - display: flex; -} - -table { - font-family: Arial, Helvetica, sans-serif; - border-collapse: collapse; - width: 100%; -} - -table td, -#status th { - border: 1px solid #ddd; - padding: 8px; -} - -table tr:nth-child(even) { - background-color: #1c567d; -} - -table tr:hover { - background-color: #2980b9; -} - -table th { - padding-top: 12px; - padding-bottom: 12px; - text-align: left; - background-color: #04AA6D; - color: white; -} - -nav { - background-color: #34495e; - width: 200px; - padding: 20px; - text-align: center; -} - -nav ul { - list-style: none; - margin: 0; - padding: 0; -} - -nav li a { - color: #fff; - text-decoration: none; - padding: 10px 0; - display: block; -} - -nav li a:hover { - background-color: #2980b9; -} - -.selected { - background-color: #2980b9; -} - -main { - padding: 20px; - flex-grow: 1; -} diff --git a/cogs/web/static/index.css b/cogs/web/static/index.css deleted file mode 100644 index 9ac95ae..0000000 --- a/cogs/web/static/index.css +++ /dev/null @@ -1,61 +0,0 @@ -body { - font-family: Arial, sans-serif; - margin: 0; - padding: 0; - background-color: #2c3e50; - color: #fff; -} -.selected { - background-color: #2980b9; -} -.logo { - width: 25; - height: 25; -} - -header { - background-color: #3e4982; - color: #fff; - padding: 20px; - text-align: center; -} - -header h1 { - margin: 0; -} - -.container { - display: flex; -} - -nav { - background-color: #34495e; - width: 200px; - padding: 20px; - text-align: center; -} - -nav ul { - list-style: none; - margin: 0; - padding: 0; -} - -nav li a { - color: #fff; - text-decoration: none; - padding: 10px 0; - display: block; -} - -nav li a:hover { - background-color: #2980b9; -} - -main { - padding: 20px; - flex-grow: 1; -} - - - diff --git a/cogs/web/static/js/configuration.js b/cogs/web/static/js/configuration.js deleted file mode 100644 index 4aa072e..0000000 --- a/cogs/web/static/js/configuration.js +++ /dev/null @@ -1,66 +0,0 @@ -const form = document.querySelector("form"); -const tokenInput = form.querySelector("#token"); -const nameInput = form.querySelector("#name"); -const statusSelect = form.querySelector("#status"); - -// set the token input as password field -tokenInput.setAttribute("type", "password"); - -// function to get the config values from the server -const getConfigValues = async () => { - try { - const tokenResponse = await fetch('/api/token'); - const tokenValue = await tokenResponse.text(); - tokenInput.value = tokenValue; - - const nameResponse = await fetch('/api/name'); - const nameValue = await nameResponse.text(); - nameInput.value = nameValue; - - const statusResponse = await fetch('/api/status'); - const statusValue = await statusResponse.text(); - statusSelect.value = statusValue; - } catch (error) { - console.error(error); - } -} - -getConfigValues(); - -form.addEventListener("submit", async (event) => { - event.preventDefault(); - const token = tokenInput.value; - const name = nameInput.value; - const status = statusSelect.value; - - try { - // send POST request to /api/token endpoint with token as the body - if (token !== '') { - await fetch('/api/token', { - method: 'POST', - body: token - }); - } - - - // send POST request to /api/name endpoint with name as the body - if (name !== '') { - await fetch('/api/name', { - method: 'POST', - body: name - }); - } - - - // send POST request to /api/status endpoint with status as the body - if (status !== '') { - await fetch('/api/status', { - method: 'POST', - body: status - }); - } - - } catch (error) { - console.error(error); - } -}); \ No newline at end of file diff --git a/cogs/web/static/plugins.css b/cogs/web/static/plugins.css deleted file mode 100644 index fca533e..0000000 --- a/cogs/web/static/plugins.css +++ /dev/null @@ -1,88 +0,0 @@ -body { - font-family: Arial, sans-serif; - margin: 0; - padding: 0; - background-color: #2c3e50; - color: #fff; -} - -.logo { - width: 25; - height: 25; -} - -header { - background-color: #3e4982; - color: #fff; - padding: 20px; - text-align: center; -} - -header h1 { - margin: 0; -} - -.container { - display: flex; -} - -table { - font-family: Arial, Helvetica, sans-serif; - border-collapse: collapse; - width: 100%; -} - -table td, -#status th { - border: 1px solid #ddd; - padding: 8px; -} - -table tr:nth-child(even) { - background-color: #1c567d; -} - -table tr:hover { - background-color: #2980b9; -} - -table th { - padding-top: 12px; - padding-bottom: 12px; - text-align: left; - background-color: #04AA6D; - color: white; -} - -nav { - background-color: #34495e; - width: 200px; - padding: 20px; - text-align: center; -} - -nav ul { - list-style: none; - margin: 0; - padding: 0; -} - -nav li a { - color: #fff; - text-decoration: none; - padding: 10px 0; - display: block; -} - -nav li a:hover { - background-color: #2980b9; -} - -.selected { - background-color: #2980b9; -} - -main { - padding: 20px; - flex-grow: 1; -} \ No newline at end of file diff --git a/cogs/web/templates/configuration.html b/cogs/web/templates/configuration.html deleted file mode 100644 index c416904..0000000 --- a/cogs/web/templates/configuration.html +++ /dev/null @@ -1,47 +0,0 @@ - - - - - MEE2 Configuration - - - - - - -
-

MEE2 Configuration

-
-
- -
-
- - -
- - -
- - -
- -
-
-
- - - \ No newline at end of file diff --git a/cogs/web/templates/dashboard.html b/cogs/web/templates/dashboard.html deleted file mode 100644 index 8913275..0000000 --- a/cogs/web/templates/dashboard.html +++ /dev/null @@ -1,54 +0,0 @@ - - - - - MEE2 Dashboard - - - - - -
-

MEE2 - Admin Dashboard

-
-
- -
-

This is the admin dashboard. Here you can see important thing like the uptime, hits per minute, cogs status etc..

- - - - - - - - - - - - - - - - - - - - - -
ModuleStatusModule link
Uptime1 Year/api/uptime
Hits Per Minute10/api/hpm
Plugin - FivemOnline/plugins/fivem
-
- -
- - - diff --git a/cogs/web/templates/index.html b/cogs/web/templates/index.html deleted file mode 100644 index 5413691..0000000 --- a/cogs/web/templates/index.html +++ /dev/null @@ -1,34 +0,0 @@ - - - - - MEE2 Index - - - - - - -
-

MEE2

-
-
- -
-

Welcome to the MEE2 index page.

-

This bot is designed to help you with various tasks and make your life easier

-

Here you can find information about the bot's features, plugins, configuration, and support. All this info is public. If you want you can turn it off in the settings page.

-
-
- - - diff --git a/cogs/web/templates/plugins.html b/cogs/web/templates/plugins.html deleted file mode 100644 index 970ce15..0000000 --- a/cogs/web/templates/plugins.html +++ /dev/null @@ -1,54 +0,0 @@ - - - - - MEE2 Plugins - - - - - -
-

MEE2 - Plugins

-
-
- -
-

This is the plugin page here you can disable/enable the individual cogs.

- - - - - - - - - - - - - - - - - - - - - -
PluginStatusPlugin link
Uptime1 Year/api/uptime
Hits Per Minute10/api/hpm
Plugin - FivemOnline/plugins/fivem
-
- -
- - - \ No newline at end of file diff --git a/cogs/web/web.py b/cogs/web/web.py deleted file mode 100644 index 24cba8c..0000000 --- a/cogs/web/web.py +++ /dev/null @@ -1,39 +0,0 @@ -import sys -import discord -from discord.ext import commands -import quart -import toml -import logging -from quart import render_template -from quart.helpers import make_response - -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 b1358e4..3ca8931 100644 --- a/config.toml +++ b/config.toml @@ -14,4 +14,4 @@ key = "/path/to/private.key" [bot] -cogs=["cogs.example", "cogs.web.web"] +cogs=["cogs.example", "cogs.web.web", "cogs.sapi.sapi"] diff --git a/main.py b/main.py index 00d9236..2a83043 100644 --- a/main.py +++ b/main.py @@ -2,13 +2,6 @@ import discord, os, sys, toml, time, datetime, logging from discord.ext import commands - - - - - - - with open("config.toml", "r") as f: config = toml.load(f) @@ -53,6 +46,56 @@ bot = commands.Bot(command_prefix='!', intents=intents) logging.debug("Loaded the client.") + +#Api used mainly for plugins so getting uptime, loading, unloading, reloading plugins, getting status of plugins, get plugin info, stopping the bot, getting bot name and tag, getting cpm/commands per minute, get if there is web plugin, if there is web plugin register api, get if plugin supports web and so on.. + +class API: + + #Returns config.tomls content in a array. + def get_config(self): + return self.config + #Dumps all the toml data from self.config and stores it inside toml.config + def save_config(self): + try: + with open("config.toml", w) as f: + self.log("inf", "Saving the configuration file...") + toml.dump(self.config, f) + self.log("inf", "Config was saved to config.toml") + #aok + return 0 + #In case file doesnt exist + except Exception as e: + self.log("err", f"Failed to save to config.toml. {e}") + return 1 + #Connect the main .log file to the api so plugins can log to latest.log w/o risking corrupting the file. + def log(self, status, log): + self.logger(str(status), str(log)) + def load(self, extension): + self.logger("inf", f"Loading {extension}...") + + extension = str(extension) + + if extension.startswith("cogs."): + extension.replace("cogs.", "", 1) + + try: + self.bot.load_extension(f"cogs.{extension}") + except Exception as e: + self.logger("wrn", f"Extension {extension} failed to load due to: {e}") + else: + self.config["bot"]["cogs"].append(f"cogs.{extension}") + self.save_config() + self.logger("inf", f"Extension {extension} loaded.") + + + def __init__(self, config, bot, log): + self.start_time = time.time() + self.config = config + self.bot = bot + self.logger = log + +print(type(config["bot"])) + #Load all the extensions for x in config["bot"]["cogs"]: log("inf", f"Loading {x}...") @@ -81,5 +124,7 @@ async def stop(ctx): else: await ctx.respond("https://media.tenor.com/Iv6oKRuAhVEAAAAC/hal9000-im-sorry-dave.gif") +if __name__ == "__main__": + api = API(config, bot, log) + bot.run(token) -bot.run(token)