2018-09-27 10:46:10 +00:00
|
|
|
from src import ModuleManager, Utils
|
2018-08-28 13:55:57 +00:00
|
|
|
|
2018-09-27 10:46:10 +00:00
|
|
|
class Module(ModuleManager.BaseModule):
|
2016-04-03 12:20:05 +00:00
|
|
|
def _set(self, settings, event, target):
|
2018-09-02 18:54:45 +00:00
|
|
|
settings_dict = dict([(setting["setting"], setting
|
|
|
|
) for setting in settings])
|
2016-03-29 11:56:58 +00:00
|
|
|
if len(event["args_split"]) > 1:
|
|
|
|
setting = event["args_split"][0].lower()
|
2018-09-02 18:54:45 +00:00
|
|
|
if setting in settings_dict:
|
2016-03-29 11:56:58 +00:00
|
|
|
value = " ".join(event["args_split"][1:])
|
2018-09-02 18:54:45 +00:00
|
|
|
value = settings_dict[setting].get("validate",
|
|
|
|
lambda x: x)(value)
|
2016-03-29 11:56:58 +00:00
|
|
|
if not value == None:
|
2016-04-03 12:20:05 +00:00
|
|
|
target.set_setting(setting, value)
|
2016-03-29 11:56:58 +00:00
|
|
|
event["stdout"].write("Saved setting")
|
|
|
|
else:
|
|
|
|
event["stderr"].write("Invalid value")
|
|
|
|
else:
|
|
|
|
event["stderr"].write("Unknown setting")
|
|
|
|
elif len(event["args_split"]) == 1:
|
|
|
|
event["stderr"].write("Please provide a value")
|
|
|
|
else:
|
|
|
|
event["stdout"].write("Available settings: %s" % (
|
2018-09-02 18:54:45 +00:00
|
|
|
", ".join(settings_dict.keys())))
|
2018-09-26 17:27:17 +00:00
|
|
|
@Utils.hook("received.command.set", usage="<setting> <value>")
|
2016-03-29 11:56:58 +00:00
|
|
|
def set(self, event):
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
|
|
|
Set a specified user setting
|
|
|
|
"""
|
2018-09-02 18:54:45 +00:00
|
|
|
self._set(self.exports.get_all("set"), event, event["user"])
|
2016-03-29 11:56:58 +00:00
|
|
|
|
2018-09-26 17:27:17 +00:00
|
|
|
@Utils.hook("received.command.channelset", channel_only=True,
|
|
|
|
usage="<setting> <value>", require_mode="o")
|
|
|
|
@Utils.hook("received.command.channelsetoverride", channel_only=True,
|
|
|
|
usage="<setting> <value>", permission="channelsetoverride")
|
2016-03-29 11:56:58 +00:00
|
|
|
def channel_set(self, event):
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
|
|
|
Get a specified channel setting for the current channel
|
|
|
|
"""
|
2018-09-09 08:34:55 +00:00
|
|
|
self._set(self.exports.get_all("channelset"), event, event["target"])
|
|
|
|
|
2018-09-26 17:27:17 +00:00
|
|
|
@Utils.hook("received.command.serverset", usage="<setting> <value>",
|
|
|
|
permission="serverset")
|
2018-09-09 08:34:55 +00:00
|
|
|
def server_set(self, event):
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
|
|
|
Set a specified server setting for the current server
|
|
|
|
"""
|
2018-09-09 08:34:55 +00:00
|
|
|
self._set(self.exports.get_all("serverset"), event, event["server"])
|
2018-08-08 19:45:57 +00:00
|
|
|
|
|
|
|
def _get(self, event, setting, qualifier, value):
|
|
|
|
if not value == None:
|
|
|
|
event["stdout"].write("'%s'%s: %s" % (setting,
|
2018-08-08 19:49:34 +00:00
|
|
|
qualifier, str(value)))
|
2016-03-29 11:56:58 +00:00
|
|
|
else:
|
2018-08-08 19:45:57 +00:00
|
|
|
event["stdout"].write("'%s' has no value set" % setting)
|
|
|
|
|
2018-09-26 17:27:17 +00:00
|
|
|
@Utils.hook("received.command.get", min_args=1, usage="<setting>")
|
2018-09-09 08:34:55 +00:00
|
|
|
def get(self, event):
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
|
|
|
Get a specified user setting
|
|
|
|
"""
|
2018-09-09 08:34:55 +00:00
|
|
|
setting = event["args_split"][0]
|
|
|
|
self._get(event, setting, "", event["user"].get_setting(
|
|
|
|
setting, None))
|
|
|
|
|
2018-09-26 17:27:17 +00:00
|
|
|
@Utils.hook("received.command.channelget", channel_only=True,
|
|
|
|
usage="<setting>", min_args=1, require_mode="o")
|
2018-08-08 19:45:57 +00:00
|
|
|
def channel_get(self, event):
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
|
|
|
Get a specified channel setting for the current channel
|
|
|
|
"""
|
2018-08-08 19:45:57 +00:00
|
|
|
setting = event["args_split"][0]
|
2018-08-08 19:49:34 +00:00
|
|
|
self._get(event, setting, " for %s" % event["target"].name,
|
|
|
|
event["target"].get_setting(setting, None))
|
2018-08-08 19:45:57 +00:00
|
|
|
|
2018-09-26 17:27:17 +00:00
|
|
|
@Utils.hook("received.command.serverget", usage="<setting>", min_args=1,
|
|
|
|
permission="serverget")
|
2018-09-09 08:34:55 +00:00
|
|
|
def server_get(self, event):
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
|
|
|
Get a specified server setting for the current server
|
|
|
|
"""
|
2018-08-08 19:45:57 +00:00
|
|
|
setting = event["args_split"][0]
|
2018-09-09 08:38:35 +00:00
|
|
|
self._get(event, setting, "", event["server"].get_setting(
|
|
|
|
setting, None))
|