1 # Mattermost Bot module.
2 # Copyright (c) 2016-2024 by Someone <someone@somenet.org> (aka. Jan Vales <jan@jvales.net>)
3 # published under MIT-License
5 from inspect import cleandoc
11 # pylint: disable=wrong-import-position
12 from AbstractCommand import AbstractCommand
13 from AbstractPublicWS import AbstractPublicWS
14 class CommandFSOpen(AbstractCommand,AbstractPublicWS):
15 TRIGGER=NAME = "is-it-open"
16 CONFIG = {"display_name": "somebot-command", "auto_complete": True,
17 "auto_complete_hint": "",
19 USEINFO = CONFIG["auto_complete_desc"] = CONFIG["description"] = "Is fsinf open?"
21 cmd_state = msg_state = "Wos waas i" # unknown
24 def __init__(self, team_id, channel_id):
25 super().__init__(team_id)
26 self.channel_id = channel_id
29 def on_POST(self, request, data):
30 request.respond_cmd_temp("## Is FSInf open?\n\n"+self.bot.modules[list(self.bot.modules.keys())[0]][self.TRIGGER].cmd_state)
33 def on_public_POST(self, request, data):
34 if "ubahn_warnung" in data:
35 day=datetime.date.today()
36 if "## :white_check_mark: FsInf opening - Kumm ume!" in self.bot.modules[list(self.bot.modules.keys())[0]][self.TRIGGER].msg_state.strip() and not (day.weekday() == 5 or day.weekday() == 6 or holidays.AT().get(day)):
37 self.bot.api.create_post(self.channel_id, data["ubahn_warnung"], props={"somecleaner_autodelete":"day"})
40 if data["cmd_state"] != self.bot.modules[list(self.bot.modules.keys())[0]][self.TRIGGER].cmd_state or data["msg_state"] != self.bot.modules[list(self.bot.modules.keys())[0]][self.TRIGGER].msg_state:
41 if self.bot.modules[list(self.bot.modules.keys())[0]][self.TRIGGER].msg_state != "Wos waas i":
42 self.bot.api.create_post(self.channel_id, data["msg_state"], props={"somecleaner_autodelete":"day"})
43 if "## :white_check_mark: FsInf opening - Kumm ume!" in data["msg_state"]:
45 self.bot.api._post("/v4/commands/execute", data={"channel_id":"e7ed3sdhbbba5xi86uaqbc4f8o", "command":"/fsinf-control open"});
50 self.bot.api._post("/v4/commands/execute", data={"channel_id":"e7ed3sdhbbba5xi86uaqbc4f8o", "command":"/fsinf-control close"});
54 self.bot.modules[list(self.bot.modules.keys())[0]][self.TRIGGER].cmd_state=data["cmd_state"]
55 self.bot.modules[list(self.bot.modules.keys())[0]][self.TRIGGER].msg_state=data["msg_state"]
56 request.respond_public(200, {"status":"changed"})
58 request.respond_public(200, {"status":"unchanged"})