From 764e1e3245fc6d1deac9042fad128362be59d042 Mon Sep 17 00:00:00 2001 From: jesopo Date: Wed, 5 Dec 2018 12:13:29 +0000 Subject: [PATCH] Prevent setting values to array settings and prevent adding to non-array settings --- modules/github.py | 2 +- modules/set.py | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/modules/github.py b/modules/github.py index ed27e1a9..c147ae42 100644 --- a/modules/github.py +++ b/modules/github.py @@ -28,7 +28,7 @@ COMMENT_ACTIONS = { @utils.export("channelset", {"setting": "github-hook", "help": ("Disable/Enable showing BitBot's github commits in the " - "current channel")}) + "current channel"), "array": True}) @utils.export("channelset", {"setting": "github-hide-prefix", "help": "Hide/show command-like prefix on Github hook outputs", "validate": utils.bool_or_none}) diff --git a/modules/set.py b/modules/set.py index 24a234e6..d7310cc3 100644 --- a/modules/set.py +++ b/modules/set.py @@ -7,15 +7,22 @@ CHANNELSETADD_HELP = ("Add to a specified channel setting for the " class Module(ModuleManager.BaseModule): def _set(self, category, event, target, array): settings = self.exports.get_all(category) - settings_dict = dict([(setting["setting"], setting - ) for setting in settings]) + settings_dict = {setting["setting"]: setting for setting in settings} if len(event["args_split"]) > 1: setting = event["args_split"][0].lower() if setting in settings_dict: + setting_options = settings_dict[setting] + if not setting_options.get("array", False) == array: + if array: + raise utils.EventError( + "Can't add to a non-array setting") + else: + raise utils.EventError( + "You can only 'add' to an array setting") + value = " ".join(event["args_split"][1:]) - value = settings_dict[setting].get("validate", - lambda x: x)(value) + value = setting_options.get("validate", lambda x: x)(value) if not value == None: if array: