From 87ff49c4d259d653c19b4e6e25c07024ee8cd95c Mon Sep 17 00:00:00 2001 From: jesopo Date: Sun, 9 Sep 2018 09:34:55 +0100 Subject: [PATCH] Add !serverset and !serverget --- modules/commands.py | 8 +++++--- modules/set.py | 24 +++++++++++++++++++----- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/modules/commands.py b/modules/commands.py index 79631a8c..21b0f361 100644 --- a/modules/commands.py +++ b/modules/commands.py @@ -64,13 +64,15 @@ class Module(object): help="Unignore commands from a given user", usage="", permission="unignore") - exports.add("channelset", {"setting": "command-prefix", - "help": "Set the command prefix used in this channel"}) - events.on("new").on("user", "channel").hook(self.new) events.on("send").on("stdout").hook(self.send_stdout) events.on("send").on("stderr").hook(self.send_stderr) + exports.add("channelset", {"setting": "command-prefix", + "help": "Set the command prefix used in this channel"}) + exports.add("serverset", {"setting": "identity-mechanism", + "help": "Set the identity mechanism for this server"}) + def new(self, event): if "user" in event: target = event["user"] diff --git a/modules/set.py b/modules/set.py index a9a677ae..6735b34a 100644 --- a/modules/set.py +++ b/modules/set.py @@ -22,6 +22,13 @@ class Module(object): require_mode="o", help="Get a specified setting for the current " "channel") + events.on("received.command.serverset").hook(self.server_set, + usage=" ", permission="serverset", + help="Set a specified setting for the current server") + events.on("received.command.serverget").hook(self.server_get, + usage="", min_args=1, permission="serverget", + help="Get a specified setting for the current server") + def _set(self, settings, event, target): settings_dict = dict([(setting["setting"], setting ) for setting in settings]) @@ -47,8 +54,10 @@ class Module(object): self._set(self.exports.get_all("set"), event, event["user"]) def channel_set(self, event): - self._set(self.exports.get_all("channelset"), event, - event["target"]) + self._set(self.exports.get_all("channelset"), event, event["target"]) + + def server_set(self, event): + self._set(self.exports.get_all("serverset"), event, event["server"]) def _get(self, event, setting, qualifier, value): if not value == None: @@ -57,12 +66,17 @@ class Module(object): else: event["stdout"].write("'%s' has no value set" % setting) + def get(self, event): + setting = event["args_split"][0] + self._get(event, setting, "", event["user"].get_setting( + setting, None)) + def channel_get(self, event): setting = event["args_split"][0] self._get(event, setting, " for %s" % event["target"].name, event["target"].get_setting(setting, None)) - def get(self, event): + def server_get(self, event): setting = event["args_split"][0] - self._get(event, setting, "", event["user"].get_setting( - setting, None)) + self._get(event, setting, " for %s" % event["server"].name, + event["server"].get_setting(setting, None))