Fixed bugs in alias and search system, including properly searching inventory. Expanded @alias command with more functionality.
This commit is contained in:
parent
50e66b3813
commit
8aa22fbec8
3 changed files with 39 additions and 22 deletions
|
|
@ -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):
|
||||||
|
|
@ -1355,11 +1372,9 @@ class CmdExamine(ObjManipCommand):
|
||||||
obj_name = objdef['name']
|
obj_name = objdef['name']
|
||||||
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.
|
||||||
caller.exec_cmd('look %s' % obj_name)
|
caller.exec_cmd('look %s' % obj_name)
|
||||||
|
|
@ -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):
|
||||||
|
|
|
||||||
|
|
@ -142,7 +142,7 @@ class ObjectManager(TypedObjectManager):
|
||||||
lstring_alias = ", db_obj__db_location=location"
|
lstring_alias = ", db_obj__db_location=location"
|
||||||
if exact:
|
if exact:
|
||||||
estring = "iexact"
|
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:
|
if not matches:
|
||||||
alias_matches = eval("self.model.alias_set.related.model.objects.filter(db_key__%s=ostring%s)" % (estring, lstring_alias))
|
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]
|
matches = [alias.db_obj for alias in alias_matches]
|
||||||
|
|
@ -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,
|
||||||
|
|
@ -220,7 +220,7 @@ class ObjectManager(TypedObjectManager):
|
||||||
def local_and_global_search(ostring, exact=False):
|
def local_and_global_search(ostring, exact=False):
|
||||||
"Helper method for searching objects"
|
"Helper method for searching objects"
|
||||||
matches = []
|
matches = []
|
||||||
for location in search_locations:
|
for location in search_locations:
|
||||||
if attribute_name:
|
if attribute_name:
|
||||||
# Attribute/property search. First, search for db_<attrname> matches on the model
|
# 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))
|
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))
|
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.
|
||||||
|
|
||||||
match_number = None
|
match_number = None
|
||||||
matches = local_and_global_search(ostring, exact=True)
|
matches = local_and_global_search(ostring, exact=True)
|
||||||
if not matches:
|
if not matches:
|
||||||
# if we have no match, check if we are dealing with an "N-keyword" query - if so, strip it.
|
# if we have no match, check if we are dealing with an "N-keyword" query - if so, strip it.
|
||||||
match_number, ostring = IDPARSER(ostring)
|
match_number, ostring = IDPARSER(ostring)
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue