]> git.somenet.org - pub/jan/mattermost-bot.git/blob - modules/CACommandModGetPostText.py
core/AbstractCommand.py
[pub/jan/mattermost-bot.git] / modules / CACommandModGetPostText.py
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
4 #
5 # This command relies on the priviledged DB-Cleaner maint script.
6
7
8
9 # pylint: disable=wrong-import-position
10 from AbstractCommand import AbstractCommand
11 class CACommandModGetPostText(AbstractCommand):
12     TRIGGER = "mod-get-post-text"
13     CONFIG = {"display_name": "somebot-command", "auto_complete": True,
14               "auto_complete_hint": "<permalink>",
15              }
16     CONFIG["auto_complete_desc"] = CONFIG["description"] = AbstractCommand.ICON_PRIVATE+"Get post-text removed by /mod-remove-post-text. Run in same channel. [CHANNEL_ADMIN]"
17
18
19     def on_POST(self, request, data):
20         self._require_channel_admin(data) # will throw an exception if not. (Dont try-except: Its handled up the stack.)
21
22         msg_text = data['text'].strip().split(" ", 1)
23
24         try:
25             splitpath = msg_text[0].strip().strip("/").split("/")
26             if splitpath[4] == "pl":
27                 post = self.bot.api.get_post(splitpath[5])
28         except:
29             request.respond_cmd_err("``/"+self.TRIGGER+"`` The first parameter is not a valid post-permalink or the permalinked post has been deleted.")
30             return
31
32         if post["channel_id"] != data["channel_id"]:
33             request.respond_cmd_err("``/"+self.TRIGGER+"`` Must be executed in the same channel as the permalinked post.")
34             return
35
36         if "somebot_removed_post_text" not in post["props"]:
37             request.respond_cmd_err("``/"+self.TRIGGER+"`` The permalinked post has no known removed text.")
38             return
39
40         request.respond_cmd_temp("## :white_check_mark: Success! :)\n----\n\n"+post["props"]["somebot_removed_post_text"])