]> git.somenet.org - pub/jan/mattermost-bot.git/blob - modules/CommandGetPostSrc.py
renamed: modules/CACommandModRemovePostText.py -> modules/CACommandModDelPostText.py
[pub/jan/mattermost-bot.git] / modules / CommandGetPostSrc.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 import re
9
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]",
16              }
17     CONFIG["auto_complete_desc"] = CONFIG["description"] = AbstractCommand.ICON_PRIVATE+"Get the unparsed post message of permalinked post. Use --channel to post to channel."
18
19
20     def on_POST(self, request, data):
21         msg_text = data['text'].strip().split(" ", 1)
22
23         try:
24             splitpath = msg_text[0].strip().strip("/").split("/")
25             if splitpath[4] == "pl":
26                 post = self.bot.api.get_post(splitpath[5])
27         except:
28             request.respond_cmd_err("``/"+self.TRIGGER+"`` The first parameter is not a valid post-permalink or the permalinked post has been deleted.")
29             return
30
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.")
33             return
34
35         if len(msg_text) == 2 and re.match(r"^(-|—|–)+channel$", msg_text[1]):
36             request.respond_cmd_chan("``````\n"+post["message"]+"\n``````")
37         else:
38             #request.respond_cmd_temp("## :white_check_mark: Success! :)\n``````\n"+post["message"]+"\n``````")
39             request.respond_cmd_temp("``````\n"+post["message"]+"\n``````")