]> git.somenet.org - pub/jan/mattermost-bot.git/blob - modules/CommandGetText.py
modules/CommandGetText.py
[pub/jan/mattermost-bot.git] / modules / CommandGetText.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 CommandGetText(AbstractCommand):
12     TRIGGER = "get-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 of permalinked post (useful when wantng to get the latex source of a post)"
17
18
19     def on_POST(self, request, data):
20         msg_text = data['text'].strip().split(" ", 1)
21
22         try:
23             splitpath = msg_text[0].strip().strip("/").split("/")
24             if splitpath[4] == "pl":
25                 post = self.bot.api.get_post(splitpath[5])
26         except:
27             request.respond_cmd_err("``/"+self.TRIGGER+"`` The first parameter is not a valid post-permalink or the permalinked post has been deleted.")
28             return
29
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.")
32             return
33
34         request.respond_cmd_temp("## :white_check_mark: Success! :)\n```\n"+post["message"]+"\n```")