]> git.cworth.org Git - turbot/blob - turbot/views.py
Fix several problems pointed out by flake8
[turbot] / turbot / views.py
1 def text(body):
2     return {
3         "text": {
4             "type": "mrkdwn",
5             "text": body
6         }
7     }
8
9 def section(block):
10     return {
11         "type": "section",
12         **block
13     }
14
15 def actions(*elements):
16     return {
17         "type": "actions",
18         "elements": list(elements)
19     }
20
21 def button(label, name):
22     return {
23         "type": "button",
24         "text": {
25             "type": "plain_text",
26             "text": label,
27             "emoji": True
28         },
29         "value": name
30     }
31
32 def home(user_id, body):
33     """Returns a view to be published as the turbot home tab for user_id
34
35     The body argument is a dictionary as provided by the Slack request.
36     The return value is a dictionary suitable to be published to the
37     Slack views_publish API."""
38
39     return {
40         "type": "home",
41         "blocks": [
42             section(text("This is (or soon will be) a list of "
43                          + "available puzzle hunts)")),
44             actions(button("New hunt", "new_hunt"))
45         ]
46     }