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
5 # This command relies on the priviledged DB-Cleaner maint script.
10 # pylint: disable=wrong-import-position
11 from AbstractCommand import AbstractCommand
12 class CommandGetPostSrc(AbstractCommand):
13 TRIGGER = "get-post-src"
14 CONFIG = {"display_name": "somebot-command", "auto_complete": True,
15 "auto_complete_hint": "<permalink> [--channel]",
17 CONFIG["auto_complete_desc"] = CONFIG["description"] = AbstractCommand.ICON_PRIVATE+"Get the unparsed post message of permalinked post. Use --channel to post to channel."
20 def on_POST(self, request, data):
21 msg_text = data['text'].strip().split(" ", 1)
24 splitpath = msg_text[0].strip().strip("/").split("/")
25 if splitpath[4] == "pl":
26 post = self.bot.api.get_post(splitpath[5])
28 request.respond_cmd_err("``/"+self.TRIGGER+"`` The first parameter is not a valid post-permalink or the permalinked post has been deleted.")
31 if post["channel_id"] != data["channel_id"]:
32 request.respond_cmd_err("``/"+self.TRIGGER+"`` Must be executed in the same channel as the permalinked post.")
35 if len(msg_text) == 2 and re.match(r"^(-|—|–)+channel$", msg_text[1]):
36 request.respond_cmd_chan("``````\n"+post["message"]+"\n``````")
38 #request.respond_cmd_temp("## :white_check_mark: Success! :)\n``````\n"+post["message"]+"\n``````")
39 request.respond_cmd_temp("``````\n"+post["message"]+"\n``````")