]> git.cworth.org Git - turbot/blobdiff - turbot/blocks.py
Add an edit button next to each puzzle
[turbot] / turbot / blocks.py
index 5222e87e0433d248c2805ca0973396c411165dd2..cfef7f6a76ecf481224043d5a52b41565f46280b 100644 (file)
@@ -1,3 +1,8 @@
+def divider_block():
+    return {
+        "type": "divider"
+    }
+
 def text_block(body):
     return {
         "text": {
@@ -29,10 +34,19 @@ def button_block(label, name):
         "value": name
     }
 
-def input_block(label, name, placeholder):
+def accessory_block(main, accessory):
+    return {
+        **main,
+        "accessory": {
+            **accessory
+        }
+    }
+
+def input_block(label, name, placeholder, optional=False):
     return {
         "type": "input",
         "block_id": name,
+        "optional": optional,
         "element": {
             "type": "plain_text_input",
             "action_id": name,
@@ -46,3 +60,30 @@ def input_block(label, name, placeholder):
             "text": label
         }
     }
+
+def multi_select_block(label, name, placeholder, options, default=None):
+    return {
+        "type": "section",
+        "block_id": name,
+        "text": {
+            "type": "mrkdwn",
+            "text": "*{}*".format(label)
+        },
+        "accessory": {
+            "action_id": name,
+            "type": "multi_static_select",
+            "placeholder": {
+                "type": "plain_text",
+                "text": placeholder
+            },
+            "options": [
+                {
+                    "text": {
+                        "type": "plain_text",
+                        "text": option
+                    },
+                    "value": option
+                } for option in options
+            ]
+        }
+    }