]> git.somenet.org - pub/jan/mattermost-bot.git/blob - modules/CommandCurriculaSave.py
core/AbstractCommand.py
[pub/jan/mattermost-bot.git] / modules / CommandCurriculaSave.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 from inspect import cleandoc
6
7
8 # pylint: disable=wrong-import-position
9 from AbstractCommand import AbstractCommand
10 class CommandCurriculaSave(AbstractCommand):
11     TRIGGER = "curricula-save"
12     CONFIG = {"display_name": "somebot-command", "auto_complete": True,
13               "auto_complete_hint": "",
14              }
15     USEINFO = CONFIG["auto_complete_desc"] = CONFIG["description"] = "Generate save-code for curricula.fsinf.at."
16
17
18     def on_POST(self, request, data):
19         att = [{
20             "text": "Delete this post.",
21             "color": "#ff0000",
22             "actions": [{
23                 "name": ":wastebasket: Delete this post and all associated data. :wastebasket:",
24                 "integration": {"url": self.URL+"/interactive", "context": {"action": "delete_self"}}
25                 }]
26             }]
27
28         chan = self.bot.api.create_dm_channel_with(data['user_id'])
29         post = self.bot.api.create_post(chan['id'], "### Generating curricula.fsinf.at storage ...", {"attachments":att, "context":{"curricula_fsinf":{}}})
30
31         post["props"].update(dict({"attachments":att}))
32
33         post["message"] = cleandoc("""
34             ## ** https://curricula.fsinf.at storage**
35             Please copy the following code into the https://curricula.fsinf.at storage section.
36             # ``"""+post["id"]+"""``
37             There are **``"""+str(len(post["props"]["context"]["curricula_fsinf"]))+""" bytes``** of additional data stored in this message.
38             """)
39         self.bot.api.update_post(post["id"], message=post["message"], is_pinned=post["is_pinned"], has_reactions=None, props=post["props"])
40         request.respond(200, {})
41
42
43     def on_POST_interactive(self, request, data):
44         if data["context"]["action"] == "delete_self":
45             self.bot.api.delete_post(data["post_id"])