From: Carl Worth Date: Fri, 1 Jan 2021 18:55:35 +0000 (-0800) Subject: Add list of available hunts to the Turbot home view X-Git-Url: https://git.cworth.org/git?a=commitdiff_plain;h=e1e4adc58009aea38c51e0d038f7544596e4dc05;hp=9fa66872a067d0cf4f580e36ba24761c5634f014;p=turbot Add list of available hunts to the Turbot home view So that people can easily find active, public hunts. --- diff --git a/turbot/events.py b/turbot/events.py index 03c97e1..ccddc97 100644 --- a/turbot/events.py +++ b/turbot/events.py @@ -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")) ] }