]> git.somenet.org - pub/jan/mattermost.git/blob - somebot/core/CoreCommandHCF.py
[somebot] WS:Onboarding
[pub/jan/mattermost.git] / somebot / core / CoreCommandHCF.py
1 # Mattermost Bot.
2 #  Copyright (c) 2016-2020 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 from AbstractCommand import AbstractCommand
10 class CoreCommandHCF(AbstractCommand):
11     TRIGGER = "hcf"
12     CONFIG = {"display_name": "somebot-command", "auto_complete": False}
13     CONFIG["auto_complete_desc"] = CONFIG["description"] = "Halt, but cleanup first."
14     USEINFO = cleandoc("""
15         ``/hcf`` Halt and catch fire. Or actually halt but cleanup first.
16         Used to wipe all this bot user's commands and then fail horribly.
17         """)
18
19
20     def on_POST(self, request, data):
21         self._require_bot_admin(data) # will throw an exception if not. (Dont try-except: Its handled up the stack.)
22
23         request.cmd_respond_text_chan("### Halting and catching fire. bye...")
24
25         # wipe all commands creted by this bot (not limited to this instance!)
26         for team in self.bot.api.get_teams():
27             for command in self.bot.api.list_custom_slash_commands_per_team(team["id"]):
28                 if command["display_name"] == "somebot-command":
29                     self.bot.api.delete_slash_command(command["id"])
30
31         # fail horribly.
32         self.bot.shutdown()
33         os._exit(42)