]> git.somenet.org - pub/jan/mattermost-bot.git/blob - modules/CommandSpoiler.py
core/CoreCommandUse.py
[pub/jan/mattermost-bot.git] / modules / CommandSpoiler.py
1 # Mattermost Bot module.
2 #  Copyright (c) 2016-2022 by Someone <someone@somenet.org> (aka. Jan Vales <jan@jvales.net>)
3 #  published under MIT-License
4
5
6
7 from AbstractCommand import AbstractCommand
8 class CommandSpoiler(AbstractCommand):
9     TRIGGER = "spoiler"
10     CONFIG = {"display_name": "somebot-command", "auto_complete": True,
11               "auto_complete_hint": "<spoiler-text>",
12              }
13     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)"
14
15
16     def on_POST(self, request, data):
17         if len(data["text"]) > 15000:
18             request.cmd_respond_text_temp("``/spoiler`` failed: Spoiler-text must be smaller than 15000 characters :(\nYour text is: "+str(len(data["text"]))+" characters long.")
19             return
20
21         att = [{
22             "text": "This post contains spoilers.",
23             "actions": [{
24                 "name": ":ghost: show me the spoilers :ghost:",
25                 "integration": {"url": self.URL+"/interactive", "context": {"action": "show_spoiler", "spoiler":data['text'].strip()}}
26                 }]
27             }]
28
29         request.cmd_respond_text_chan("", {"attachments":att})
30
31
32     def on_POST_interactive(self, request, data):
33         if data["context"]["action"] == "show_spoiler":
34             request.respond(200, {"skip_slack_parsing":True, "ephemeral_text": data["context"]["spoiler"]})