Update nicks to properly handle account-nicks in e.g. pages

This commit is contained in:
Griatch 2018-01-09 20:38:06 +01:00
parent 39d1426946
commit 986ca75fe9
2 changed files with 19 additions and 6 deletions

View file

@ -457,7 +457,7 @@ class DefaultAccount(with_metaclass(TypeclassBase, AccountDB)):
callertype="account", session=session, **kwargs)
def search(self, searchdata, return_puppet=False, search_object=False,
typeclass=None, nofound_string=None, multimatch_string=None, **kwargs):
typeclass=None, nofound_string=None, multimatch_string=None, use_nicks=True, **kwargs):
"""
This is similar to `DefaultObject.search` but defaults to searching
for Accounts only.
@ -481,6 +481,7 @@ class DefaultAccount(with_metaclass(TypeclassBase, AccountDB)):
multimatch_string (str, optional): A one-time error
message to echo if `searchdata` leads to multiple matches.
If not given, will fall back to the default handler.
use_nicks (bool, optional): Use account-level nick replacement.
Return:
match (Account, Object or None): A single Account or Object match.
@ -496,8 +497,10 @@ class DefaultAccount(with_metaclass(TypeclassBase, AccountDB)):
if searchdata.lower() in ("me", "*me", "self", "*self",):
return self
if search_object:
matches = ObjectDB.objects.object_search(searchdata, typeclass=typeclass)
matches = ObjectDB.objects.object_search(searchdata, typeclass=typeclass, use_nicks=use_nicks)
else:
searchdata = self.nicks.nickreplace(searchdata, categories=("account", ), include_account=False)
matches = AccountDB.objects.account_search(searchdata, typeclass=typeclass)
matches = _AT_SEARCH_RESULT(matches, self, query=searchdata,
nofound_string=nofound_string,

View file

@ -143,13 +143,14 @@ class CmdNick(COMMAND_DEFAULT_CLASS):
return re.sub(r"(\$[0-9]+|\*|\?|\[.+?\])", r"|Y\1|n", string)
caller = self.caller
account = self.caller.account or caller
switches = self.switches
nicktypes = [switch for switch in switches if switch in (
"object", "account", "inputline")] or ["inputline"]
nicklist = (utils.make_iter(caller.nicks.get(category="inputline", return_obj=True) or []) +
utils.make_iter(caller.nicks.get(category="object", return_obj=True) or []) +
utils.make_iter(caller.nicks.get(category="account", return_obj=True) or []))
utils.make_iter(account.nicks.get(category="account", return_obj=True) or []))
if 'list' in switches or self.cmdstring in ("nicks", "@nicks"):
@ -166,6 +167,7 @@ class CmdNick(COMMAND_DEFAULT_CLASS):
if 'clearall' in switches:
caller.nicks.clear()
caller.account.nicks.clear()
caller.msg("Cleared all nicks.")
return
@ -187,7 +189,10 @@ class CmdNick(COMMAND_DEFAULT_CLASS):
nicktype = oldnick.category
nicktypestr = "%s-nick" % nicktype.capitalize()
caller.nicks.remove(old_nickstring, category=nicktype)
if nicktype == "account":
account.nicks.remove(old_nickstring, category=nicktype)
else:
caller.nicks.remove(old_nickstring, category=nicktype)
caller.msg("%s removed: '|w%s|n' -> |w%s|n." % (
nicktypestr, old_nickstring, old_replstring))
return
@ -209,11 +214,16 @@ class CmdNick(COMMAND_DEFAULT_CLASS):
errstring = ""
string = ""
for nicktype in nicktypes:
if nicktype == "account":
obj = account
else:
obj = caller
nicktypestr = "%s-nick" % nicktype.capitalize()
old_nickstring = None
old_replstring = None
oldnick = caller.nicks.get(key=nickstring, category=nicktype, return_obj=True)
oldnick = obj.nicks.get(key=nickstring, category=nicktype, return_obj=True)
if oldnick:
_, _, old_nickstring, old_replstring = oldnick.value
if replstring:
@ -228,7 +238,7 @@ class CmdNick(COMMAND_DEFAULT_CLASS):
else:
string += "\n%s '|w%s|n' mapped to '|w%s|n'." % (nicktypestr, nickstring, replstring)
try:
caller.nicks.add(nickstring, replstring, category=nicktype)
obj.nicks.add(nickstring, replstring, category=nicktype)
except NickTemplateInvalid:
caller.msg("You must use the same $-markers both in the nick and in the replacement.")
return