]> git.cworth.org Git - turbot/commitdiff
Add state string to list of puzzle attributes matched in searching
authorCarl Worth <cworth@cworth.org>
Tue, 5 Jan 2021 18:34:26 +0000 (10:34 -0800)
committerCarl Worth <cworth@cworth.org>
Tue, 5 Jan 2021 18:36:30 +0000 (10:36 -0800)
This is a really important one so that people can use state strings
for things like "logic" and others who want to solve a logic puzzle
can find them.

turbot/hunt.py
turbot/interaction.py
turbot/puzzle.py

index a832f1db2693aed5efdc5016d24d2c6f7ccaac93..d25c803ab705c423a3eae448d801110070b011a1 100644 (file)
@@ -46,9 +46,9 @@ def hunt_blocks(turb, hunt, puzzle_status='unsolved', search_terms=[]):
       search_terms: A list of search terms. Only puzzles that match
                     all of these terms will be included in the
                     result. A match will be considered on any of
-                    puzzle title, round title, puzzle URL, or solution
-                    string. Terms can include regular expression
-                    syntax.
+                    puzzle title, round title, puzzle URL, puzzle
+                    state or solution string. Terms can include
+                    regular expression syntax.
 
     The return value can be used in a Slack command expecting blocks to
     provide all the details of a hunt, (puzzles, their state,
index 164e4311fbca7c76c262438cb758fe437cdbeb46..0f71b01fc1159cd5f18f184bf83b174266db7b21 100644 (file)
@@ -626,10 +626,10 @@ def hunt(turb, body, args):
     characters, (though quotation marks can be used to include a space
     character in a term). All terms must match on a puzzle in order
     for that puzzle to be included. But a puzzle will be considered to
-    match if any of the puzzle title, round title, puzzle URL, or
-    puzzle solution match. Matching will be performed without regard
-    to case sensitivity and the search terms can include regular
-    expression syntax.
+    match if any of the puzzle title, round title, puzzle URL, puzzle
+    state, or puzzle solution match. Matching will be performed
+    without regard to case sensitivity and the search terms can
+    include regular expression syntax.
     """
 
     channel_id = body['channel_id'][0]
index 8f044b1ca7996fb6f24793639c84621d6413bebd..7db006b9b237702289a41125e81a4e169e0674d3 100644 (file)
@@ -73,8 +73,8 @@ def puzzle_matches_one(puzzle, pattern):
     """Returns True if this puzzle matches the given string (regexp)
 
     A match will be considered on any of puzzle title, round title,
-    puzzle URL, or solution string. The string can include regular
-    expression syntax. Matching is case insensitive.
+    puzzle URL, puzzle state, or solution string. The string can
+    include regular expression syntax. Matching is case insensitive.
     """
 
     p = re.compile('.*'+pattern+'.*', re.IGNORECASE)
@@ -87,22 +87,28 @@ def puzzle_matches_one(puzzle, pattern):
             if p.match(round):
                 return True
 
-    if p.match(puzzle['url']):
-        return True
+    if 'url' in puzzle:
+        if p.match(puzzle['url']):
+            return True
 
-    for solution in puzzle['solution']:
-        if p.match(solution):
+    if 'state' in puzzle:
+        if p.match(puzzle['state']):
             return True
 
+    if 'solution' in puzzle:
+        for solution in puzzle['solution']:
+            if p.match(solution):
+                return True
+
     return False
 
 def puzzle_matches_all(puzzle, patterns):
     """Returns True if this puzzle matches all of the given list of patterns
 
     A match will be considered on any of puzzle title, round title,
-    puzzle URL, or solution string. All patterns must match the puzzle
-    somewhere, (that is, there is an implicit logical AND between
-    patterns). Patterns can include regular expression
+    puzzle URL, puzzle state, or solution string. All patterns must
+    match the puzzle somewhere, (that is, there is an implicit logical
+    AND between patterns). Patterns can include regular expression
     syntax. Matching is case insensitive.
     """