From 04db9292ce10d430f3fc3cd8281cdf1c0aea10cf Mon Sep 17 00:00:00 2001 From: Rachel Blackman Date: Sun, 8 Apr 2018 13:11:35 -0700 Subject: [PATCH] Add /contains switch to find. --- evennia/commands/default/building.py | 15 ++++++++++----- evennia/commands/default/tests.py | 1 + 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/evennia/commands/default/building.py b/evennia/commands/default/building.py index 702f2e241a..a111e2c878 100644 --- a/evennia/commands/default/building.py +++ b/evennia/commands/default/building.py @@ -2270,11 +2270,12 @@ class CmdFind(COMMAND_DEFAULT_CLASS): @locate - this is a shorthand for using the /loc switch. Switches: - room - only look for rooms (location=None) - exit - only look for exits (destination!=None) - char - only look for characters (BASE_CHARACTER_TYPECLASS) - exact- only exact matches are returned. - loc - display object location if exists and match has one result + room - only look for rooms (location=None) + exit - only look for exits (destination!=None) + char - only look for characters (BASE_CHARACTER_TYPECLASS) + exact - only exact matches are returned. + loc - display object location if exists and match has one result + contains- search for names containing the string, rather than starting with. Searches the database for an object of a particular name or exact #dbref. Use *accountname to search for an account. The switches allows for @@ -2359,6 +2360,10 @@ class CmdFind(COMMAND_DEFAULT_CLASS): keyquery = Q(db_key__iexact=searchstring, id__gte=low, id__lte=high) aliasquery = Q(db_tags__db_key__iexact=searchstring, db_tags__db_tagtype__iexact="alias", id__gte=low, id__lte=high) + elif "contains" in switches: + keyquery = Q(db_key__icontains=searchstring, id__gte=low, id__lte=high) + aliasquery = Q(db_tags__db_key__icontains=searchstring, + db_tags__db_tagtype__iexact="alias", id__gte=low, id__lte=high) else: keyquery = Q(db_key__istartswith=searchstring, id__gte=low, id__lte=high) aliasquery = Q(db_tags__db_key__istartswith=searchstring, diff --git a/evennia/commands/default/tests.py b/evennia/commands/default/tests.py index 8e73a8bf5d..37e4b07b03 100644 --- a/evennia/commands/default/tests.py +++ b/evennia/commands/default/tests.py @@ -339,6 +339,7 @@ class TestBuilding(CommandTest): self.call(building.CmdFind(), "Char2", expect, cmdstring="@locate") self.call(building.CmdFind(), "/l Char2", expect, cmdstring="find") # /l switch is abbreviated form of /loc self.call(building.CmdFind(), "Char2", "One Match", cmdstring="@find") + self.call(building.CmdFind(), "/contains om2", "One Match") def test_script(self): self.call(building.CmdScript(), "Obj = scripts.Script", "Script scripts.Script successfully added")