feat: add room to api config
This commit is contained in:
parent
778ebcdad9
commit
e42aa941e5
4 changed files with 43 additions and 24 deletions
|
@ -72,17 +72,16 @@ args = parser.parse_args()
|
|||
if args.config:
|
||||
with open(args.config) as f:
|
||||
config = yaml.safe_load(f)
|
||||
SERVER_ADDRESS = (config["hostname"], config["port"])
|
||||
SERVER_ADDRESS = (config["host"], config["port"])
|
||||
MATRIX_URL = config["matrix"]["url"]
|
||||
MATRIX_ID = config["matrix"]["id"]
|
||||
MATRIX_PW = config["matrix"]["pw"]
|
||||
API_KEYS = config["api_keys"]
|
||||
LOG_FILE = config["log"]
|
||||
API_KEYS = config["api_keys"].keys()
|
||||
ROOM_KEYS = config["api_keys"]
|
||||
VERBOSE = get_numeric_log_level(config["log"]["level"])
|
||||
else:
|
||||
SERVER_ADDRESS = (args.host, args.port)
|
||||
MATRIX_URL = args.matrix_url
|
||||
LOG_FILE = args.log
|
||||
if not args.matrix_id:
|
||||
print("Missing matrix user-id. Use -i or --matrix-id or specify in config.yaml")
|
||||
sys.exit(1)
|
||||
|
|
|
@ -37,14 +37,22 @@ async def matrix_webhook(request):
|
|||
|
||||
if "formatter" in request.rel_url.query:
|
||||
try:
|
||||
format = request.rel_url.query["formatter"]
|
||||
plugin = importlib.import_module(f"matrix_webhook.formatters.{format}", "formatter")
|
||||
format_type = request.rel_url.query["formatter"]
|
||||
plugin = importlib.import_module(
|
||||
f"matrix_webhook.formatters.{format_type}", "formatter"
|
||||
)
|
||||
data = plugin.formatter(data, request.headers)
|
||||
except ModuleNotFoundError:
|
||||
return utils.create_json_response(
|
||||
HTTPStatus.BAD_REQUEST, "Unknown formatter"
|
||||
)
|
||||
|
||||
if (
|
||||
"room_id" not in request.rel_url.query
|
||||
and "room_id" not in data
|
||||
and conf.ROOM_KEYS[f'{data["key"]}']
|
||||
):
|
||||
data["room_id"] = conf.ROOM_KEYS[f'{data["key"]}']
|
||||
if "room_id" in request.rel_url.query and "room_id" not in data:
|
||||
data["room_id"] = request.rel_url.query["room_id"]
|
||||
if "room_id" not in data:
|
||||
|
@ -88,4 +96,5 @@ async def matrix_webhook(request):
|
|||
"format": "org.matrix.custom.html",
|
||||
"formatted_body": formatted_body,
|
||||
}
|
||||
print(conf.ROOM_KEYS)
|
||||
return await utils.send_room_message(data["room_id"], content)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue