]> git.cworth.org Git - turbot/commitdiff
Add list of available hunts to the Turbot home view
authorCarl Worth <cworth@cworth.org>
Fri, 1 Jan 2021 18:55:35 +0000 (10:55 -0800)
committerCarl Worth <cworth@cworth.org>
Fri, 1 Jan 2021 19:00:32 +0000 (11:00 -0800)
So that people can easily find active, public hunts.

turbot/events.py

index 03c97e18cfd17960176d50ae80674503fb15d563..ccddc973a1db502e7381c20f068d73c29f23313e 100644 (file)
@@ -53,7 +53,7 @@ def puzzle_block(puzzle):
 
     return section_block(text_block(puzzle_text))
 
-def hunt_block(turb, hunt):
+def hunt_details_block(turb, hunt):
     name = hunt['name']
     hunt_id = hunt['hunt_id']
     channel_id = hunt['channel_id']
@@ -74,6 +74,17 @@ def hunt_block(turb, hunt):
         divider_block()
     ]
 
+def available_hunt_block(turb, hunt):
+
+    name = hunt['name']
+    channel_id = hunt['channel_id']
+
+    hunt_link = "*<{}|{}>*".format(channel_url(channel_id), name)
+
+    return [
+        section_block(text_block(hunt_link)),
+    ]
+
 def home(turb, user_id):
     """Returns a view to be published as the turbot home tab for user_id
 
@@ -89,30 +100,40 @@ def home(turb, user_id):
     except Exception:
         hunts = []
 
-    hunt_blocks = []
+    my_hunt_blocks = []
+    available_hunt_blocks = []
     for hunt in hunts:
         if not hunt['active']:
             continue
-        if user_id not in slack_channel_members(turb.slack_client,
-                                                hunt['channel_id']):
-            continue
-        hunt_blocks += hunt_block(turb, hunt)
-
-    if len(hunt_blocks):
-        hunt_blocks = [
-            section_block(text_block("*Hunts you belong to*")),
+        if user_id in slack_channel_members(turb.slack_client,
+                                            hunt['channel_id']):
+            my_hunt_blocks += hunt_details_block(turb, hunt)
+        else:
+            available_hunt_blocks += available_hunt_block(turb, hunt)
+
+    if len(my_hunt_blocks):
+        my_hunt_blocks = [
+            section_block(text_block("*Hunts you belong to:*")),
             divider_block(),
-            * hunt_blocks
+            * my_hunt_blocks
         ]
     else:
-        hunt_blocks = [
+        my_hunt_blocks = [
             section_block(text_block("You do not belong to any hunts"))
         ]
 
+    if len(available_hunt_blocks):
+        available_hunt_blocks = [
+            section_block(text_block("*Hunts you can join:*")),
+            divider_block(),
+            * available_hunt_blocks
+        ]
+
     return {
         "type": "home",
         "blocks": [
-            * hunt_blocks,
+            * my_hunt_blocks,
+            * available_hunt_blocks,
             actions_block(button_block("New hunt", "new_hunt"))
         ]
     }