diff --git a/src/commands/objmanip.py b/src/commands/objmanip.py index 21ed6b0415..afd8d1f05b 100644 --- a/src/commands/objmanip.py +++ b/src/commands/objmanip.py @@ -16,7 +16,7 @@ def cmd_teleport(command): teleport Usage: - teleport/switch [ = ] + teleport/switch [ =] Switches: quiet - don't inform the source and target @@ -48,16 +48,14 @@ def cmd_teleport(command): # Use search_for_object to handle duplicate/nonexistant results. if not victim: return - - destination = source_object.search_for_object(eq_args[1]) - # Use search_for_object to handle duplicate/nonexistant results. - if not destination: - return - if victim.is_room(): source_object.emit_to("You can't teleport a room.") return - + destination = source_object.search_for_object_global(eq_args[1],exact_match=True, + limit_types=[defines_global.OTYPE_THING, + defines_global.OTYPE_ROOM]) + if not destination: + return if victim == destination: source_object.emit_to("You can't teleport an object inside of itself!") return @@ -65,7 +63,9 @@ def cmd_teleport(command): victim.move_to(destination, quiet=tel_quietly) else: # Direct teleport (no equal sign) - target_obj = source_object.search_for_object(command.command_argument) + target_obj = source_object.search_for_object_global(eq_args[0],exact_match=True, + limit_types=[defines_global.OTYPE_THING, + defines_global.OTYPE_ROOM]) # Use search_for_object to handle duplicate/nonexistant results. if not target_obj: return @@ -687,18 +687,12 @@ def cmd_open(command): else: # We have the name of a destination. Try to find it. - destination = Object.objects.global_object_name_search(dest_name) + destination = source_object.search_for_object_global(dest_name, exact_match=True, + limit_types=[defines_global.OTYPE_THING, + defines_global.OTYPE_ROOM]) if not destination: - source_object.emit_to("No matches found for '%s'." % dest_name) return - if len(destination) > 1: - s = "There are multiple matches. Please use #dbref to be more specific." - for d in destination: - s += "\n %s" % destination.get_name() - source_object.emit_to(s) - return - destination = destination[0] - + if destination.is_exit(): source_object.emit_to("You can't open an exit to an exit!") return @@ -914,18 +908,11 @@ def cmd_link(command): if not source_object.controls_other(obj): source_object.emit_to(defines_global.NOCONTROL_MSG) return - destination = Object.objects.global_object_name_search(dest_name) + destination = source_object.search_for_object_global(dest_name, exact_match=True, + limit_types=[defines_global.OTYPE_THING, + defines_global.OTYPE_ROOM]) if not destination: - source_object.emit_to("No matches found for '%s'." % dest_name) return - if len(destination) > 1: - s = "There are multiple matches. Please use #dbref to be more specific." - for d in destination: - s += "\n %s" % destination.get_name(show_dbref=True) - source_object.emit_to(s) - return - destination = destination[0] - # do the link. oldhome = obj.get_home() ohome_text = "" diff --git a/src/objects/managers/object.py b/src/objects/managers/object.py index 9b38243d3a..29b3bb2e77 100644 --- a/src/objects/managers/object.py +++ b/src/objects/managers/object.py @@ -145,8 +145,9 @@ class ObjectManager(models.Manager): o_query = self.filter(name__iexact=ostring) else: o_query = self.filter(name__icontains=ostring) - if limit_types: - o_query = o_query.include(type__in=limit_types) + if limit_types is not False: + for limiter in limit_types: + o_query.filter(type=limiter) return o_query.exclude(type__in=[defines_global.OTYPE_GARBAGE, defines_global.OTYPE_GOING]) diff --git a/src/objects/models.py b/src/objects/models.py index 5ba05a3ce5..eedbc84f62 100755 --- a/src/objects/models.py +++ b/src/objects/models.py @@ -220,6 +220,27 @@ class Object(models.Model): return False else: return results[0] + + def search_for_object_global(self, ostring, exact_match=True, limit_types=[]): + """ + Search for ostring in all objects, globally. Handle multiple-matches + and no matches gracefully. This is mainly intended to be used by + admin and build-type commands. It also accepts #dbref + search queries. + """ + results = Object.objects.global_object_name_search(ostring, exact_match=exact_match, + limit_types=limit_types) + if not results: + self.emit_to("No matches found for '%s'." % ostring) + return + if len(results) > 1: + string = "More than one match for '%s' (please narrow target):" % ostring + for res in results: + string += "\n %s" % res.get_name() + self.emit_to(string) + return + return results[0] + def get_sessions(self): """