]> git.cworth.org Git - turbot/blob - turbot/events.py
Handle the submission of the "New Hunt" modal
[turbot] / turbot / events.py
1 from turbot.blocks import section_block, text_block, button_block, actions_block
2
3 def hunt_block(hunt):
4     text = "{}: <#{}>".format(hunt['name'], hunt['channel_id'])
5     return section_block(text_block(text))
6
7 def home(turb, user_id, body):
8     """Returns a view to be published as the turbot home tab for user_id
9
10     The body argument is a dictionary as provided by the Slack request.
11     The return value is a dictionary suitable to be published to the
12     Slack views_publish API."""
13
14     response = turb.db.Table("hunts").scan()
15     hunts = response['Items']
16
17     return {
18         "type": "home",
19         "blocks": [
20             section_block(text_block("*Active hunts*")),
21             *[hunt_block(hunt) for hunt in hunts if hunt['active']],
22             actions_block(button_block("New hunt", "new_hunt"))
23         ]
24     }
25
26 def app_home_opened(turb, body):
27     user_id = body['event']['user']
28     view = home(turb, user_id, body)
29     turb.slack_client.views_publish(user_id=user_id, view=view)
30     return "OK"
31
32 events = {
33     "app_home_opened": app_home_opened
34 }