]> git.somenet.org - pub/jan/mattermost-bot.git/blob - core/CoreCommandHCF.py
modules/TACommandJoinAdmins.py
[pub/jan/mattermost-bot.git] / core / CoreCommandHCF.py
1 # Mattermost Bot.
2 #  Copyright (c) 2016-2022 by Someone <someone@somenet.org> (aka. Jan Vales <jan@jvales.net>)
3 #  published under MIT-License
4
5
6 import os
7 from inspect import cleandoc
8
9 # pylint: disable=wrong-import-position
10 from AbstractCommand import AbstractCommand
11 class CoreCommandHCF(AbstractCommand):
12     TRIGGER = "hcf"
13     CONFIG = {"display_name": "somebot-command", "auto_complete": False}
14     CONFIG["auto_complete_desc"] = CONFIG["description"] = AbstractCommand.ICON_PUBLIC+"Halt, but cleanup first."
15     USEINFO = cleandoc("""
16         ``/hcf`` - Halt and catch fire. Or actually halt but cleanup first.
17         Used to wipe all this bot user's commands and then fail horribly.
18         BOT_ADMIN only command.
19         """)
20
21
22     def on_POST(self, request, data):
23         self._require_bot_admin(data) # will throw an exception if not. (Dont try-except: Its handled up the stack.)
24
25         request.respond_cmd_chan("### Halting and catching fire. Bye...\n# :fire::fire::fire::fire::fire:")
26
27         # wipe all commands creted by this bot (not limited to this instance!)
28         for team in self.bot.api.get_teams():
29             for command in self.bot.api.list_custom_slash_commands_for_team(team["id"]):
30                 if command["display_name"] == "somebot-command":
31                     self.bot.api.delete_slash_command(command["id"])
32
33         # fail horribly.
34         self.bot.on_shutdown()
35         os._exit(42)