Update nicks to properly handle account-nicks in e.g. pages
This commit is contained in:
parent
c7cfca2785
commit
728f933d6d
2 changed files with 19 additions and 6 deletions
|
|
@ -457,7 +457,7 @@ class DefaultAccount(with_metaclass(TypeclassBase, AccountDB)):
|
||||||
callertype="account", session=session, **kwargs)
|
callertype="account", session=session, **kwargs)
|
||||||
|
|
||||||
def search(self, searchdata, return_puppet=False, search_object=False,
|
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
|
This is similar to `DefaultObject.search` but defaults to searching
|
||||||
for Accounts only.
|
for Accounts only.
|
||||||
|
|
@ -481,6 +481,7 @@ class DefaultAccount(with_metaclass(TypeclassBase, AccountDB)):
|
||||||
multimatch_string (str, optional): A one-time error
|
multimatch_string (str, optional): A one-time error
|
||||||
message to echo if `searchdata` leads to multiple matches.
|
message to echo if `searchdata` leads to multiple matches.
|
||||||
If not given, will fall back to the default handler.
|
If not given, will fall back to the default handler.
|
||||||
|
use_nicks (bool, optional): Use account-level nick replacement.
|
||||||
|
|
||||||
Return:
|
Return:
|
||||||
match (Account, Object or None): A single Account or Object match.
|
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",):
|
if searchdata.lower() in ("me", "*me", "self", "*self",):
|
||||||
return self
|
return self
|
||||||
if search_object:
|
if search_object:
|
||||||
matches = ObjectDB.objects.object_search(searchdata, typeclass=typeclass)
|
matches = ObjectDB.objects.object_search(searchdata, typeclass=typeclass, use_nicks=use_nicks)
|
||||||
else:
|
else:
|
||||||
|
searchdata = self.nicks.nickreplace(searchdata, categories=("account", ), include_account=False)
|
||||||
|
|
||||||
matches = AccountDB.objects.account_search(searchdata, typeclass=typeclass)
|
matches = AccountDB.objects.account_search(searchdata, typeclass=typeclass)
|
||||||
matches = _AT_SEARCH_RESULT(matches, self, query=searchdata,
|
matches = _AT_SEARCH_RESULT(matches, self, query=searchdata,
|
||||||
nofound_string=nofound_string,
|
nofound_string=nofound_string,
|
||||||
|
|
|
||||||
|
|
@ -143,13 +143,14 @@ class CmdNick(COMMAND_DEFAULT_CLASS):
|
||||||
return re.sub(r"(\$[0-9]+|\*|\?|\[.+?\])", r"|Y\1|n", string)
|
return re.sub(r"(\$[0-9]+|\*|\?|\[.+?\])", r"|Y\1|n", string)
|
||||||
|
|
||||||
caller = self.caller
|
caller = self.caller
|
||||||
|
account = self.caller.account or caller
|
||||||
switches = self.switches
|
switches = self.switches
|
||||||
nicktypes = [switch for switch in switches if switch in (
|
nicktypes = [switch for switch in switches if switch in (
|
||||||
"object", "account", "inputline")] or ["inputline"]
|
"object", "account", "inputline")] or ["inputline"]
|
||||||
|
|
||||||
nicklist = (utils.make_iter(caller.nicks.get(category="inputline", return_obj=True) or []) +
|
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="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"):
|
if 'list' in switches or self.cmdstring in ("nicks", "@nicks"):
|
||||||
|
|
||||||
|
|
@ -166,6 +167,7 @@ class CmdNick(COMMAND_DEFAULT_CLASS):
|
||||||
|
|
||||||
if 'clearall' in switches:
|
if 'clearall' in switches:
|
||||||
caller.nicks.clear()
|
caller.nicks.clear()
|
||||||
|
caller.account.nicks.clear()
|
||||||
caller.msg("Cleared all nicks.")
|
caller.msg("Cleared all nicks.")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
@ -187,7 +189,10 @@ class CmdNick(COMMAND_DEFAULT_CLASS):
|
||||||
nicktype = oldnick.category
|
nicktype = oldnick.category
|
||||||
nicktypestr = "%s-nick" % nicktype.capitalize()
|
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." % (
|
caller.msg("%s removed: '|w%s|n' -> |w%s|n." % (
|
||||||
nicktypestr, old_nickstring, old_replstring))
|
nicktypestr, old_nickstring, old_replstring))
|
||||||
return
|
return
|
||||||
|
|
@ -209,11 +214,16 @@ class CmdNick(COMMAND_DEFAULT_CLASS):
|
||||||
errstring = ""
|
errstring = ""
|
||||||
string = ""
|
string = ""
|
||||||
for nicktype in nicktypes:
|
for nicktype in nicktypes:
|
||||||
|
if nicktype == "account":
|
||||||
|
obj = account
|
||||||
|
else:
|
||||||
|
obj = caller
|
||||||
|
|
||||||
nicktypestr = "%s-nick" % nicktype.capitalize()
|
nicktypestr = "%s-nick" % nicktype.capitalize()
|
||||||
old_nickstring = None
|
old_nickstring = None
|
||||||
old_replstring = 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:
|
if oldnick:
|
||||||
_, _, old_nickstring, old_replstring = oldnick.value
|
_, _, old_nickstring, old_replstring = oldnick.value
|
||||||
if replstring:
|
if replstring:
|
||||||
|
|
@ -228,7 +238,7 @@ class CmdNick(COMMAND_DEFAULT_CLASS):
|
||||||
else:
|
else:
|
||||||
string += "\n%s '|w%s|n' mapped to '|w%s|n'." % (nicktypestr, nickstring, replstring)
|
string += "\n%s '|w%s|n' mapped to '|w%s|n'." % (nicktypestr, nickstring, replstring)
|
||||||
try:
|
try:
|
||||||
caller.nicks.add(nickstring, replstring, category=nicktype)
|
obj.nicks.add(nickstring, replstring, category=nicktype)
|
||||||
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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue