From 3be514ffdc984eea602e2a5a496111d53d681f43 Mon Sep 17 00:00:00 2001 From: Griatch Date: Thu, 22 Oct 2009 20:59:19 +0000 Subject: [PATCH] Added high/low dbref limits to @find (Issue 59). /Griatch --- src/commands/objmanip.py | 48 ++++++++++++++++++++++++++-------------- src/objects/models.py | 20 ++++++++++++++--- src/session.py | 6 ++--- 3 files changed, 51 insertions(+), 23 deletions(-) diff --git a/src/commands/objmanip.py b/src/commands/objmanip.py index 36556cdd86..c47a23f39f 100644 --- a/src/commands/objmanip.py +++ b/src/commands/objmanip.py @@ -451,31 +451,45 @@ def cmd_find(command): find Usage: - find + find [,low_dbref[,high_dbref]] Searches for an object of a particular name. """ source_object = command.source_object can_find = source_object.has_perm("genperms.builder") - - if not command.command_argument: - source_object.emit_to("Usage: @find ") + args = command.command_argument + if not args: + source_object.emit_to("Usage: @find [,low [,high]]") return - - searchstring = command.command_argument - results = Object.objects.global_object_name_search(searchstring) - - if len(results) > 0: - source_object.emit_to("Name matches for: %s" % (searchstring,)) - s = "" - for result in results: - s += " %s\n\r" % (result.get_name(fullname=True),) - s += "%d matches returned." % (len(results),) - source_object.emit_to(s) + lowlim = None + highlim = None + args = args.split(",",2) + if len(args) < 2: + searchstring = args[0].strip() + elif len(args) == 2: + # we have only the low dbref given + searchstring, lowlim = [arg.strip() for arg in args] else: - source_object.emit_to("No name matches found for: %s" % (searchstring,)) + # we have all input given + searchstring, lowlim, highlim = [arg.strip() for arg in args] + results = source_object.search_for_object_global(searchstring, exact_match=False, + dbref_limits=(lowlim, highlim)) + if not results: + return + source_object.emit_to("Name match: %s" % results) + + ## if len(results) > 0: + ## source_object.emit_to("Name matches for: %s" % (searchstring,)) + ## s = "" + ## for result in results: + ## s += " %s\n\r" % (result.get_name(fullname=True),) + ## s += "%d matches returned." % (len(results),) + ## source_object.emit_to(s) + ## else: + ## source_object.emit_to("No name matches found for: %s" % (searchstring,)) GLOBAL_CMD_TABLE.add_command("@find", cmd_find, - priv_tuple=("objects.info",), help_category="Building") + priv_tuple=("objects.info",), help_category="Building", + auto_help_override=False) def cmd_create(command): """ diff --git a/src/objects/models.py b/src/objects/models.py index b54b60ab91..a7f7de3821 100755 --- a/src/objects/models.py +++ b/src/objects/models.py @@ -222,7 +222,7 @@ class Object(models.Model): return results[0] def search_for_object_global(self, ostring, exact_match=True, limit_types=[], - emit_to_obj=None): + emit_to_obj=None, dbref_limits=()): """ Search for ostring in all objects, globally. Handle multiple-matches and no matches gracefully. This is mainly intended to be used by @@ -234,15 +234,29 @@ class Object(models.Model): results = Object.objects.global_object_name_search(ostring, exact_match=exact_match, limit_types=limit_types) + if dbref_limits: + # if this is set we expect a tuple of 2, even if one is None. + try: + if dbref_limits[0]: + results = [result for result in results + if result.id >= int(dbref_limits[0].strip('#'))] + if dbref_limits[1]: + results = [result for result in results + if result.id <= int(dbref_limits[1].strip("#"))] + except KeyError: + pass + if not results: emit_to_obj.emit_to("No matches found for '%s'." % ostring) - return + return + if len(results) > 1: - string = "More than one match for '%s' (please narrow target):" % ostring + string = "Multiple matches for '%s':" % ostring for res in results: string += "\n %s" % res.get_name() emit_to_obj.emit_to(string) return + return results[0] diff --git a/src/session.py b/src/session.py index 84beb7e32e..0c14063ea5 100755 --- a/src/session.py +++ b/src/session.py @@ -79,11 +79,11 @@ class SessionProtocol(StatefulTelnetProtocol): the user input and pass it to this session's pobject. """ try: - data = u"%s" % data + test = u"%s" % data except UnicodeDecodeError: - self.msg("Couldn't parse that. You put some non-standard characters in there.") + self.msg("Couldn't parse that - one or more characters were not recognized.") return - + if self.pobject: # Session is logged in, run through the normal object execution. self.pobject.execute_cmd(data, session=self)