2016-03-29 11:56:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Module(object):
|
|
|
|
def __init__(self, bot):
|
|
|
|
self.bot = bot
|
|
|
|
self.settings = {}
|
|
|
|
self.channel_settings = {}
|
|
|
|
bot.events.on("postboot").on("configure").on("set").hook(
|
|
|
|
self.postboot_set)
|
|
|
|
bot.events.on("postboot").on("configure").on("channelset"
|
|
|
|
).hook(self.postboot_channelset)
|
|
|
|
bot.events.on("received").on("command").on("set").hook(
|
|
|
|
self.set, help="Set a specified user setting")
|
|
|
|
bot.events.on("received").on("command").on("channelset"
|
2016-03-29 13:37:35 +00:00
|
|
|
).hook(self.channel_set, channel_only=True,
|
|
|
|
help="Set a specified setting for the current channel")
|
2016-03-29 11:56:58 +00:00
|
|
|
|
|
|
|
def _postboot_set(self, settings, event):
|
|
|
|
settings[event["setting"]] = {}
|
|
|
|
settings[event["setting"]]["validate"] = event.get(
|
|
|
|
"validate", lambda s: s)
|
|
|
|
settings[event["setting"]]["help"] = event.get("help",
|
|
|
|
"")
|
|
|
|
def postboot_set(self, event):
|
|
|
|
self._postboot_set(self.settings, event)
|
|
|
|
def postboot_channelset(self, event):
|
|
|
|
self._postboot_set(self.channel_settings, event)
|
|
|
|
|
2016-03-31 12:37:08 +00:00
|
|
|
def _set(self, settings, event):
|
2016-03-29 11:56:58 +00:00
|
|
|
if len(event["args_split"]) > 1:
|
|
|
|
setting = event["args_split"][0].lower()
|
|
|
|
if setting in settings:
|
|
|
|
value = " ".join(event["args_split"][1:])
|
|
|
|
value = settings[setting]["validate"](value)
|
|
|
|
if not value == None:
|
2016-03-31 12:37:08 +00:00
|
|
|
event["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" % (
|
|
|
|
", ".join(settings.keys())))
|
|
|
|
def set(self, event):
|
|
|
|
self._set(self.settings, event["user"], event)
|
|
|
|
|
|
|
|
def channel_set(self, event):
|
2016-03-31 12:37:08 +00:00
|
|
|
if event["target"].mode_or_above(event["user"].nickname,
|
2016-03-29 11:56:58 +00:00
|
|
|
"o"):
|
2016-03-31 12:37:08 +00:00
|
|
|
self._set(self.channel_settings, event)
|
2016-03-29 11:56:58 +00:00
|
|
|
else:
|
|
|
|
event["stderr"].write("You do not have the modes required")
|