From b529c0ad0dcb5d3cc3c53290a3f95368824dd4b3 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Tue, 5 Jan 2021 10:34:26 -0800 Subject: [PATCH] Add state string to list of puzzle attributes matched in searching 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 | 6 +++--- turbot/interaction.py | 8 ++++---- turbot/puzzle.py | 24 +++++++++++++++--------- 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/turbot/hunt.py b/turbot/hunt.py index a832f1d..d25c803 100644 --- a/turbot/hunt.py +++ b/turbot/hunt.py @@ -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, diff --git a/turbot/interaction.py b/turbot/interaction.py index 164e431..0f71b01 100644 --- a/turbot/interaction.py +++ b/turbot/interaction.py @@ -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] diff --git a/turbot/puzzle.py b/turbot/puzzle.py index 8f044b1..7db006b 100644 --- a/turbot/puzzle.py +++ b/turbot/puzzle.py @@ -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. """ -- 2.43.0