From a6715d8dcf3629e71ab2c7f1328fda74d9bc4084 Mon Sep 17 00:00:00 2001 From: Jarno Rankinen Date: Wed, 26 Oct 2022 21:49:55 +0300 Subject: [PATCH] Get/set Motion config parameters --- modules/cam.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/modules/cam.py b/modules/cam.py index 60d2534..936d646 100644 --- a/modules/cam.py +++ b/modules/cam.py @@ -52,24 +52,31 @@ class MatrixModule(BotModule): await bot.send_text(room, f"Motion URL is currently {self.motionurl}") else: - recvd_camid = 1 + cmdindex = 1 try: # Check if first argument is numeric (camera id) camid = int(args[0]) camid = str(camid) except ValueError: - recvd_camid = 0 + cmdindex = 0 camid = '0' - if args[recvd_camid] not in self.allowed_cmds: + if args[cmdindex] not in self.allowed_cmds: await bot.send_text(room, f'Unknown category: "{args[1]}"', event) return - category = args[recvd_camid] - recvd_camid = recvd_camid + 1 - if args[recvd_camid] not in self.allowed_cmds[category]: - await bot.send_text(room, f'Unknown command: "{args[recvd_camid]}"', event) + category = args[cmdindex] + cmdindex = cmdindex + 1 + if args[cmdindex] not in self.allowed_cmds[category]: + await bot.send_text(room, f'Unknown command: "{args[cmdindex]}"', event) return - command = args[recvd_camid] + command = args[cmdindex] req_url = f'{self.motionurl}/{camid}/{category}/{command}' + if category == 'config' and command == 'get': + queryparam = args[cmdindex + 1] + req_url = f'{req_url}?query={queryparam}' + elif category == 'config' and command == 'set': + param = args[cmdindex + 1] + value = args[cmdindex + 2] + req_url = f'{req_url}?{param}={value}' resp = requests.get(req_url).text await bot.send_text(room, resp, event)