1 # Mattermost Bot module.
2 # Copyright (c) 2016-2021 by Someone <someone@somenet.org> (aka. Jan Vales <jan@jvales.net>)
3 # published under MIT-License
5 from inspect import cleandoc
10 from AbstractCommand import AbstractCommand
11 class CommandDrinkBindAccount(AbstractCommand):
12 TRIGGER = "drink-bind-account"
13 CONFIG = {"display_name": "somebot-command", "auto_complete": True,
14 "auto_complete_hint": "<drink-terminal-username> <drink-terminal-password>",
16 USEINFO = CONFIG["auto_complete_desc"] = CONFIG["description"] = "Bind your drink-terminal-account to your mattermost username."
19 def on_POST(self, request, data):
20 data['text'] = data['text'].strip()
21 mc_credentials = data['text'].split(" ", 2)
23 if data["text"] == "" or data["text"].lower() == "help" or len(mc_credentials) != 2:
24 request.cmd_respond_text_temp(cleandoc("""This command takes exactly 2 parameters: ``<drink-terminal-username> <drink-terminal-password``.
25 Once you passed the correct drink-terminal credentials your Mattermost account will be bound to that account.
26 The binding can be undone at the drink-terminal @ fsinf or via debug weg-front-end.
27 Once sucessfully bound you will be able to use ``/drink <drink-terminal-input-string>`` to pay for your drink.
31 handle = MCAPI.API("KEYBOARD", mc_credentials[0], mc_credentials[1])
32 handle.manage_token('add', 'MM_'+data["user_id"])
33 except MCAPI.APIException as e:
34 if e.message == 'CERR_AUTH_FAIL_ACCPWDRATE':
35 request.cmd_respond_text_temp(":stop_sign: Failed to bind Mattermost account to drink-terminal account: Invalid drink-terminal credentials :(")
36 elif e.message == 'CERR_FAILED_TO_ADD_TOKEN_EXISTING':
37 request.cmd_respond_text_temp(":warning: Failed to bind Mattermost account to drink-terminal account: Mattermost username is already bound to an account.")
39 request.cmd_respond_text_temp(":warning: Failed to bind Mattermost account to drink-terminal account: Unknown error: "+ e.message)
42 request.cmd_respond_text_temp(":white_check_mark: Sucessfully bound Mattermost account and drink-terminal account :)")
43 self.bot.debug_chan("``/drink-bind-account success: @"+data["user_name"]+'``')