added a function to Utils to get the "closest" setting, with channel/user settings being more important than server-wide settings.

This commit is contained in:
jesopo 2016-05-06 13:36:01 +01:00
parent 9c9d7aa439
commit 5338859e31
No known key found for this signature in database
GPG key ID: 0BBDEB2AEFCFFCB3
3 changed files with 12 additions and 2 deletions

View file

@ -174,3 +174,13 @@ def bool_or_none(s):
return True
elif s in IS_FALSE:
return False
def get_closest_setting(event, setting, default=None):
server = event["server"]
if "channel" in event:
closest = event["channel"]
elif "target" in event and "is_channel" in event and event["is_channel"]:
closest = event["target"]
else:
closest = event["user"]
return closest.get_setting(setting, server.get_setting(setting, default))

View file

@ -128,7 +128,7 @@ class Module(object):
self.bot.events.on("received").on("command").on(command).call(
1, user=user, server=server, target=target, log=log,
args=args, args_split=args_split, stdout=stdout, stderr=stderr,
command=command.lower())
command=command.lower(), is_channel=is_channel)
stdout.send()
target.last_stdout = stdout
stderr.send()

View file

@ -18,7 +18,7 @@ class Module(object):
validate=Utils.bool_or_none)
def channel_message(self, event):
if event["action"] or not event["channel"].get_setting("sed", True):
if event["action"] or not Utils.get_closest_setting(event, "sed", True):
return
sed_split = re.split(REGEX_SPLIT, event["message"], 3)
if event["message"].startswith("s/") and len(sed_split) > 2: