From ad63f829fd170b9808e66784069b403e41d5ec6e Mon Sep 17 00:00:00 2001
From: Someone <someone@somenet.org>
Date: Thu, 27 Jan 2022 12:50:24 +0100
Subject: [PATCH] modules/CommandGetText.py

---
 modules/CommandGetText.py | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
 create mode 100644 modules/CommandGetText.py

diff --git a/modules/CommandGetText.py b/modules/CommandGetText.py
new file mode 100644
index 0000000..8738063
--- /dev/null
+++ b/modules/CommandGetText.py
@@ -0,0 +1,38 @@
+# Mattermost Bot module.
+#  Copyright (c) 2016-2022 by Someone <someone@somenet.org> (aka. Jan Vales <jan@jvales.net>)
+#  published under MIT-License
+#
+# This command relies on the priviledged DB-Cleaner maint script.
+
+
+
+# pylint: disable=wrong-import-position
+from AbstractCommand import AbstractCommand
+class CommandGetText(AbstractCommand):
+    TRIGGER = "get-text"
+    CONFIG = {"display_name": "somebot-command", "auto_complete": True,
+              "auto_complete_hint": "<permalink>",
+             }
+    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)"
+
+
+    def on_POST(self, request, data):
+        msg_text = data['text'].strip().split(" ", 1)
+
+        try:
+            splitpath = msg_text[0].strip().strip("/").split("/")
+            if splitpath[4] == "pl":
+                post = self.bot.api.get_post(splitpath[5])
+        except:
+            request.respond_cmd_err("``/"+self.TRIGGER+"`` The first parameter is not a valid post-permalink or the permalinked post has been deleted.")
+            return
+
+        if post["channel_id"] != data["channel_id"]:
+            request.respond_cmd_err("``/"+self.TRIGGER+"`` Must be executed in the same channel as the permalinked post.")
+            return
+
+        if "somebot_removed_post_text" not in post["props"]:
+            request.respond_cmd_err("``/"+self.TRIGGER+"`` The permalinked post has no known removed text.")
+            return
+
+        request.respond_cmd_temp("## :white_check_mark: Success! :)\n```\n"+post["message"]+"\n```")
-- 
2.43.0