Added high/low dbref limits to @find (Issue 59).

/Griatch
This commit is contained in:
Griatch 2009-10-22 20:59:19 +00:00
parent 3614960471
commit 3be514ffdc
3 changed files with 51 additions and 23 deletions

View file

@ -451,31 +451,45 @@ def cmd_find(command):
find
Usage:
find <searchname>
find <searchname> [,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 <name>")
args = command.command_argument
if not args:
source_object.emit_to("Usage: @find <name> [,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):
"""

View file

@ -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]

View file

@ -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)