Fixing @open to be a bit more robust. Also handle exit name matching a lot more gracefully.
This commit is contained in:
parent
f6311dd41e
commit
531fbbacaa
4 changed files with 27 additions and 16 deletions
|
|
@ -540,7 +540,7 @@ class Object(models.Model):
|
||||||
|
|
||||||
return is_match
|
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.
|
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
|
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.
|
dbref_match for an exclusively name-based match.
|
||||||
"""
|
"""
|
||||||
if oname[0] == '#':
|
if oname[0] == '#':
|
||||||
|
# First character is a pound sign, looks to be a dbref.
|
||||||
return self.dbref_match(oname)
|
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:
|
else:
|
||||||
|
# Fuzzy matching.
|
||||||
return oname.lower() in self.name.lower()
|
return oname.lower() in self.name.lower()
|
||||||
|
|
||||||
def filter_contents_from_str(self, oname):
|
def filter_contents_from_str(self, oname):
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ def match_exits(pobject, searchstr):
|
||||||
See if we can find an input match to exits.
|
See if we can find an input match to exits.
|
||||||
"""
|
"""
|
||||||
exits = pobject.get_location().get_contents(filter_type=4)
|
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):
|
def handle(cdat):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,16 @@
|
||||||
import os
|
import os
|
||||||
import resource
|
import resource
|
||||||
|
|
||||||
import functions_db
|
|
||||||
import functions_general
|
|
||||||
import commands_general
|
|
||||||
import commands_unloggedin
|
|
||||||
import cmdhandler
|
|
||||||
|
|
||||||
import session_mgr
|
|
||||||
import ansi
|
|
||||||
import defines_global
|
import defines_global
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from apps.objects.models import Object
|
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
|
Any command here is prefixed by an '@' sign, usually denoting a
|
||||||
builder, staff or otherwise manipulative command that doesn't fall within
|
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?")
|
session.msg("Open an exit to where?")
|
||||||
return
|
return
|
||||||
|
|
||||||
eq_args = args[0].split('=')
|
eq_args = ' '.join(args).split('=')
|
||||||
exit_name = eq_args[0]
|
exit_name = eq_args[0]
|
||||||
|
|
||||||
if len(exit_name) == 0:
|
if len(exit_name) == 0:
|
||||||
|
|
@ -349,15 +348,18 @@ def cmd_open(cdat):
|
||||||
session.msg("You can't open an exit to an exit!")
|
session.msg("You can't open an exit to an exit!")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
print exit_name
|
||||||
odat = {"name": exit_name, "type": 4, "location": pobject.get_location(), "owner": pobject, "home":destination}
|
odat = {"name": exit_name, "type": 4, "location": pobject.get_location(), "owner": pobject, "home":destination}
|
||||||
new_object = functions_db.create_object(odat)
|
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:
|
if len(comma_split) > 1:
|
||||||
second_exit_name = ','.join(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()}
|
odat = {"name": second_exit_name, "type": 4, "location": destination, "owner": pobject, "home": pobject.get_location()}
|
||||||
new_object = functions_db.create_object(odat)
|
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:
|
else:
|
||||||
# Create an un-linked exit.
|
# Create an un-linked exit.
|
||||||
odat = {"name": exit_name, "type": 4, "location": pobject.get_location(), "owner": pobject, "home":None}
|
odat = {"name": exit_name, "type": 4, "location": pobject.get_location(), "owner": pobject, "home":None}
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@ def global_object_name_search(ostring, exact_match=False):
|
||||||
else:
|
else:
|
||||||
return Object.objects.filter(name__icontains=ostring).exclude(type=global_defines.OTYPE_GARBAGE)
|
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
|
Iterates through a list of objects and returns a list of
|
||||||
name matches.
|
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)]
|
return [prospect for prospect in searchlist if prospect.dbref_match(ostring)]
|
||||||
else:
|
else:
|
||||||
if limit_types:
|
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:
|
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):
|
def player_search(searcher, ostring):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue