From 1fbb4c4358adc06e27230732472dffb6a62b3994 Mon Sep 17 00:00:00 2001 From: Griatch Date: Fri, 17 Feb 2017 08:40:32 +0100 Subject: [PATCH] Add functioning prefix-ignorer and cleanup of code. --- evennia/commands/cmdhandler.py | 2 ++ evennia/commands/cmdparser.py | 13 +++---------- evennia/commands/default/cmdset_character.py | 2 +- evennia/commands/default/general.py | 2 +- evennia/commands/default/tests.py | 2 +- evennia/contrib/extended_room.py | 2 +- evennia/settings_default.py | 2 +- 7 files changed, 10 insertions(+), 15 deletions(-) diff --git a/evennia/commands/cmdhandler.py b/evennia/commands/cmdhandler.py index 85f52c13dd..36a73078bd 100644 --- a/evennia/commands/cmdhandler.py +++ b/evennia/commands/cmdhandler.py @@ -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: diff --git a/evennia/commands/cmdparser.py b/evennia/commands/cmdparser.py index 22de701576..6cb9ee0143 100644 --- a/evennia/commands/cmdparser.py +++ b/evennia/commands/cmdparser.py @@ -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')] diff --git a/evennia/commands/default/cmdset_character.py b/evennia/commands/default/cmdset_character.py index a8216db73b..f695cc6762 100644 --- a/evennia/commands/default/cmdset_character.py +++ b/evennia/commands/default/cmdset_character.py @@ -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()) diff --git a/evennia/commands/default/general.py b/evennia/commands/default/general.py index 3bc4337ecf..a4afbf961e 100644 --- a/evennia/commands/default/general.py +++ b/evennia/commands/default/general.py @@ -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|$" diff --git a/evennia/commands/default/tests.py b/evennia/commands/default/tests.py index c61304710a..ee0409e06d 100644 --- a/evennia/commands/default/tests.py +++ b/evennia/commands/default/tests.py @@ -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.") diff --git a/evennia/contrib/extended_room.py b/evennia/contrib/extended_room.py index 6bc8ccecbc..791babf73e 100644 --- a/evennia/contrib/extended_room.py +++ b/evennia/contrib/extended_room.py @@ -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!") diff --git a/evennia/settings_default.py b/evennia/settings_default.py index 743e345670..39a6165228 100644 --- a/evennia/settings_default.py +++ b/evennia/settings_default.py @@ -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