[somebot] /hcf
authorSomeone <someone@somenet.org>
Thu, 18 Jun 2020 23:32:13 +0000 (01:32 +0200)
committerSomeone <someone@somenet.org>
Thu, 18 Jun 2020 23:32:13 +0000 (01:32 +0200)
somebot/core/CoreCommandHCF.py [new file with mode: 0644]

diff --git a/somebot/core/CoreCommandHCF.py b/somebot/core/CoreCommandHCF.py
new file mode 100644 (file)
index 0000000..d702220
--- /dev/null
@@ -0,0 +1,33 @@
+# Mattermost Bot.
+#  Copyright (c) 2016-2020 by Someone <someone@somenet.org> (aka. Jan Vales <jan@jvales.net>)
+#  published under MIT-License
+
+
+import os
+from inspect import cleandoc
+
+from AbstractCommand import AbstractCommand
+class CoreCommandHCF(AbstractCommand):
+    TRIGGER = "hcf"
+    CONFIG = {"display_name": "somebot-command", "auto_complete": False}
+    CONFIG["auto_complete_desc"] = CONFIG["description"] = "Halt, but cleanup first."
+    USEINFO = cleandoc("""
+        ``/hcf`` Halt and catch fire. Or actually halt but cleanup first.
+        Used to wipe all this bot user's commands and then fail horribly.
+        """)
+
+
+    def on_POST(self, request, data):
+        self._require_bot_admin(data) # will throw an exception if not. (Dont try-except: Its handled up the stack.)
+
+        request.cmd_respond_text_chan("### Halting and catching fire. bye...")
+
+        # wipe all commands creted by this bot (not limited to this instance!)
+        for team in self.bot.api.get_teams():
+            for command in self.bot.api.list_custom_slash_commands_per_team(team["id"]):
+                if command["display_name"] == "somebot-command":
+                    self.bot.api.delete_slash_command(command["id"])
+
+        # fail horribly.
+        self.bot.shutdown()
+        os._exit(42)