Fixed bugs in alias and search system, including properly searching inventory. Expanded @alias command with more functionality.

This commit is contained in:
Griatch 2010-11-09 14:46:39 +00:00
parent 50e66b3813
commit 8aa22fbec8
3 changed files with 39 additions and 22 deletions

View file

@ -109,10 +109,11 @@ class CmdSetObjAlias(MuxCommand):
Adding permanent aliases
Usage:
@alias <obj> = alias[,alias,alias,...]
@alias <obj> = [alias[,alias,alias,...]]
Assigns aliases to an object so it can be referenced by more
than one name. Observe that this is not the same thing as aliases
than one name. Assign empty to remove all aliases from object.
Observe that this is not the same thing as aliases
created with the 'alias' command! Aliases set with @alias are
changing the object in question, making those aliases usable
by everyone.
@ -127,18 +128,33 @@ class CmdSetObjAlias(MuxCommand):
"Set the aliases."
caller = self.caller
objname, aliases = self.lhs, self.rhslist
if not aliases:
if not objname:
caller.msg("Usage: @alias <obj> = <alias>,<alias>,...")
return
return
# Find the object to receive aliases
obj = caller.search(objname, global_search=True)
# Use search to handle duplicate/nonexistant results.
if not obj:
return
if self.rhs == None:
# no =, so we just list aliases on object.
aliases = obj.aliases
if aliases:
caller.msg("Aliases for '%s': %s" % (obj.key, ", ".join(aliases)))
else:
caller.msg("No aliases exist for '%s'." % obj.key)
return
if not has_perm(caller, obj, 'modify_attributes'):
caller.msg("You don't have permission to do that.")
return
if not aliases or not aliases[0]:
# we have given an empty =, so delete aliases
old_aliases = obj.aliases
if old_aliases:
caller.msg("Cleared aliases from %s: %s" % (obj.key, ", ".join(old_aliases)))
del obj.dbobj.aliases # TODO: del does not understand indirect typeclass reference!
else:
caller.msg("No aliases to clear.")
return
# merge the old and new aliases (if any)
old_aliases = obj.aliases
new_aliases = [str(alias).strip().lower()
@ -148,8 +164,7 @@ class CmdSetObjAlias(MuxCommand):
aliases = list(set(old_aliases))
# save back to object.
obj.aliases = aliases
caller.msg("Aliases for '%s' are now set to %s." % (obj.name, aliases))
caller.msg("Aliases for '%s' are now set to %s." % (obj.key, obj.aliases))
class CmdCopy(ObjManipCommand):
"""
@ -875,9 +890,11 @@ class CmdName(ObjManipCommand):
# change the name and set aliases:
if newname:
obj.name = newname
astring = ""
if aliases:
obj.aliases = aliases
caller.msg("Object's name changed to '%s' %s." % (newname, ", ".join(aliases)))
astring = " (%s)" % (", ".join(aliases))
caller.msg("Object's name changed to '%s'%s." % (newname, astring))
class CmdOpen(ObjManipCommand):
@ -1355,11 +1372,9 @@ class CmdExamine(ObjManipCommand):
obj_name = objdef['name']
obj_attrs = objdef['attrs']
obj = caller.search(obj_name)
obj = caller.search(obj_name)
if not obj:
string += "\nObject '%s' not found." % obj_name
continue
continue
if not has_perm(caller, obj, 'obj_info'):
#If we don't have special info access, just look at the object instead.
caller.exec_cmd('look %s' % obj_name)
@ -1370,8 +1385,10 @@ class CmdExamine(ObjManipCommand):
string += self.format_attributes(obj, attrname)
else:
string += self.format_output(obj)
string = string.strip()
# Send it all
caller.msg(string)
if string:
caller.msg(string.strip())
class CmdFind(MuxCommand):

View file

@ -142,7 +142,7 @@ class ObjectManager(TypedObjectManager):
lstring_alias = ", db_obj__db_location=location"
if exact:
estring = "iexact"
matches = eval("self.filter(db_key__%s=ostring%s)" % (estring, lstring_key))
matches = eval("self.filter(db_key__%s=ostring%s)" % (estring, lstring_key))
if not matches:
alias_matches = eval("self.model.alias_set.related.model.objects.filter(db_key__%s=ostring%s)" % (estring, lstring_alias))
matches = [alias.db_obj for alias in alias_matches]
@ -156,10 +156,10 @@ class ObjectManager(TypedObjectManager):
Get all objects that has a location
set to this one.
"""
oquery = self.filter(db_location__id=location.id)
estring = ""
if excludeobj:
oquery = oquery.exclude(db_key=excludeobj)
return oquery
estring = ".exclude(db_key=excludeobj)"
return eval("self.filter(db_location__id=location.id)%s" % estring)
@returns_typeclass_list
def object_search(self, character, ostring,
@ -220,7 +220,7 @@ class ObjectManager(TypedObjectManager):
def local_and_global_search(ostring, exact=False):
"Helper method for searching objects"
matches = []
for location in search_locations:
for location in search_locations:
if attribute_name:
# Attribute/property search. First, search for db_<attrname> matches on the model
matches.extend(self.get_objs_with_db_property_match(attribute_name, ostring, location, exact))
@ -229,13 +229,13 @@ class ObjectManager(TypedObjectManager):
matches.extend(self.get_objs_with_attr_match(attribute_name, ostring, location, exact))
else:
# No attribute/property named. Do a normal key/alias-search
matches = self.get_objs_with_key_or_alias(ostring, location, exact)
matches.extend(self.get_objs_with_key_or_alias(ostring, location, exact))
return matches
# Search through all possibilities.
match_number = None
matches = local_and_global_search(ostring, exact=True)
matches = local_and_global_search(ostring, exact=True)
if not matches:
# if we have no match, check if we are dealing with an "N-keyword" query - if so, strip it.
match_number, ostring = IDPARSER(ostring)

View file

@ -587,7 +587,7 @@ class TypedObject(SharedMemoryModel):
TYPECLASS_CACHE[path] = typeclass
return typeclass
#@typeclass.deleter
def typeclass_del(self, value):
def typeclass_del(self):
"Deleter. Allows for del self.typeclass (don't allow deletion)"
raise Exception("The typeclass property should never be deleted!")
typeclass = property(typeclass_get, fdel=typeclass_del)