commit d19b1795f614f651a4f0a1161249d3b3bab0ebfe Author: cynic Date: Sun Oct 30 22:36:37 2022 -0400 first commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ed8ebf5 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +__pycache__ \ No newline at end of file diff --git a/cathedral.py b/cathedral.py new file mode 100644 index 0000000..85fe1e5 --- /dev/null +++ b/cathedral.py @@ -0,0 +1,26 @@ +from tower_manager import load_towers, handle_route +import asyncio +from aiohttp import web + +class cathedral(): + def __init__(self, settings): + self.cfg = settings + self.towers = load_towers(self.cfg.get("PLUGIN_PATH")) + async def handle_http(self, r): + return web.Response(text=f"lol dongs {r.host}") + async def start_http(self): + srv = web.Server(self.handle_http) + runner = web.ServerRunner(srv) + await runner.setup() + + site = web.TCPSite(runner, "localhost", 1488) + await site.start() + + print("serving...") + await asyncio.sleep(3600*24*365) + def erect(self): + l = asyncio.get_event_loop() + try: l.run_until_complete(self.start_http()) + except Exception as e: + print(e) + l.close() diff --git a/cli_params.py b/cli_params.py new file mode 100644 index 0000000..27f8da7 --- /dev/null +++ b/cli_params.py @@ -0,0 +1,34 @@ +from sys import argv, exit +from json import loads + +# so `spec` is supposed to be {strArgKey: (bRequired?, strDesc)} +def parse_args(spec): + given = [i[2:] if i[0:2] == "--" else i for i in argv[1:]] + + if "help" in given: + print( + "\n".join( + ["; ".join((opt, spec[opt][1], "required" if spec[opt][0] else "optional")) for opt in spec.keys()] + ) + ) + + settings = {} + traveller = 0 + while traveller < len(given): + opt = given[traveller] + if opt in spec.keys(): + settings[opt] = given[traveller + 1] + traveller += 1 + traveller += 1 + + for req in filter(lambda a: spec[a][0], spec.keys()): + if not(req in settings): + print(f"missing required parameter: '{req}'") + exit(-1) + return settings + +def fetch_cfg(filepath): + try: return loads(open(filepath, "r").read()) + except: + print(f"could not read config from path: '{filepath}',\nmake sure it is a valid JSON file") + exit(-2) \ No newline at end of file diff --git a/config.json b/config.json new file mode 100644 index 0000000..b45d949 --- /dev/null +++ b/config.json @@ -0,0 +1,3 @@ +{ + "PLUGIN_PATH": "./towers" +} \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..4c57779 --- /dev/null +++ b/main.py @@ -0,0 +1,9 @@ +from sys import argv +from cli_params import parse_args, fetch_cfg +from cathedral import cathedral + +args = parse_args({ + "cfg": (True, "path to config file") +}) +settings = fetch_cfg(args["cfg"]) +cathedral(settings).erect() \ No newline at end of file diff --git a/readme.txt b/readme.txt new file mode 100644 index 0000000..0525020 --- /dev/null +++ b/readme.txt @@ -0,0 +1,8 @@ +the core of a plugin-based usergroup system. +establishes a central auth for users, and loads plugins to carry out various functions based on events. + +requires aiohttp ~= 3.7.4 + +events: +USER_CREATE +READY \ No newline at end of file diff --git a/tower_manager.py b/tower_manager.py new file mode 100644 index 0000000..15c4d01 --- /dev/null +++ b/tower_manager.py @@ -0,0 +1,26 @@ +from os import listdir +from sys import path as working_path +from sys import exit + +def load_towers(dir): + working_path.append(dir) + found = [name.split(".py")[0] for name in listdir(dir) if name.endswith(".py")] + loaded = [] + + for tower in found: + try: lt = __import__(tower) + except Exception as e: + print(f"plugin '{tower}' could not be sucessfully loaded ({e})") + continue + + if not(hasattr(lt, "run")) or not(hasattr(lt, "hooks")): + print(f"plugin '{tower}' is missing critical elements and thus could not be loaded") + continue + + loaded.append(lt) + print(f"loaded plugin: '{tower}'") + + return loaded + +def handle_route(towers, route): + pass \ No newline at end of file diff --git a/towers/users.py b/towers/users.py new file mode 100644 index 0000000..d0ed1b7 --- /dev/null +++ b/towers/users.py @@ -0,0 +1,5 @@ + +hooks = [] + +def run(ctx): + pass \ No newline at end of file