Fix some more problems with the nick command.

This commit is contained in:
Griatch 2016-06-26 09:36:45 +02:00
parent 7f82049e33
commit 0bc13df712

View file

@ -111,7 +111,7 @@ class CmdNick(COMMAND_DEFAULT_CLASS):
""" """
key = "nick" key = "nick"
aliases = ["nickname", "nicks", "@nick", "alias"] aliases = ["nickname", "nicks", "@nick", "@nicks", "alias"]
locks = "cmd:all()" locks = "cmd:all()"
def func(self): def func(self):
@ -123,7 +123,7 @@ class CmdNick(COMMAND_DEFAULT_CLASS):
nicklist = utils.make_iter(caller.nicks.get(return_obj=True) or []) nicklist = utils.make_iter(caller.nicks.get(return_obj=True) or [])
if 'list' in switches: if 'list' in switches or self.cmdstring in ("nicks", "@nicks"):
if not nicklist: if not nicklist:
string = "{wNo nicks defined.{n" string = "{wNo nicks defined.{n"
@ -147,41 +147,45 @@ class CmdNick(COMMAND_DEFAULT_CLASS):
nickstring = self.lhs nickstring = self.lhs
replstring = self.rhs replstring = self.rhs
old_nickstring = None
old_replstring = None
if replstring == nickstring: if replstring == nickstring:
caller.msg("No point in setting nick same as the string to replace...") caller.msg("No point in setting nick same as the string to replace...")
return return
# check so we have a suitable nick type # check so we have a suitable nick type
errstring = ""
string = "" string = ""
for nicktype in nicktypes: for nicktype in nicktypes:
oldnick = caller.nicks.get(key=nickstring, category=nicktype, return_obj=True) oldnick = caller.nicks.get(key=nickstring, category=nicktype, return_obj=True)
oldnick = oldnick if oldnick.key is not None else None oldnick = oldnick if oldnick.key is not None else None
if "delete" in switches or "del" in switches: if oldnick:
if oldnick: _, _, old_nickstring, old_replstring = oldnick.value
_, _, nickstring, replstring = oldnick.value else:
else: # no old nick, see if a number was given
# no old nick, see if a number was given if self.args.isdigit():
if self.args.isdigit(): # we are given a index in nicklist
# we are given a index in nicklist delindex = int(self.args)
delindex = int(self.args) if 0 < delindex <= len(nicklist):
if 0 < delindex <= len(nicklist): oldnick = nicklist[delindex-1]
oldnick = nicklist[delindex-1] _, _, old_nickstring, old_replstring = oldnick.value
_, _, nickstring, replstring = oldnick.value
else:
caller.msg("Not a valid nick index.")
return
else: else:
caller.msg("Nick not found.") errstring += "Not a valid nick index."
return else:
errstring += "Nick not found."
if "delete" in switches or "del" in switches:
# clear the nick # clear the nick
string += "\nNick removed: '|w%s|n' -> |w%s|n." % (nickstring, replstring) errstring = ""
string += "\nNick removed: '|w%s|n' -> |w%s|n." % (old_nickstring, old_replstring)
caller.nicks.remove(nickstring, category=nicktype) caller.nicks.remove(nickstring, category=nicktype)
elif replstring: elif replstring:
# creating new nick # creating new nick
errstring = ""
if oldnick: if oldnick:
string += "\nNick '{w%s{n' updated to map to '{w%s{n'." % (nickstring, replstring) string += "\nNick '{w%s{n' updated to map to '{w%s{n'." % (old_nickstring, replstring)
else: else:
string += "\nNick '{w%s{n' mapped to '{w%s{n'." % (nickstring, replstring) string += "\nNick '{w%s{n' mapped to '{w%s{n'." % (nickstring, replstring)
try: try:
@ -189,9 +193,11 @@ class CmdNick(COMMAND_DEFAULT_CLASS):
except NickTemplateInvalid: except NickTemplateInvalid:
caller.msg("You must use the same $-markers both in the nick and in the replacement.") caller.msg("You must use the same $-markers both in the nick and in the replacement.")
return return
else: elif old_nickstring and old_replstring:
# just looking at the nick # just looking at the nick
string += "\nNick: '{w%s{n'{n -> '{w%s{n'." % (nickstring, oldnick.key) string += "\nNick '{w%s{n' maps to '{w%s{n'." % (old_nickstring, old_replstring)
errstring = ""
string = errstring if errstring else string
caller.msg(string) caller.msg(string)