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 Adding permanent aliases
Usage: Usage:
@alias <obj> = alias[,alias,alias,...] @alias <obj> = [alias[,alias,alias,...]]
Assigns aliases to an object so it can be referenced by more 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 created with the 'alias' command! Aliases set with @alias are
changing the object in question, making those aliases usable changing the object in question, making those aliases usable
by everyone. by everyone.
@ -127,18 +128,33 @@ class CmdSetObjAlias(MuxCommand):
"Set the aliases." "Set the aliases."
caller = self.caller caller = self.caller
objname, aliases = self.lhs, self.rhslist objname, aliases = self.lhs, self.rhslist
if not objname:
if not aliases:
caller.msg("Usage: @alias <obj> = <alias>,<alias>,...") caller.msg("Usage: @alias <obj> = <alias>,<alias>,...")
return return
# Find the object to receive aliases # Find the object to receive aliases
obj = caller.search(objname, global_search=True) obj = caller.search(objname, global_search=True)
# Use search to handle duplicate/nonexistant results.
if not obj: if not obj:
return 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'): if not has_perm(caller, obj, 'modify_attributes'):
caller.msg("You don't have permission to do that.") caller.msg("You don't have permission to do that.")
return 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) # merge the old and new aliases (if any)
old_aliases = obj.aliases old_aliases = obj.aliases
new_aliases = [str(alias).strip().lower() new_aliases = [str(alias).strip().lower()
@ -148,8 +164,7 @@ class CmdSetObjAlias(MuxCommand):
aliases = list(set(old_aliases)) aliases = list(set(old_aliases))
# save back to object. # save back to object.
obj.aliases = aliases 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): class CmdCopy(ObjManipCommand):
""" """
@ -875,9 +890,11 @@ class CmdName(ObjManipCommand):
# change the name and set aliases: # change the name and set aliases:
if newname: if newname:
obj.name = newname obj.name = newname
astring = ""
if aliases: if aliases:
obj.aliases = 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): class CmdOpen(ObjManipCommand):
@ -1356,9 +1373,7 @@ class CmdExamine(ObjManipCommand):
obj_attrs = objdef['attrs'] obj_attrs = objdef['attrs']
obj = caller.search(obj_name) obj = caller.search(obj_name)
if not obj: if not obj:
string += "\nObject '%s' not found." % obj_name
continue continue
if not has_perm(caller, obj, 'obj_info'): if not has_perm(caller, obj, 'obj_info'):
#If we don't have special info access, just look at the object instead. #If we don't have special info access, just look at the object instead.
@ -1370,8 +1385,10 @@ class CmdExamine(ObjManipCommand):
string += self.format_attributes(obj, attrname) string += self.format_attributes(obj, attrname)
else: else:
string += self.format_output(obj) string += self.format_output(obj)
string = string.strip()
# Send it all # Send it all
caller.msg(string) if string:
caller.msg(string.strip())
class CmdFind(MuxCommand): class CmdFind(MuxCommand):

View file

@ -156,10 +156,10 @@ class ObjectManager(TypedObjectManager):
Get all objects that has a location Get all objects that has a location
set to this one. set to this one.
""" """
oquery = self.filter(db_location__id=location.id) estring = ""
if excludeobj: if excludeobj:
oquery = oquery.exclude(db_key=excludeobj) estring = ".exclude(db_key=excludeobj)"
return oquery return eval("self.filter(db_location__id=location.id)%s" % estring)
@returns_typeclass_list @returns_typeclass_list
def object_search(self, character, ostring, def object_search(self, character, ostring,
@ -229,7 +229,7 @@ class ObjectManager(TypedObjectManager):
matches.extend(self.get_objs_with_attr_match(attribute_name, ostring, location, exact)) matches.extend(self.get_objs_with_attr_match(attribute_name, ostring, location, exact))
else: else:
# No attribute/property named. Do a normal key/alias-search # 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 return matches
# Search through all possibilities. # Search through all possibilities.

View file

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