Fixed a bug and cleaned up the nick command. Resolves #756.

This commit is contained in:
Griatch 2015-06-09 14:34:27 +02:00
parent 9c677362e7
commit 7f8d421039

View file

@ -88,7 +88,7 @@ class CmdNick(MuxCommand):
define a personal alias/nick define a personal alias/nick
Usage: Usage:
nick[/switches] <nickname> = [<string>] nick[/switches] <nickname> [= [<string>]]
alias '' alias ''
Switches: Switches:
@ -100,6 +100,8 @@ class CmdNick(MuxCommand):
Examples: Examples:
nick hi = say Hello, I'm Sarah! nick hi = say Hello, I'm Sarah!
nick/object tom = the tall man nick/object tom = the tall man
nick hi (shows the nick substitution)
nick hi = (removes nick 'hi')
A 'nick' is a personal shortcut you create for your own use. When A 'nick' is a personal shortcut you create for your own use. When
you enter the nick, the alternative string will be sent instead. you enter the nick, the alternative string will be sent instead.
@ -126,12 +128,15 @@ class CmdNick(MuxCommand):
nicks = caller.nicks.get(return_obj=True) nicks = caller.nicks.get(return_obj=True)
if 'list' in switches: if 'list' in switches:
table = prettytable.PrettyTable(["{wNickType", if not nicks:
"{wNickname", string = "{wNo nicks defined.{n"
"{wTranslates-to"]) else:
for nick in utils.make_iter(nicks): table = prettytable.PrettyTable(["{wNickType",
table.add_row([nick.db_category, nick.db_key, nick.db_strvalue]) "{wNickname",
string = "{wDefined Nicks:{n\n%s" % table "{wTranslates-to"])
for nick in utils.make_iter(nicks):
table.add_row([nick.db_category, nick.db_key, nick.db_strvalue])
string = "{wDefined Nicks:{n\n%s" % table
caller.msg(string) caller.msg(string)
return return
if 'clearall' in switches: if 'clearall' in switches:
@ -155,19 +160,22 @@ class CmdNick(MuxCommand):
for switch in switches: for switch in switches:
oldnick = caller.nicks.get(key=nick, category=switch) oldnick = caller.nicks.get(key=nick, category=switch)
if not real: if not real:
# removal of nick if "=" in self.args:
if oldnick: if oldnick:
# clear the alias # clear the alias
string += "\nNick '%s' (= '%s') was cleared." % (nick, oldnick) string += "\nNick cleared: '{w%s{n' (-> '{w%s{n')." % (nick, oldnick)
caller.nicks.delete(nick, category=switch) caller.nicks.remove(nick, category=switch)
else:
string += "\nNo nick '%s' found, so it could not be removed." % nick
else: else:
string += "\nNo nick '%s' found, so it could not be removed." % nick string += "\nNick: '{w%s{n'{n -> '{w%s{n'." % (nick, oldnick)
else: else:
# creating new nick # creating new nick
if oldnick: if oldnick:
string += "\nNick %s changed from '%s' to '%s'." % (nick, oldnick, real) string += "\nNick '{w%s{n' reset from '{w%s{n' to '{w%s{n'." % (nick, oldnick, real)
else: else:
string += "\nNick set: '%s' = '%s'." % (nick, real) string += "\nNick set: '{w%s{n' -> '{w%s{n'." % (nick, real)
caller.nicks.add(nick, real, category=switch) caller.nicks.add(nick, real, category=switch)
caller.msg(string) caller.msg(string)