]> git.cworth.org Git - turbot/commitdiff
Live fix for apparently overflowing the Slack message limit with hunt details
authorCarl Worth <cworth@cworth.org>
Sat, 16 Jan 2021 15:47:45 +0000 (07:47 -0800)
committerCarl Worth <cworth@cworth.org>
Sat, 16 Jan 2021 15:49:32 +0000 (07:49 -0800)
Condense the Turbot Home view to only link to hunts, not give all the
details.

Change hunt_blocks() function to return an array of array of blocks,
(broken up at the level of a round). Callers now generate one post for
each element in the outer array. Hopefully this gives us a little
breathing room for now.

turbot/events.py
turbot/hunt.py
turbot/interaction.py

index 508e8d95da15caa666cac268bb25efc14660945d..eb5bcc46c69a8e8bfa09c275081a6f650e71de69 100644 (file)
@@ -1,7 +1,7 @@
 from turbot.blocks import (
     section_block, text_block, button_block, actions_block, divider_block
 )
 from turbot.blocks import (
     section_block, text_block, button_block, actions_block, divider_block
 )
-from turbot.hunt import hunt_blocks, find_hunt_for_hunt_id
+from turbot.hunt import find_hunt_for_hunt_id
 from turbot.sheets import (
     sheets_create, sheets_create_for_puzzle, sheets_create_folder
 )
 from turbot.sheets import (
     sheets_create, sheets_create_for_puzzle, sheets_create_folder
 )
@@ -47,7 +47,7 @@ def home(turb, user_id):
             continue
         if user_id in slack_channel_members(turb.slack_client,
                                             hunt['channel_id']):
             continue
         if user_id in slack_channel_members(turb.slack_client,
                                             hunt['channel_id']):
-            my_hunt_blocks += hunt_blocks(turb, hunt, puzzle_status='all')
+            my_hunt_blocks.append(hunt_link_block(turb, hunt))
         else:
             available_hunt_blocks.append(hunt_link_block(turb, hunt))
 
         else:
             available_hunt_blocks.append(hunt_link_block(turb, hunt))
 
@@ -58,9 +58,9 @@ def home(turb, user_id):
             * my_hunt_blocks
         ]
     else:
             * my_hunt_blocks
         ]
     else:
-        my_hunt_blocks = [
+        my_hunt_blocks.append([
             section_block(text_block("You do not belong to any hunts"))
             section_block(text_block("You do not belong to any hunts"))
-        ]
+        ])
 
     if len(available_hunt_blocks):
         available_hunt_blocks = [
 
     if len(available_hunt_blocks):
         available_hunt_blocks = [
index 97712982fd32aa7afb4367a7b65ce0838f3c910f..7b515d21c0012ccf5b8f74f9f7962f0ef00349cf 100644 (file)
@@ -41,6 +41,10 @@ def hunt_blocks(turb, hunt, puzzle_status='unsolved', search_terms=[],
                 limit_to_rounds=None):
     """Generate Slack blocks for a hunt
 
                 limit_to_rounds=None):
     """Generate Slack blocks for a hunt
 
+    Returns a list of lists of blocks, (broken up by round so that
+    the receiver should do one Slack post for each entry in the
+    outer array.
+
     The hunt argument should be a dictionary as returned from the
     database.
 
     The hunt argument should be a dictionary as returned from the
     database.
 
@@ -117,12 +121,13 @@ def hunt_blocks(turb, hunt, puzzle_status='unsolved', search_terms=[],
             button_block("✏", "edit_hunt", hunt_id)
         )
     ]
             button_block("✏", "edit_hunt", hunt_id)
         )
     ]
+    block = blocks[0]
 
     if not len(puzzles):
         text = "No puzzles found."
         if puzzle_status != 'all':
             text += ' (Consider searching for "all" puzzles?)'
 
     if not len(puzzles):
         text = "No puzzles found."
         if puzzle_status != 'all':
             text += ' (Consider searching for "all" puzzles?)'
-        blocks += [
+        block += [
             section_block(text_block(text))
         ]
 
             section_block(text_block(text))
         ]
 
@@ -132,10 +137,12 @@ def hunt_blocks(turb, hunt, puzzle_status='unsolved', search_terms=[],
             continue
         # If we're only displaying one round the round header is redundant
         if limit_to_rounds and len(limit_to_rounds) == 1:
             continue
         # If we're only displaying one round the round header is redundant
         if limit_to_rounds and len(limit_to_rounds) == 1:
-            blocks += round_blocks(round, puzzles, omit_header=True)
+            block += round_blocks(round, puzzles, omit_header=True)
         else:
         else:
-            blocks += round_blocks(round, puzzles)
-        blocks.append(divider_block())
+            block += round_blocks(round, puzzles)
+        block.append(divider_block())
+        blocks.append([])
+        block = blocks[-1]
 
     # Also blocks for any puzzles not in any round
     stray_puzzles = [puzzle for puzzle in puzzles if 'rounds' not in puzzle]
 
     # Also blocks for any puzzles not in any round
     stray_puzzles = [puzzle for puzzle in puzzles if 'rounds' not in puzzle]
@@ -147,10 +154,10 @@ def hunt_blocks(turb, hunt, puzzle_status='unsolved', search_terms=[],
     # to rounds but specifically the round of unassigned puzzles
     if len(stray_puzzles) and not limit_to_rounds:
         stray_text = "*Puzzles with no assigned round*"
     # to rounds but specifically the round of unassigned puzzles
     if len(stray_puzzles) and not limit_to_rounds:
         stray_text = "*Puzzles with no assigned round*"
-        blocks.append(section_block(text_block(stray_text)))
+        block.append(section_block(text_block(stray_text)))
         for puzzle in stray_puzzles:
         for puzzle in stray_puzzles:
-            blocks += puzzle_blocks(puzzle)
+            block += puzzle_blocks(puzzle)
 
 
-    blocks.append(divider_block())
+    block.append(divider_block())
 
     return blocks
 
     return blocks
index d87d27ac1a6827a9da4f6392245e96328440de6e..94787b40fbc28e15c7773f0ca497b5dcf4bea1b9 100644 (file)
@@ -1269,10 +1269,11 @@ def hunt(turb, body, args):
 
     blocks = hunt_blocks(turb, hunt, puzzle_status=status, search_terms=terms)
 
 
     blocks = hunt_blocks(turb, hunt, puzzle_status=status, search_terms=terms)
 
-    requests.post(response_url,
-                  json = { 'blocks': blocks },
-                  headers = {'Content-type': 'application/json'}
-                  )
+    for block in blocks:
+        requests.post(response_url,
+                      json = { 'blocks': block },
+                      headers = {'Content-type': 'application/json'}
+                      )
 
     return lambda_ok
 
 
     return lambda_ok
 
@@ -1343,10 +1344,11 @@ def round(turb, body, args):
                          limit_to_rounds=puzzle.get('rounds', [])
                          )
 
                          limit_to_rounds=puzzle.get('rounds', [])
                          )
 
-    requests.post(response_url,
-                  json = { 'blocks': blocks },
-                  headers = {'Content-type': 'application/json'}
-                  )
+    for block in blocks:
+        requests.post(response_url,
+                      json = { 'blocks': block },
+                      headers = {'Content-type': 'application/json'}
+                      )
 
     return lambda_ok
 
 
     return lambda_ok