Add functioning prefix-ignorer and cleanup of code.

This commit is contained in:
Griatch 2017-02-17 08:40:32 +01:00
parent d4df0948e3
commit 1fbb4c4358
7 changed files with 10 additions and 15 deletions

View file

@ -549,6 +549,8 @@ def cmdhandler(called_by, raw_string, _testing=False, callertype="session", sess
if not cmdset:
# this is bad and shouldn't happen.
raise NoCmdSets
# store the completely unmodified raw string - including
# whitespace and eventual prefixes-to-be-stripped.
unformatted_raw_string = raw_string
raw_string = raw_string.strip()
if not raw_string:

View file

@ -120,17 +120,10 @@ def cmdparser(raw_string, cmdset, caller, match_index=None):
mindex, new_raw_string = try_num_prefixes(raw_string)
if mindex is not None:
return cmdparser(new_raw_string, cmdset, caller, match_index=int(mindex))
elif _CMD_IGNORE_PREFIXES:
if _CMD_IGNORE_PREFIXES:
# still no match. Try to strip prefixes
new_raw_string = raw_string.lstrip(_CMD_IGNORE_PREFIXES) if len(raw_string) > 1 else raw_string
if len(new_raw_string) < len(raw_string):
raw_string = new_raw_string
matches = build_matches(raw_string, include_prefixes=False)
if not matches:
# try to match a number 1-cmdname, 2-cmdname etc
mindex, new_raw_string = try_num_prefixes(raw_string)
if mindex is not None:
return cmdparser(new_raw_string, cmdset, caller, match_index=int(mindex))
raw_string = raw_string.lstrip(_CMD_IGNORE_PREFIXES) if len(raw_string) > 1 else raw_string
matches = build_matches(raw_string, include_prefixes=False)
# only select command matches we are actually allowed to call.
matches = [match for match in matches if match[2].access(caller, 'cmd')]

View file

@ -63,7 +63,7 @@ class CharacterCmdSet(CmdSet):
self.add(building.CmdWipe())
self.add(building.CmdSetAttribute())
self.add(building.CmdName())
self.add(building.CmdDesc())
self.add(building.CmdSetDesc())
self.add(building.CmdCpAttr())
self.add(building.CmdMvAttr())
self.add(building.CmdCopy())

View file

@ -367,7 +367,7 @@ class CmdDesc(COMMAND_DEFAULT_CLASS):
will be visible to people when they
look at you.
"""
key = "setdesc"
key = "desc"
locks = "cmd:all()"
arg_regex = r"\s|$"

View file

@ -229,7 +229,7 @@ class TestBuilding(CommandTest):
self.call(building.CmdName(), "Obj2=Obj3", "Object's name changed to 'Obj3'.")
def test_desc(self):
self.call(building.CmdDesc(), "Obj2=TestDesc", "The description was set on Obj2(#5).")
self.call(building.CmdSetDesc(), "Obj2=TestDesc", "The description was set on Obj2(#5).")
def test_wipe(self):
self.call(building.CmdDestroy(), "Obj", "Obj was destroyed.")

View file

@ -375,7 +375,7 @@ class CmdExtendedDesc(default_cmds.CmdDesc):
"Define extended command"
caller = self.caller
location = caller.location
if self.cmdstring == '@detail':
if self.cmdname == 'detail':
# switch to detailing mode. This operates only on current location
if not location:
caller.msg("No location to detail!")

View file

@ -280,7 +280,7 @@ SEARCH_MULTIMATCH_TEMPLATE = " {number}-{name}{aliases}{info}\n"
# over the error output (it uses SEARCH_MULTIMATCH_TEMPLATE by default).
SEARCH_AT_RESULT = "evennia.utils.utils.at_search_result"
# Single characters to ignore at the beginning of a command. When set, e.g.
# cmd, @cmd and +cmd will all find a command "cmd" or one named "@cmd". If
# cmd, @cmd and +cmd will all find a command "cmd" or one named "@cmd" etc. If
# you have defined two different commands cmd and @cmd you can still enter
# @cmd to exactly target the second one. Single-character commands consisting
# of only a prefix character will not be stripped. Set to the empty