Fixing @open to be a bit more robust. Also handle exit name matching a lot more gracefully.

This commit is contained in:
Greg Taylor 2007-05-18 15:20:24 +00:00
parent f6311dd41e
commit 531fbbacaa
4 changed files with 27 additions and 16 deletions

View file

@ -540,7 +540,7 @@ class Object(models.Model):
return is_match
def name_match(self, oname):
def name_match(self, oname, match_type="fuzzy"):
"""
See if the input (oname) can be used to identify this particular object.
Check the # sign for dbref (exact) reference, and anything else is a
@ -550,8 +550,17 @@ class Object(models.Model):
dbref_match for an exclusively name-based match.
"""
if oname[0] == '#':
# First character is a pound sign, looks to be a dbref.
return self.dbref_match(oname)
elif match_type == "exact":
# Exact matching
name_chunks = self.name.lower().split(';')
for chunk in name_chunks:
if oname.lower() == chunk:
return True
return False
else:
# Fuzzy matching.
return oname.lower() in self.name.lower()
def filter_contents_from_str(self, oname):

View file

@ -24,7 +24,7 @@ def match_exits(pobject, searchstr):
See if we can find an input match to exits.
"""
exits = pobject.get_location().get_contents(filter_type=4)
return functions_db.list_search_object_namestr(exits, searchstr)
return functions_db.list_search_object_namestr(exits, searchstr, match_type="exact")
def handle(cdat):
"""

View file

@ -1,17 +1,16 @@
import os
import resource
import functions_db
import functions_general
import commands_general
import commands_unloggedin
import cmdhandler
import session_mgr
import ansi
import defines_global
from django.contrib.auth.models import User
from apps.objects.models import Object
import cmdhandler
import session_mgr
import functions_general
import functions_db
import commands_general
import commands_unloggedin
import ansi
"""
Any command here is prefixed by an '@' sign, usually denoting a
builder, staff or otherwise manipulative command that doesn't fall within
@ -323,7 +322,7 @@ def cmd_open(cdat):
session.msg("Open an exit to where?")
return
eq_args = args[0].split('=')
eq_args = ' '.join(args).split('=')
exit_name = eq_args[0]
if len(exit_name) == 0:
@ -348,16 +347,19 @@ def cmd_open(cdat):
if destination.is_exit():
session.msg("You can't open an exit to an exit!")
return
print exit_name
odat = {"name": exit_name, "type": 4, "location": pobject.get_location(), "owner": pobject, "home":destination}
new_object = functions_db.create_object(odat)
session.msg("You open the exit - %s" % (new_object,))
session.msg("You open the an exit - %s to %s" % (new_object.get_name(),destination.get_name()))
if len(comma_split) > 1:
second_exit_name = ','.join(comma_split[1:])
odat = {"name": second_exit_name, "type": 4, "location": destination, "owner": pobject, "home": pobject.get_location()}
new_object = functions_db.create_object(odat)
session.msg("You open the an exit - %s to %s" % (new_object.get_name(),pobject.get_location().get_name()))
else:
# Create an un-linked exit.
odat = {"name": exit_name, "type": 4, "location": pobject.get_location(), "owner": pobject, "home":None}

View file

@ -68,7 +68,7 @@ def global_object_name_search(ostring, exact_match=False):
else:
return Object.objects.filter(name__icontains=ostring).exclude(type=global_defines.OTYPE_GARBAGE)
def list_search_object_namestr(searchlist, ostring, dbref_only=False, limit_types=False):
def list_search_object_namestr(searchlist, ostring, dbref_only=False, limit_types=False, match_type="fuzzy"):
"""
Iterates through a list of objects and returns a list of
name matches.
@ -85,9 +85,9 @@ def list_search_object_namestr(searchlist, ostring, dbref_only=False, limit_type
return [prospect for prospect in searchlist if prospect.dbref_match(ostring)]
else:
if limit_types:
return [prospect for prospect in searchlist if prospect.name_match(ostring) and prospect.type in limit_types]
return [prospect for prospect in searchlist if prospect.name_match(ostring, match_type=match_type) and prospect.type in limit_types]
else:
return [prospect for prospect in searchlist if prospect.name_match(ostring)]
return [prospect for prospect in searchlist if prospect.name_match(ostring, match_type=match_type)]
def player_search(searcher, ostring):
"""