From e725b6ea2bc89c4a4c22402c8a774d83c424f5c9 Mon Sep 17 00:00:00 2001 From: Someone Date: Wed, 8 Dec 2021 19:38:38 +0100 Subject: [PATCH] [somebot] /spoiler --- modules/CommandSpoiler.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 modules/CommandSpoiler.py diff --git a/modules/CommandSpoiler.py b/modules/CommandSpoiler.py new file mode 100644 index 0000000..e1ec22e --- /dev/null +++ b/modules/CommandSpoiler.py @@ -0,0 +1,34 @@ +# Mattermost Bot module. +# Copyright (c) 2016-2021 by Someone (aka. Jan Vales ) +# published under MIT-License + + + +from AbstractCommand import AbstractCommand +class CommandSpoiler(AbstractCommand): + TRIGGER = "spoiler" + CONFIG = {"display_name": "somebot-command", "auto_complete": True, + "auto_complete_hint": "", + } + 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"]}) -- 2.43.0