From 1af32409a8d60e9580a0873bd8b2fa3c676c37ee Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Tue, 11 Jan 2022 21:37:54 -0800 Subject: [PATCH] Add a state field to the "edit hunt" form Also, put both the hunt url and the hunt state into the hunt channel's topic. --- turbot/hunt.py | 20 ++++++++++++++++++++ turbot/interaction.py | 13 ++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/turbot/hunt.py b/turbot/hunt.py index 5edd443..2d4de51 100644 --- a/turbot/hunt.py +++ b/turbot/hunt.py @@ -163,3 +163,23 @@ def hunt_blocks(turb, hunt, puzzle_status='unsolved', search_terms=[], block.append(divider_block()) return blocks + +def hunt_update_topic(turb, hunt): + + channel_id = hunt['channel_id'] + + topic = '' + + url = hunt.get('url', None) + if url: + topic += "<{}|Hunt website> ".format(url) + + state = hunt.get('state', None) + if state: + topic += state + + # Slack only allows 250 characters for a topic + if len(topic) > 250: + topic = topic[:247] + "..." + turb.slack_client.conversations_setTopic(channel=channel_id, + topic=topic) diff --git a/turbot/interaction.py b/turbot/interaction.py index 21e741e..25307c2 100644 --- a/turbot/interaction.py +++ b/turbot/interaction.py @@ -5,7 +5,8 @@ from turbot.blocks import ( from turbot.hunt import ( find_hunt_for_hunt_id, hunt_blocks, - hunt_puzzles_for_hunt_id + hunt_puzzles_for_hunt_id, + hunt_update_topic ) from turbot.puzzle import ( find_puzzle_for_url, @@ -459,6 +460,10 @@ def edit_hunt(turb, hunt, trigger_id): input_block("Hunt URL", "url", "External URL of hunt", initial_value=hunt.get("url", None), optional=True), + input_block("State", "state", + "State of the hunt (goals, upcoming meetings, etc.)", + initial_value=hunt.get("state", None), + optional=True), checkbox_block("Is this hunt active?", "Active", "active", checked=(hunt.get('active', False))) ] @@ -497,6 +502,9 @@ def edit_hunt_submission(turb, payload, metadata): if url: hunt['url'] = url + hunt_state = state['state']['state']['value'] + if hunt_state: + hunt['state'] = hunt_state if state['active']['active']['selected_options']: hunt['active'] = True else: @@ -522,6 +530,9 @@ def edit_hunt_submission(turb, payload, metadata): turb.slack_client, hunt['channel_id'], edit_message, blocks=blocks) + # Update channel topic and description + hunt_update_topic(turb, hunt) + return lambda_ok def new_hunt_command(turb, body): -- 2.43.0