From: Carl Worth Date: Sat, 16 Jan 2021 15:47:45 +0000 (-0800) Subject: Live fix for apparently overflowing the Slack message limit with hunt details X-Git-Url: https://git.cworth.org/git?p=turbot;a=commitdiff_plain;h=c6ad0733c2613b899a30291b14222ef6c322c6cb Live fix for apparently overflowing the Slack message limit with hunt details 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. --- diff --git a/turbot/events.py b/turbot/events.py index 508e8d9..eb5bcc4 100644 --- a/turbot/events.py +++ b/turbot/events.py @@ -1,7 +1,7 @@ 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 ) @@ -47,7 +47,7 @@ def home(turb, user_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)) @@ -58,9 +58,9 @@ def home(turb, user_id): * my_hunt_blocks ] else: - my_hunt_blocks = [ + my_hunt_blocks.append([ section_block(text_block("You do not belong to any hunts")) - ] + ]) if len(available_hunt_blocks): available_hunt_blocks = [ diff --git a/turbot/hunt.py b/turbot/hunt.py index 9771298..7b515d2 100644 --- a/turbot/hunt.py +++ b/turbot/hunt.py @@ -41,6 +41,10 @@ def hunt_blocks(turb, hunt, puzzle_status='unsolved', search_terms=[], 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. @@ -117,12 +121,13 @@ def hunt_blocks(turb, hunt, puzzle_status='unsolved', search_terms=[], 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?)' - blocks += [ + block += [ 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: - blocks += round_blocks(round, puzzles, omit_header=True) + block += round_blocks(round, puzzles, omit_header=True) 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] @@ -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*" - blocks.append(section_block(text_block(stray_text))) + block.append(section_block(text_block(stray_text))) for puzzle in stray_puzzles: - blocks += puzzle_blocks(puzzle) + block += puzzle_blocks(puzzle) - blocks.append(divider_block()) + block.append(divider_block()) return blocks diff --git a/turbot/interaction.py b/turbot/interaction.py index d87d27a..94787b4 100644 --- a/turbot/interaction.py +++ b/turbot/interaction.py @@ -1269,10 +1269,11 @@ def hunt(turb, body, args): 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 @@ -1343,10 +1344,11 @@ def round(turb, body, args): 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