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:
21 request.respond_cmd_err("``/"+self.TRIGGER+"`` It seems like you did not supply any spoiler-text. (use --remove to remove)")
24 if len(msg_text[1]) > 15000:
25 request.respond_cmd_err("``/"+self.TRIGGER+"`` reason-text must be smaller than 15000 characters :(\nYour text is: "+str(len(msg_text[1]))+" characters long.")
29 splitpath = msg_text[0].strip().strip("/").split("/")
30 if splitpath[4] == "pl":
31 post = self.bot.api.get_post(splitpath[5])
33 request.respond_cmd_err("``/"+self.TRIGGER+"`` The first parameter is not a valid post-permalink or the permalinked post has been deleted.")
36 if post['user_id'] != data['user_id']:
37 request.respond_cmd_err("``/"+self.TRIGGER+"`` Is the permalinked post yours?")
40 if "cmd" in post["props"] and post["props"]["cmd"] != self.TRIGGER:
41 request.respond_cmd_err("``/"+self.TRIGGER+"`` The command **``/"+post["props"]["cmd"]+"``** already affects this post. Undo said command before applying this one.")
45 "text": "This post contains spoilers.",
47 "name": ":ghost: show me the spoilers :ghost:",
48 "integration": {"url": self.URL+"/interactive", "context": {"action": "show_spoiler", "spoiler":msg_text[1]}}
52 post["props"].update(dict({"attachments":att}))
54 if msg_text[1] in ["--abort", "--undo", "--remove", "--clear"]:
55 del post["props"]["cmd"]
56 del post["props"]["attachments"]
58 # self.bot.api.patch_post(splitpath[5], props=post["props"])
59 self.bot.api.update_post(splitpath[5], message=post["message"], is_pinned=post["is_pinned"], has_reactions=post["has_reactions"], props=post["props"])
60 request.respond_cmd_temp("## :white_check_mark: Success! :)")
63 def on_POST_interactive(self, request, data):
64 if data["context"]["action"] == "show_spoiler":
65 if data["context"]["spoiler"] != "":
66 request.respond_interactive_temp(data["context"]["spoiler"])
68 request.respond_interactive_err("Post has no stored spoiler text")