Added high/low dbref limits to @find (Issue 59).
/Griatch
This commit is contained in:
parent
3614960471
commit
3be514ffdc
3 changed files with 51 additions and 23 deletions
|
|
@ -451,31 +451,45 @@ def cmd_find(command):
|
||||||
find
|
find
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
find <searchname>
|
find <searchname> [,low_dbref[,high_dbref]]
|
||||||
|
|
||||||
Searches for an object of a particular name.
|
Searches for an object of a particular name.
|
||||||
"""
|
"""
|
||||||
source_object = command.source_object
|
source_object = command.source_object
|
||||||
can_find = source_object.has_perm("genperms.builder")
|
can_find = source_object.has_perm("genperms.builder")
|
||||||
|
args = command.command_argument
|
||||||
if not command.command_argument:
|
if not args:
|
||||||
source_object.emit_to("Usage: @find <name>")
|
source_object.emit_to("Usage: @find <name> [,low [,high]]")
|
||||||
return
|
return
|
||||||
|
lowlim = None
|
||||||
searchstring = command.command_argument
|
highlim = None
|
||||||
results = Object.objects.global_object_name_search(searchstring)
|
args = args.split(",",2)
|
||||||
|
if len(args) < 2:
|
||||||
if len(results) > 0:
|
searchstring = args[0].strip()
|
||||||
source_object.emit_to("Name matches for: %s" % (searchstring,))
|
elif len(args) == 2:
|
||||||
s = ""
|
# we have only the low dbref given
|
||||||
for result in results:
|
searchstring, lowlim = [arg.strip() for arg in args]
|
||||||
s += " %s\n\r" % (result.get_name(fullname=True),)
|
|
||||||
s += "%d matches returned." % (len(results),)
|
|
||||||
source_object.emit_to(s)
|
|
||||||
else:
|
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,
|
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):
|
def cmd_create(command):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -222,7 +222,7 @@ class Object(models.Model):
|
||||||
return results[0]
|
return results[0]
|
||||||
|
|
||||||
def search_for_object_global(self, ostring, exact_match=True, limit_types=[],
|
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
|
Search for ostring in all objects, globally. Handle multiple-matches
|
||||||
and no matches gracefully. This is mainly intended to be used by
|
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,
|
results = Object.objects.global_object_name_search(ostring, exact_match=exact_match,
|
||||||
limit_types=limit_types)
|
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:
|
if not results:
|
||||||
emit_to_obj.emit_to("No matches found for '%s'." % ostring)
|
emit_to_obj.emit_to("No matches found for '%s'." % ostring)
|
||||||
return
|
return
|
||||||
|
|
||||||
if len(results) > 1:
|
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:
|
for res in results:
|
||||||
string += "\n %s" % res.get_name()
|
string += "\n %s" % res.get_name()
|
||||||
emit_to_obj.emit_to(string)
|
emit_to_obj.emit_to(string)
|
||||||
return
|
return
|
||||||
|
|
||||||
return results[0]
|
return results[0]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -79,9 +79,9 @@ class SessionProtocol(StatefulTelnetProtocol):
|
||||||
the user input and pass it to this session's pobject.
|
the user input and pass it to this session's pobject.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
data = u"%s" % data
|
test = u"%s" % data
|
||||||
except UnicodeDecodeError:
|
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
|
return
|
||||||
|
|
||||||
if self.pobject:
|
if self.pobject:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue