]> git.cworth.org Git - turbot/commitdiff
Extend puzzle search to include type and tags
authorCarl Worth <cworth@cworth.org>
Sat, 9 Jan 2021 13:21:43 +0000 (05:21 -0800)
committerCarl Worth <cworth@cworth.org>
Sat, 9 Jan 2021 13:35:42 +0000 (05:35 -0800)
The matching on puzzle type means you can now do:

/hunt meta

or:

/hunt plain

to see all meta or non-meta puzzles.

And the matching on tags should be obvious.

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

index c2e59e2be937c4577e7696f80b01fce51356e05d..1e46f6c94eb2c96ed2f721e29facb73551bce85b 100644 (file)
@@ -54,8 +54,9 @@ def hunt_blocks(turb, hunt, puzzle_status='unsolved', search_terms=[],
                     all of these terms will be included in the
                     result. A match will be considered on any of
                     puzzle title, round title, puzzle URL, puzzle
-                    state or solution string. Terms can include
-                    regular expression syntax.
+                    state, puzzle type, tags, or solution
+                    string. Terms can include regular expression
+                    syntax.
 
       limit_to_rounds: A list of rounds. If provided only the given
                        rounds will be included in the output. Note:
index 99e76e6d688f34266cb568d5a808dd2fc9fc0a82..1f5d11f4b4218b9a92680088d87521d69c6cd74b 100644 (file)
@@ -1024,9 +1024,10 @@ def hunt(turb, body, args):
     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, puzzle
-    state, or puzzle solution match. Matching will be performed
-    without regard to case sensitivity and the search terms can
-    include regular expression syntax.
+    state, puzzle type, tags, 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 b361b10f3d322ce5efb43abd92c3e978e3e8c9d3..1dbea5d74906c447b3e6b09df70758f4379389d5 100644 (file)
@@ -129,8 +129,9 @@ 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, puzzle state, or solution string. The string can
-    include regular expression syntax. Matching is case insensitive.
+    puzzle URL, puzzle state, puzzle type, tags, or solution
+    string. The string can include regular expression syntax. Matching
+    is case insensitive.
     """
 
     p = re.compile('.*'+pattern+'.*', re.IGNORECASE)
@@ -151,21 +152,31 @@ def puzzle_matches_one(puzzle, pattern):
         if p.match(puzzle['state']):
             return True
 
+    if 'type' in puzzle:
+        if p.match(puzzle['type']):
+            return True
+
     if 'solution' in puzzle:
         for solution in puzzle['solution']:
             if p.match(solution):
                 return True
 
+    if 'tags' in puzzle:
+        for tag in puzzle['tags']:
+            if p.match(tag):
+                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, 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.
+    puzzle URL, puzzle state, puzzle types, tags, 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.
+
     """
 
     for pattern in patterns: