[somebot] /spoiler <spoiler-text>
authorSomeone <someone@somenet.org>
Wed, 8 Dec 2021 18:38:38 +0000 (19:38 +0100)
committerSomeone <someone@somenet.org>
Wed, 8 Dec 2021 18:38:38 +0000 (19:38 +0100)
modules/CommandSpoiler.py [new file with mode: 0644]

diff --git a/modules/CommandSpoiler.py b/modules/CommandSpoiler.py
new file mode 100644 (file)
index 0000000..e1ec22e
--- /dev/null
@@ -0,0 +1,34 @@
+# Mattermost Bot module.
+#  Copyright (c) 2016-2021 by Someone <someone@somenet.org> (aka. Jan Vales <jan@jvales.net>)
+#  published under MIT-License
+
+
+
+from AbstractCommand import AbstractCommand
+class CommandSpoiler(AbstractCommand):
+    TRIGGER = "spoiler"
+    CONFIG = {"display_name": "somebot-command", "auto_complete": True,
+              "auto_complete_hint": "<spoiler-text>",
+             }
+    USEINFO = CONFIG["auto_complete_desc"] = CONFIG["description"] = "Creates an empty post with spoiler-text. Use /spoiler-adv for advanced features (add to existing message/replace/remove)"
+
+
+    def on_POST(self, request, data):
+        if len(data["text"]) > 15000:
+            request.cmd_respond_text_temp("``/spoiler`` failed: Spoiler-text must be smaller than 15000 characters :(\nYour text is: "+str(len(data["text"]))+" characters long.")
+            return
+
+        att = [{
+            "text": "This post contains spoilers.",
+            "actions": [{
+                "name": ":ghost: show me the spoilers :ghost:",
+                "integration": {"url": self.URL+"/interactive", "context": {"action": "show_spoiler", "spoiler":data['text'].strip()}}
+                }]
+            }]
+
+        request.cmd_respond_text_chan("", {"attachments":att})
+
+
+    def on_POST_interactive(self, request, data):
+        if data["context"]["action"] == "show_spoiler":
+            request.respond(200, {"skip_slack_parsing":True, "ephemeral_text": data["context"]["spoiler"]})