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
7 # pylint: disable=wrong-import-position
8 from AbstractCommand import AbstractCommand
9 class CommandSpoiler(AbstractCommand):
11 CONFIG = {"display_name": "somebot-command", "auto_complete": True,
12 "auto_complete_hint": "<spoiler-text>",
14 USEINFO = CONFIG["auto_complete_desc"] = CONFIG["description"] = AbstractCommand.ICON_PUBLIC+"Creates an empty post with spoiler-text. Use /spoiler-adv for advanced features (add to existing message/replace/remove)"
17 def on_POST(self, request, data):
18 msg_text = data['text'].strip()
20 if len(msg_text) == 1:
21 request.respond_cmd_err("``/"+self.TRIGGER+"`` It seems like you did not supply any spoiler-text. (use --remove to remove)")
23 if len(msg_text) > 15000:
24 request.respond_cmd_err("``/"+self.TRIGGER+"`` reason-text must be smaller than 15000 characters :(\nYour text is: "+str(len(msg_text))+" characters long.")
28 "text": "This post contains spoilers.",
30 "name": ":ghost: show me the spoilers :ghost:",
31 "integration": {"url": self.URL+"/interactive", "context": {"action": "show_spoiler", "spoiler":msg_text}}
35 request.respond_cmd_chan("", att=att)
38 def on_POST_interactive(self, request, data):
39 if data["context"]["action"] == "show_spoiler":
40 if data["context"]["spoiler"] != "":
41 request.respond_interactive_temp(data["context"]["spoiler"])
43 request.respond_interactive_err("Post has no stored spoiler text")