From c66f8031d25fdccaf8d783287a95aeee681526d6 Mon Sep 17 00:00:00 2001 From: Someone Date: Fri, 19 Jun 2020 01:32:13 +0200 Subject: [PATCH] [somebot] /spoiler --- somebot/modules/CommandSpoiler.py | 34 +++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 somebot/modules/CommandSpoiler.py diff --git a/somebot/modules/CommandSpoiler.py b/somebot/modules/CommandSpoiler.py new file mode 100644 index 0000000..f40ed02 --- /dev/null +++ b/somebot/modules/CommandSpoiler.py @@ -0,0 +1,34 @@ +# Mattermost Bot. +# Copyright (c) 2016-2020 by Someone (aka. Jan Vales ) +# published under MIT-License + + + +from AbstractCommand import * +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"]) > 7000: + request.cmd_respond_text_temp("``/spoiler`` failed: Spoiler-text must be smaller than 7000 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