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.
9 # pylint: disable=wrong-import-position
10 from AbstractCommand import AbstractCommand
11 class CommandGetText(AbstractCommand):
13 CONFIG = {"display_name": "somebot-command", "auto_complete": True,
14 "auto_complete_hint": "<permalink>",
16 CONFIG["auto_complete_desc"] = CONFIG["description"] = AbstractCommand.ICON_PRIVATE+"Get post-text of permalinked post (useful when wantng to get the latex source of a post)"
19 def on_POST(self, request, data):
20 msg_text = data['text'].strip().split(" ", 1)
23 splitpath = msg_text[0].strip().strip("/").split("/")
24 if splitpath[4] == "pl":
25 post = self.bot.api.get_post(splitpath[5])
27 request.respond_cmd_err("``/"+self.TRIGGER+"`` The first parameter is not a valid post-permalink or the permalinked post has been deleted.")
30 if post["channel_id"] != data["channel_id"]:
31 request.respond_cmd_err("``/"+self.TRIGGER+"`` Must be executed in the same channel as the permalinked post.")
34 request.respond_cmd_temp("## :white_check_mark: Success! :)\n```\n"+post["message"]+"\n```")