1 # Mattermost Bot module.
2 # Copyright (c) 2016-2022 by Someone <someone@somenet.org> (aka. Jan Vales <jan@jvales.net>)
3 # Copyright (c) 2020 by Sabrina -- minor rewording of the message
4 # published under MIT-License
9 from inspect import cleandoc
12 # pylint: disable=wrong-import-position
13 from AbstractCommand import AbstractCommand
14 class CommandFreeDrink(AbstractCommand):
15 TRIGGER = "free-drink"
16 CONFIG = {"display_name": "somebot-command", "auto_complete": True,
17 "auto_complete_hint": "",
19 USEINFO = CONFIG["auto_complete_desc"] = CONFIG["description"] = AbstractCommand.ICON_PRIVATE+"used to log our free drink for the onboarding event."
22 def __init__(self, team_id, datadir, email_rex_str):
23 super().__init__(team_id)
24 self.datadir = datadir
25 self.email_rex = re.compile(email_rex_str)
28 def on_POST(self, request, data):
29 user = self.bot.api.get_user(data["user_id"])
31 if self.email_rex.match(user["email"]):
32 filename = self.datadir + data["user_id"]
33 if not os.path.isfile(filename):
34 with open(filename, "w") as file:
35 file.write(data["user_id"]+" -- "+data["user_name"]+" -- "+datetime.datetime.now().isoformat()+"\n")
36 request.respond_cmd_temp(cleandoc("""
37 ## :white_check_mark: Success! :)
38 #### Enjoy your drink!
40 #self.bot.api.add_user_to_channel("m5sik9jwmib6mfpnpcmsib1h7w", data["user_id"])
41 self.bot.debug_chan(":white_check_mark: ``/free-drink`` logged: ``"+data["user_name"]+"``")
44 request.respond_cmd_err("It seems you already logged your free drink before.")
45 self.bot.debug_chan(":x: ``/free-drink`` already logged for: ``"+data["user_name"]+"``")
47 request.respond_cmd_err("You are not eligible for a free drink. If you think this was a mistake, contact @someone")
48 self.bot.debug_chan(":x: ``/free-drink`` not eligible: ``"+data["user_name"]+"``")