commit
d19b1795f6
@ -0,0 +1 @@ |
|||||||
|
__pycache__ |
@ -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() |
@ -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) |
@ -0,0 +1,3 @@ |
|||||||
|
{ |
||||||
|
"PLUGIN_PATH": "./towers" |
||||||
|
} |
@ -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() |
@ -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 |
@ -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 |
@ -0,0 +1,5 @@ |
|||||||
|
|
||||||
|
hooks = [] |
||||||
|
|
||||||
|
def run(ctx): |
||||||
|
pass |
Loading…
Reference in new issue