]> git.cworth.org Git - turbot/blobdiff - turbot/puzzle.py
Use a deep copy when comparing a puzzle to detect state modifications
[turbot] / turbot / puzzle.py
index 037dd5e01b3599dc7cca0b329d18777c2c532eaf..b361b10f3d322ce5efb43abd92c3e978e3e8c9d3 100644 (file)
@@ -62,6 +62,7 @@ def puzzle_blocks(puzzle, include_rounds=False):
     url = puzzle.get('url', None)
     sheet_url = puzzle.get('sheet_url', None)
     state = puzzle.get('state', None)
+    tags = puzzle.get('tags', [])
     status_emoji = ''
     solution_str = ''
 
@@ -85,7 +86,15 @@ def puzzle_blocks(puzzle, include_rounds=False):
 
     state_str = ''
     if state:
-        state_str = "\n{}".format(state)
+        state_str = " State: {}".format(state)
+
+    tags_str = ''
+    if tags:
+        tags_str = " Tags: "+" ".join(["`{}`".format(tag) for tag in tags])
+
+    extra_str = ''
+    if state_str or tags_str:
+        extra_str = "\n{}{}".format(tags_str, state_str)
 
     rounds_str = ''
     if include_rounds and 'rounds' in puzzle:
@@ -95,12 +104,13 @@ def puzzle_blocks(puzzle, include_rounds=False):
             ", ".join(rounds)
         )
 
-    puzzle_text = "{}{} {}<{}|{}> ({}){}{}".format(
-        status_emoji, solution_str,
+    puzzle_text = "{} {}<{}|{}> {} ({}){}{}".format(
+        status_emoji,
         meta_str,
         channel_url(channel_id), name,
+        solution_str,
         ', '.join(links), rounds_str,
-        state_str
+        extra_str
     )
 
     # Combining hunt ID and puzzle ID together here is safe because
@@ -208,6 +218,10 @@ def puzzle_channel_topic(puzzle):
     if len(links):
         topic += "({})".format(', '.join(links))
 
+    tags = puzzle.get('tags', [])
+    if tags:
+        topic += " {}".format(" ".join(["`{}`".format(t) for t in tags]))
+
     state = puzzle.get('state', None)
     if state:
         topic += " {}".format(state)
@@ -279,3 +293,12 @@ def puzzle_update_channel_and_sheet(turb, puzzle, old_puzzle=None):
             channel=channel_id,
             name=channel_name
         )
+
+# A copy deep enough to work for puzzle_update_channel_and_sheet above
+def puzzle_copy(old_puzzle):
+    new_puzzle = old_puzzle.copy()
+
+    if 'tags' in old_puzzle:
+        new_puzzle['tags'] = old_puzzle['tags'].copy()
+
+    return new_puzzle