[alias] Dusting module

This commit is contained in:
nemunaire 2015-07-11 00:09:43 +02:00
parent 4d51bc1fda
commit 3c15d35fca

View File

@ -28,10 +28,6 @@ def load(context):
context.data.getNode("variables").setIndex("name") context.data.getNode("variables").setIndex("name")
def help_full():
return "TODO"
def set_variable(name, value, creator): def set_variable(name, value, creator):
var = ModuleState("variable") var = ModuleState("variable")
var["name"] = name var["name"] = name
@ -55,56 +51,58 @@ def get_variable(name, msg=None):
@hook("cmd_hook", "set") @hook("cmd_hook", "set")
def cmd_set(msg): def cmd_set(msg):
if len(msg.cmds) > 2: if len(msg.args) < 2:
set_variable(msg.cmds[1], " ".join(msg.cmds[2:]), msg.nick) raise IRCException("!set prend au minimum deux arguments : "
res = Response("Variable \$%s définie." % msg.cmds[1], "le nom de la variable et sa valeur.")
channel=msg.channel) set_variable(msg.args[0], " ".join(msg.args[1:]), msg.nick)
context.save() context.save()
return res return Response("Variable \$%s définie." % msg.args[0],
return Response("!set prend au minimum deux arguments : "
"le nom de la variable et sa valeur.",
channel=msg.channel) channel=msg.channel)
@hook("cmd_hook", "listalias") @hook("cmd_hook", "listalias")
def cmd_listalias(msg): def cmd_listalias(msg):
if len(msg.cmds) > 1: if len(msg.args):
res = list() res = list()
for user in msg.cmds[1:]: for user in msg.args:
als = [x["alias"] for x in context.data.getNode("aliases").index.values() if x["creator"] == user] als = [x["alias"] for x in context.data.getNode("aliases").index.values() if x["creator"] == user]
if len(als) > 0: if len(als) > 0:
res.append("Alias créés par %s : %s" % (user, ", ".join(als))) res.append("%s's aliases: %s" % (user, ", ".join(als)))
else: else:
res.append("%s n'a pas encore créé d'alias" % user) res.append("%s has never created aliases." % user)
return Response(" ; ".join(res), channel=msg.channel) return Response("; ".join(res), channel=msg.channel)
else: elif len(context.data.getNode("aliases").index):
return Response("Alias connus : %s." % return Response("Known aliases: %s." %
", ".join(context.data.getNode("aliases").index.keys()), ", ".join(context.data.getNode("aliases").index.keys()),
channel=msg.channel) channel=msg.channel)
else:
return Response("There is no alias currently.", channel=msg.channel)
@hook("cmd_hook", "listvars") @hook("cmd_hook", "listvars")
def cmd_listvars(msg): def cmd_listvars(msg):
if len(msg.cmds) > 1: if len(msg.args):
res = list() res = list()
for user in msg.cmds[1:]: for user in msg.args:
als = [x["alias"] for x in context.data.getNode("variables").index.values() if x["creator"] == user] als = [x["alias"] for x in context.data.getNode("variables").index.values() if x["creator"] == user]
if len(als) > 0: if len(als) > 0:
res.append("Variables créées par %s : %s" % (user, ", ".join(als))) res.append("Variables créées par %s : %s" % (user, ", ".join(als)))
else: else:
res.append("%s n'a pas encore créé de variable" % user) res.append("%s n'a pas encore créé de variable" % user)
return Response(" ; ".join(res), channel=msg.channel) return Response(" ; ".join(res), channel=msg.channel)
else: elif len(context.data.getNode("variables").index):
return Response("Variables connues : %s." % return Response("Variables connues : %s." %
", ".join(context.data.getNode("variables").index.keys()), ", ".join(context.data.getNode("variables").index.keys()),
channel=msg.channel) channel=msg.channel)
else:
return Response("No variable are currently stored.", channel=msg.channel)
@hook("cmd_hook", "alias") @hook("cmd_hook", "alias")
def cmd_alias(msg): def cmd_alias(msg):
if len(msg.cmds) > 1: if len(msg.args):
res = list() res = list()
for alias in msg.cmds[1:]: for alias in msg.args:
if alias[0] == "!": if alias[0] == "!":
alias = alias[1:] alias = alias[1:]
if alias in context.data.getNode("aliases").index: if alias in context.data.getNode("aliases").index:
@ -119,9 +117,9 @@ def cmd_alias(msg):
@hook("cmd_hook", "unalias") @hook("cmd_hook", "unalias")
def cmd_unalias(msg): def cmd_unalias(msg):
if len(msg.cmds) > 1: if len(msg.args):
res = list() res = list()
for alias in msg.cmds[1:]: for alias in msg.args:
if alias[0] == "!" and len(alias) > 1: if alias[0] == "!" and len(alias) > 1:
alias = alias[1:] alias = alias[1:]
if alias in context.data.getNode("aliases").index: if alias in context.data.getNode("aliases").index: