diff options
| author | 2020-04-08 14:29:52 +0100 | |
|---|---|---|
| committer | 2020-04-08 14:29:52 +0100 | |
| commit | 5df8df83ad523d8814d69cbf688f0b0944a7f38e (patch) | |
| tree | 952f783b42a5deabea8ae9fdd04aa4d767b50f15 /src/core_modules | |
| parent | remove now-unused vars (diff) | |
| signature | ||
fail an alias when an ${} var isn't found
Diffstat (limited to 'src/core_modules')
| -rw-r--r-- | src/core_modules/aliases.py | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/src/core_modules/aliases.py b/src/core_modules/aliases.py index b6ca8961..b5ed86f1 100644 --- a/src/core_modules/aliases.py +++ b/src/core_modules/aliases.py @@ -3,6 +3,8 @@ from src import EventManager, ModuleManager, utils SETTING_PREFIX = "command-alias-" +class VariableKeyError(KeyError): + pass class Module(ModuleManager.BaseModule): def _arg_replace(self, s, args_split, kwargs): vars = {} @@ -11,7 +13,11 @@ class Module(ModuleManager.BaseModule): vars["%d-" % i] = " ".join(args_split[i:]) vars["-"] = " ".join(args_split) vars.update(kwargs) - return utils.parse.format_token_replace(s, vars) + + not_found, new_s = utils.parse.format_token_replace(s, vars) + if not_found: + raise VariableKeyError(f"not found: {not_found!r}") + return new_s def _get_alias(self, server, target, command): setting = "%s%s" % (SETTING_PREFIX, command) @@ -45,9 +51,14 @@ class Module(ModuleManager.BaseModule): if event["command"].args: given_args = event["command"].args.split(" ") - event["command"].command = alias - event["command"].args = self._arg_replace(alias_args, given_args, - event["kwargs"]) + try: + event["command"].args = self._arg_replace(alias_args, + given_args, event["kwargs"]) + except VariableKeyError: + pass + else: + event["command"].command = alias + @utils.hook("received.command.alias", permission="alias") |
