From 0878d40471403513b6da016d7412d07a5d903e9b Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Sat, 9 Jan 2021 05:21:43 -0800 Subject: [PATCH] Extend puzzle search to include type and tags 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 | 5 +++-- turbot/interaction.py | 7 ++++--- turbot/puzzle.py | 23 +++++++++++++++++------ 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/turbot/hunt.py b/turbot/hunt.py index c2e59e2..1e46f6c 100644 --- a/turbot/hunt.py +++ b/turbot/hunt.py @@ -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: diff --git a/turbot/interaction.py b/turbot/interaction.py index 99e76e6..1f5d11f 100644 --- a/turbot/interaction.py +++ b/turbot/interaction.py @@ -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] diff --git a/turbot/puzzle.py b/turbot/puzzle.py index b361b10..1dbea5d 100644 --- a/turbot/puzzle.py +++ b/turbot/puzzle.py @@ -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: -- 2.43.0