From cd2546b39398283b4b5c84c46f551ee6c3a4e101 Mon Sep 17 00:00:00 2001 From: Someone Date: Tue, 30 Aug 2022 23:25:29 +0200 Subject: [PATCH] new file: modules/CommandCurriculaSave.py --- modules/CommandCurriculaSave.py | 45 +++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 modules/CommandCurriculaSave.py diff --git a/modules/CommandCurriculaSave.py b/modules/CommandCurriculaSave.py new file mode 100644 index 0000000..33d2a17 --- /dev/null +++ b/modules/CommandCurriculaSave.py @@ -0,0 +1,45 @@ +# Mattermost Bot module. +# Copyright (c) 2016-2022 by Someone (aka. Jan Vales ) +# published under MIT-License + +from inspect import cleandoc + + +# pylint: disable=wrong-import-position +from AbstractCommand import AbstractCommand +class CommandCurriculaSave(AbstractCommand): + TRIGGER = "curricula-save" + CONFIG = {"display_name": "somebot-command", "auto_complete": True, + "auto_complete_hint": "", + } + USEINFO = CONFIG["auto_complete_desc"] = CONFIG["description"] = "Generate save-code for curricula.fsinf.at." + + + def on_POST(self, request, data): + att = [{ + "text": "Delete this post.", + "color": "#ff0000", + "actions": [{ + "name": ":wastebasket: Delete this post and all associated data. :wastebasket:", + "integration": {"url": self.URL+"/interactive", "context": {"action": "delete_self"}} + }] + }] + + chan = self.bot.api.create_dm_channel_with(data['user_id']) + post = self.bot.api.create_post(chan['id'], "### Generating curricula.fsinf.at storage ...", {"attachments":att, "context":{"curricula_fsinf":{}}}) + + post["props"].update(dict({"attachments":att})) + + post["message"] = cleandoc(""" + ## ** https://curricula.fsinf.at storage** + Please copy the following code into the https://curricula.fsinf.at storage section. + # ``"""+post["id"]+"""`` + There are **``"""+str(len(post["props"]["context"]["curricula_fsinf"]))+""" bytes``** of additional data stored in this message. + """) + self.bot.api.update_post(post["id"], message=post["message"], is_pinned=post["is_pinned"], has_reactions=None, props=post["props"]) + request.respond(200, {}) + + + def on_POST_interactive(self, request, data): + if data["context"]["action"] == "delete_self": + self.bot.api.delete_post(data["post_id"]) -- 2.43.0