]> git.cworth.org Git - turbot/blob - turbot/blocks.py
Add a multi-select round field to puzzle creation
[turbot] / turbot / blocks.py
1 def divider_block():
2     return {
3         "type": "divider"
4     }
5
6 def text_block(body):
7     return {
8         "text": {
9             "type": "mrkdwn",
10             "text": body
11         }
12     }
13
14 def section_block(block):
15     return {
16         "type": "section",
17         **block
18     }
19
20 def actions_block(*elements):
21     return {
22         "type": "actions",
23         "elements": list(elements)
24     }
25
26 def button_block(label, name):
27     return {
28         "type": "button",
29         "text": {
30             "type": "plain_text",
31             "text": label,
32             "emoji": True
33         },
34         "value": name
35     }
36
37 def input_block(label, name, placeholder, optional=False):
38     return {
39         "type": "input",
40         "block_id": name,
41         "optional": optional,
42         "element": {
43             "type": "plain_text_input",
44             "action_id": name,
45             "placeholder": {
46                 "type": "plain_text",
47                 "text": placeholder,
48             }
49         },
50         "label": {
51             "type": "plain_text",
52             "text": label
53         }
54     }
55
56 def multi_select_block(label, name, placeholder, options, default=None):
57     return {
58         "type": "section",
59         "block_id": name,
60         "text": {
61             "type": "mrkdwn",
62             "text": "*{}*".format(label)
63         },
64         "accessory": {
65             "action_id": name,
66             "type": "multi_static_select",
67             "placeholder": {
68                 "type": "plain_text",
69                 "text": placeholder
70             },
71             "options": [
72                 {
73                     "text": {
74                         "type": "plain_text",
75                         "text": option
76                     },
77                     "value": option
78                 } for option in options
79             ]
80         }
81     }