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 CommandSpoilerAdv(AbstractCommand):
10 TRIGGER = "spoiler-adv"
11 CONFIG = {"display_name": "somebot-command", "auto_complete": True,
12 "auto_complete_hint": "<post permalink> <spoiler-text>",
14 USEINFO = CONFIG["auto_complete_desc"] = CONFIG["description"] = "Attach/replace spoiler-text on any of your messages. (--remove to remove) Must be able to edit said message."
17 def on_POST(self, request, data):
18 msg_text = data['text'].strip().split(" ", 1)
20 if len(msg_text[1]) > 15000:
21 request.cmd_respond_text_temp("``/spoiler-adv`` failed: Spoiler-text must be smaller than 15000 characters :(\nYour text is: "+str(len(msg_text[1]))+" characters long.")
25 splitpath = msg_text[0].strip().strip("/").split("/")
26 if splitpath[4] == "pl":
27 pl_post_id = splitpath[5]
29 request.cmd_respond_text_temp("``/spoiler-adv`` failed: The first parameter is not a valid post permalink. :(")
32 if len(msg_text) == 1:
33 request.cmd_respond_text_temp("``/spoiler-adv`` failed: It seems like you did not supply any spoiler-text. (use --remove to remove a spoiler text) :(")
36 post = self.bot.api.get_post(pl_post_id)
37 if post['user_id'] != data['user_id']:
38 request.cmd_respond_text_temp("``/spoiler-adv`` failed: Is the permalinked post yours? :(")
42 "text": "This post contains spoilers.",
44 "name": ":ghost: show me the spoilers :ghost:",
45 "integration": {"url": self.URL+"/interactive", "context": {"action": "show_spoiler", "spoiler":msg_text[1]}}
49 post["props"].update(dict({"attachments":att}))
51 if msg_text[1] == "--remove":
52 del post["props"]["attachments"]
54 self.bot.api.patch_post(splitpath[5], props=post["props"])
55 request.cmd_respond_text_temp("### ``Done.`` :)")
58 def on_POST_interactive(self, request, data):
59 if data["context"]["action"] == "show_spoiler":
60 request.respond(200, {"skip_slack_parsing":True, "ephemeral_text": data["context"]["spoiler"]})