Prevent setting values to array settings and prevent adding to non-array
settings
This commit is contained in:
parent
08a74d8b4d
commit
764e1e3245
2 changed files with 12 additions and 5 deletions
|
@ -28,7 +28,7 @@ COMMENT_ACTIONS = {
|
||||||
|
|
||||||
@utils.export("channelset", {"setting": "github-hook",
|
@utils.export("channelset", {"setting": "github-hook",
|
||||||
"help": ("Disable/Enable showing BitBot's github commits in the "
|
"help": ("Disable/Enable showing BitBot's github commits in the "
|
||||||
"current channel")})
|
"current channel"), "array": True})
|
||||||
@utils.export("channelset", {"setting": "github-hide-prefix",
|
@utils.export("channelset", {"setting": "github-hide-prefix",
|
||||||
"help": "Hide/show command-like prefix on Github hook outputs",
|
"help": "Hide/show command-like prefix on Github hook outputs",
|
||||||
"validate": utils.bool_or_none})
|
"validate": utils.bool_or_none})
|
||||||
|
|
|
@ -7,15 +7,22 @@ CHANNELSETADD_HELP = ("Add to a specified channel setting for the "
|
||||||
class Module(ModuleManager.BaseModule):
|
class Module(ModuleManager.BaseModule):
|
||||||
def _set(self, category, event, target, array):
|
def _set(self, category, event, target, array):
|
||||||
settings = self.exports.get_all(category)
|
settings = self.exports.get_all(category)
|
||||||
settings_dict = dict([(setting["setting"], setting
|
settings_dict = {setting["setting"]: setting for setting in settings}
|
||||||
) for setting in settings])
|
|
||||||
|
|
||||||
if len(event["args_split"]) > 1:
|
if len(event["args_split"]) > 1:
|
||||||
setting = event["args_split"][0].lower()
|
setting = event["args_split"][0].lower()
|
||||||
if setting in settings_dict:
|
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 = " ".join(event["args_split"][1:])
|
||||||
value = settings_dict[setting].get("validate",
|
value = setting_options.get("validate", lambda x: x)(value)
|
||||||
lambda x: x)(value)
|
|
||||||
|
|
||||||
if not value == None:
|
if not value == None:
|
||||||
if array:
|
if array:
|
||||||
|
|
Loading…
Reference in a new issue