diff --git a/verify.py b/verify.py index dd41e9a..29493b4 100644 --- a/verify.py +++ b/verify.py @@ -48,11 +48,15 @@ def validBind(key, data, alias = False) -> list: return ret -validKeyList = [ '\'', '=', ',', '-', - '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'semicolon', - '[', '\\', ']', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'space', 'enter', - 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', - 'x', 'y', 'z', 'mouse1', 'mouse2', 'mouse3', 'mouse4', 'mouse5', 'capslock', 'ctrl' ] +validKeyList = [ + '\'', '=', ',', '-', '[', '\\', ']', '`', '.', '/', + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', + 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', + 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', + 'u', 'v', 'w', 'x', 'y', 'z', + 'mouse1', 'mouse2', 'mouse3', 'mouse4', 'mouse5', + 'shift', 'capslock', 'ctrl', 'semicolon', 'space', 'enter' +] def validKey(key): """determines if the key is a valid key""" @@ -60,6 +64,10 @@ def validKey(key): return key in validKeyList def validBindType(key, data: dict): + """ + Checks if `key` has a valid bind type, + like 'double' or 'hold' + """ validType = False types = [ "impulse", @@ -91,10 +99,27 @@ def removeRelaventFields(data, bindType): if "primary" not in content: errMsgs.append("Double requires primary action") else: - errMessages = validBind("primary", content) + # Nasty bit of recursion to validate the action. + # It takes advantage of `alias = True` not verifying the key, + # but it isn't an alias, I'm just lazy. + errMessages = validBind("primary", content["primary"], alias = True) + if len(errMessages) > 0: + errMsgs += errMessages + if "secondary" not in content: errMsgs.append("Double requires secondary action") + else: + # Same logic as above + errMessages = validBind("secondary", content["secondary"], alias = True) + if len(errMessages) > 0: + errMsgs += errMessages + if "condition" not in content: errMsgs.append("Double requires condition to toggle") + else: + # Validate the toggler + key = content["condition"] + if not validKey(key): + errMsgs.append(f'Invalid key "{key}"') return data, errMsgs