From 7e7cd9211feafaaaeaa142cd7f4245afcc623214 Mon Sep 17 00:00:00 2001 From: Ahmed Charles Date: Tue, 10 Feb 2015 17:17:04 +0000 Subject: [PATCH] Add custom error messages to search and have drop use them. --- evennia/commands/default/general.py | 13 +++++-------- evennia/objects/objects.py | 8 ++++++-- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/evennia/commands/default/general.py b/evennia/commands/default/general.py index 99a06243be..a7b885ee68 100644 --- a/evennia/commands/default/general.py +++ b/evennia/commands/default/general.py @@ -266,6 +266,7 @@ class CmdDrop(MuxCommand): key = "drop" locks = "cmd:all()" + arg_regex = r"\s|$" def func(self): "Implement command" @@ -277,13 +278,9 @@ class CmdDrop(MuxCommand): # Because the DROP command by definition looks for items # in inventory, call the search function using location = caller - results = caller.search(self.args, location=caller, quiet=True) - - # now we send it into the error handler (this will output consistent - # error messages if there are problems). - obj = AT_SEARCH_RESULT(caller, self.args, results, False, - nofound_string="You aren't carrying %s." % self.args, - multimatch_string="You carry more than one %s:" % self.args) + obj = caller.search(self.args, location=caller, + nofound_string="You aren't carrying %s." % self.args, + multimatch_string="You carry more than one %s:" % self.args) if not obj: return @@ -291,7 +288,7 @@ class CmdDrop(MuxCommand): caller.msg("You drop %s." % (obj.name,)) caller.location.msg_contents("%s drops %s." % (caller.name, obj.name), - exclude=caller) + exclude=caller) # Call the object script's at_drop() method. obj.at_drop(caller) diff --git a/evennia/objects/objects.py b/evennia/objects/objects.py index 54f121fd97..e8c577a3bb 100644 --- a/evennia/objects/objects.py +++ b/evennia/objects/objects.py @@ -317,7 +317,9 @@ class DefaultObject(ObjectDB): attribute_name=None, quiet=False, exact=False, - candidates=None): + candidates=None, + nofound_string=None, + multimatch_string=None): """ Returns the typeclass of an Object matching a search string/condition @@ -367,6 +369,8 @@ class DefaultObject(ObjectDB): is given. If not set, this list will automatically be defined to include the location, the contents of location and the caller's contents (inventory). + nofound_string - optional custom string for not-found error message. + multimatch_string - optional custom string for multimatch error header Returns: quiet=False (default): @@ -425,7 +429,7 @@ class DefaultObject(ObjectDB): exact=exact) if quiet: return results - return _AT_SEARCH_RESULT(self, searchdata, results, global_search) + return _AT_SEARCH_RESULT(self, searchdata, results, global_search, nofound_string, multimatch_string) def search_player(self, searchdata, quiet=False): """