Add functioning prefix-ignorer and cleanup of code.
This commit is contained in:
parent
d4df0948e3
commit
1fbb4c4358
7 changed files with 10 additions and 15 deletions
|
|
@ -549,6 +549,8 @@ def cmdhandler(called_by, raw_string, _testing=False, callertype="session", sess
|
||||||
if not cmdset:
|
if not cmdset:
|
||||||
# this is bad and shouldn't happen.
|
# this is bad and shouldn't happen.
|
||||||
raise NoCmdSets
|
raise NoCmdSets
|
||||||
|
# store the completely unmodified raw string - including
|
||||||
|
# whitespace and eventual prefixes-to-be-stripped.
|
||||||
unformatted_raw_string = raw_string
|
unformatted_raw_string = raw_string
|
||||||
raw_string = raw_string.strip()
|
raw_string = raw_string.strip()
|
||||||
if not raw_string:
|
if not raw_string:
|
||||||
|
|
|
||||||
|
|
@ -120,17 +120,10 @@ def cmdparser(raw_string, cmdset, caller, match_index=None):
|
||||||
mindex, new_raw_string = try_num_prefixes(raw_string)
|
mindex, new_raw_string = try_num_prefixes(raw_string)
|
||||||
if mindex is not None:
|
if mindex is not None:
|
||||||
return cmdparser(new_raw_string, cmdset, caller, match_index=int(mindex))
|
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
|
# still no match. Try to strip prefixes
|
||||||
new_raw_string = raw_string.lstrip(_CMD_IGNORE_PREFIXES) if len(raw_string) > 1 else raw_string
|
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)
|
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))
|
|
||||||
|
|
||||||
# only select command matches we are actually allowed to call.
|
# only select command matches we are actually allowed to call.
|
||||||
matches = [match for match in matches if match[2].access(caller, 'cmd')]
|
matches = [match for match in matches if match[2].access(caller, 'cmd')]
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,7 @@ class CharacterCmdSet(CmdSet):
|
||||||
self.add(building.CmdWipe())
|
self.add(building.CmdWipe())
|
||||||
self.add(building.CmdSetAttribute())
|
self.add(building.CmdSetAttribute())
|
||||||
self.add(building.CmdName())
|
self.add(building.CmdName())
|
||||||
self.add(building.CmdDesc())
|
self.add(building.CmdSetDesc())
|
||||||
self.add(building.CmdCpAttr())
|
self.add(building.CmdCpAttr())
|
||||||
self.add(building.CmdMvAttr())
|
self.add(building.CmdMvAttr())
|
||||||
self.add(building.CmdCopy())
|
self.add(building.CmdCopy())
|
||||||
|
|
|
||||||
|
|
@ -367,7 +367,7 @@ class CmdDesc(COMMAND_DEFAULT_CLASS):
|
||||||
will be visible to people when they
|
will be visible to people when they
|
||||||
look at you.
|
look at you.
|
||||||
"""
|
"""
|
||||||
key = "setdesc"
|
key = "desc"
|
||||||
locks = "cmd:all()"
|
locks = "cmd:all()"
|
||||||
arg_regex = r"\s|$"
|
arg_regex = r"\s|$"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -229,7 +229,7 @@ class TestBuilding(CommandTest):
|
||||||
self.call(building.CmdName(), "Obj2=Obj3", "Object's name changed to 'Obj3'.")
|
self.call(building.CmdName(), "Obj2=Obj3", "Object's name changed to 'Obj3'.")
|
||||||
|
|
||||||
def test_desc(self):
|
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):
|
def test_wipe(self):
|
||||||
self.call(building.CmdDestroy(), "Obj", "Obj was destroyed.")
|
self.call(building.CmdDestroy(), "Obj", "Obj was destroyed.")
|
||||||
|
|
|
||||||
|
|
@ -375,7 +375,7 @@ class CmdExtendedDesc(default_cmds.CmdDesc):
|
||||||
"Define extended command"
|
"Define extended command"
|
||||||
caller = self.caller
|
caller = self.caller
|
||||||
location = caller.location
|
location = caller.location
|
||||||
if self.cmdstring == '@detail':
|
if self.cmdname == 'detail':
|
||||||
# switch to detailing mode. This operates only on current location
|
# switch to detailing mode. This operates only on current location
|
||||||
if not location:
|
if not location:
|
||||||
caller.msg("No location to detail!")
|
caller.msg("No location to detail!")
|
||||||
|
|
|
||||||
|
|
@ -280,7 +280,7 @@ SEARCH_MULTIMATCH_TEMPLATE = " {number}-{name}{aliases}{info}\n"
|
||||||
# over the error output (it uses SEARCH_MULTIMATCH_TEMPLATE by default).
|
# over the error output (it uses SEARCH_MULTIMATCH_TEMPLATE by default).
|
||||||
SEARCH_AT_RESULT = "evennia.utils.utils.at_search_result"
|
SEARCH_AT_RESULT = "evennia.utils.utils.at_search_result"
|
||||||
# Single characters to ignore at the beginning of a command. When set, e.g.
|
# 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
|
# you have defined two different commands cmd and @cmd you can still enter
|
||||||
# @cmd to exactly target the second one. Single-character commands consisting
|
# @cmd to exactly target the second one. Single-character commands consisting
|
||||||
# of only a prefix character will not be stripped. Set to the empty
|
# of only a prefix character will not be stripped. Set to the empty
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue