From 9a32366dc4ed1c9ea6e310ad23923b564691a8fa Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Sat, 9 Jan 2021 00:26:24 -0800 Subject: [PATCH] Put a message into the channel when a user edits a puzzle So that other members of the puzzle are informed that something has changed. --- TODO | 3 --- turbot/interaction.py | 9 +++++++++ turbot/slack.py | 8 ++++++-- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/TODO b/TODO index 23db9cb..20387a6 100644 --- a/TODO +++ b/TODO @@ -1,9 +1,6 @@ Ordered punch-list (aiming to complete by 2021-01-08) ----------------------------------------------------- -• Put a message in the puzzle channel when a user edits something - (maybe just spit out the /puzzle output) - • Add new /puzzle edit as a shortcut instead of /puzzle followed by clicking :pencil: diff --git a/turbot/interaction.py b/turbot/interaction.py index 955fae5..e68aa6f 100644 --- a/turbot/interaction.py +++ b/turbot/interaction.py @@ -179,6 +179,7 @@ def edit_puzzle_submission(turb, payload, metadata): puzzle['sheet_url'] = meta['sheet_url'] state = payload['view']['state']['values'] + user_id = payload['user']['id'] puzzle['name'] = state['name']['name']['value'] url = state['url']['url']['value'] @@ -238,6 +239,14 @@ def edit_puzzle_submission(turb, payload, metadata): # Update the puzzle in the database turb.table.put_item(Item=puzzle) + # Inform the puzzle channel about the edit + edit_message = "Puzzle edited by <@{}>".format(user_id) + blocks = ([section_block(text_block(edit_message+":\n"))] + + puzzle_blocks(puzzle, include_rounds=True)) + slack_send_message( + turb.slack_client, puzzle['channel_id'], + edit_message, blocks=blocks) + # We need to set the channel topic if any of puzzle name, url, # state, status, or solution, has changed. Let's just do that # unconditionally here. diff --git a/turbot/slack.py b/turbot/slack.py index b824213..6ea9166 100644 --- a/turbot/slack.py +++ b/turbot/slack.py @@ -59,5 +59,9 @@ def slack_channel_members(slack_client, channel_id): return members -def slack_send_message(slack_client, channel_id, text): - slack_client.chat_postMessage(channel=channel_id, text=text) +def slack_send_message(slack_client, channel_id, text, blocks=None): + if blocks: + slack_client.chat_postMessage(channel=channel_id, + text=text, blocks=blocks) + else: + slack_client.chat_postMessage(channel=channel_id, text=text) -- 2.43.0