From a61990ca637d92a0380b5e874f87ec1b381b347c Mon Sep 17 00:00:00 2001 From: Someone Date: Wed, 8 Dec 2021 19:38:38 +0100 Subject: [PATCH] [somebot] /hcf --- core/CoreCommandHCF.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 core/CoreCommandHCF.py diff --git a/core/CoreCommandHCF.py b/core/CoreCommandHCF.py new file mode 100644 index 0000000..ebbbd6e --- /dev/null +++ b/core/CoreCommandHCF.py @@ -0,0 +1,34 @@ +# Mattermost Bot. +# Copyright (c) 2016-2021 by Someone (aka. Jan Vales ) +# 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. + BOT_ADMIN only command. + """) + + + 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_for_team(team["id"]): + if command["display_name"] == "somebot-command": + self.bot.api.delete_slash_command(command["id"]) + + # fail horribly. + self.bot.on_shutdown() + os._exit(42) -- 2.43.0