]> git.cworth.org Git - turbot/commitdiff
Add a state field to the "edit hunt" form
authorCarl Worth <cworth@cworth.org>
Wed, 12 Jan 2022 05:37:54 +0000 (21:37 -0800)
committerCarl Worth <cworth@cworth.org>
Wed, 12 Jan 2022 05:37:54 +0000 (21:37 -0800)
Also, put both the hunt url and the hunt state into the hunt channel's topic.

turbot/hunt.py
turbot/interaction.py

index 5edd443e59cc00da59aa14308a6b3fd133246a0a..2d4de5108b4e75f5694b817941d3e24a1a8cec10 100644 (file)
@@ -163,3 +163,23 @@ def hunt_blocks(turb, hunt, puzzle_status='unsolved', search_terms=[],
     block.append(divider_block())
 
     return blocks
     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)
index 21e741e8c19ac84776e8c36330c295876315d553..25307c22a26aec26084da1b623ebaee2acec069f 100644 (file)
@@ -5,7 +5,8 @@ from turbot.blocks import (
 from turbot.hunt import (
     find_hunt_for_hunt_id,
     hunt_blocks,
 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,
 )
 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("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)))
         ]
             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
 
     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:
     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)
 
         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):
     return lambda_ok
 
 def new_hunt_command(turb, body):