From: Someone Date: Tue, 3 Sep 2024 20:01:27 +0000 (+0200) Subject: modified: modules/CommandFSOpen.py X-Git-Url: https://git.somenet.org/pub/jan/mattermost-bot.git/commitdiff_plain?ds=sidebyside modified: modules/CommandFSOpen.py --- diff --git a/modules/CommandFSOpen.py b/modules/CommandFSOpen.py index 3023a79..a20c495 100644 --- a/modules/CommandFSOpen.py +++ b/modules/CommandFSOpen.py @@ -4,6 +4,9 @@ from inspect import cleandoc +import datetime +import dateutil.parser +import holidays # pylint: disable=wrong-import-position from AbstractCommand import AbstractCommand @@ -15,7 +18,7 @@ class CommandFSOpen(AbstractCommand,AbstractPublicWS): } USEINFO = CONFIG["auto_complete_desc"] = CONFIG["description"] = "Is fsinf open?" - cmd_state = live_state = "Unknown" + cmd_state = msg_state = "Wos waas i" # unknown def __init__(self, team_id, channel_id): @@ -28,9 +31,29 @@ class CommandFSOpen(AbstractCommand,AbstractPublicWS): def on_public_POST(self, request, data): - if data["cmd_state"] != self.bot.modules[list(self.bot.modules.keys())[0]][self.TRIGGER].cmd_state or data["live_state"] != self.bot.modules[list(self.bot.modules.keys())[0]][self.TRIGGER].live_state: + if "ubahn_warnung" in data: + day=datetime.date.today() + 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)): + self.bot.api.create_post(self.channel_id, data["ubahn_warnung"], props={"somecleaner_autodelete":"day"}) + return + + 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: + if self.bot.modules[list(self.bot.modules.keys())[0]][self.TRIGGER].msg_state != "Wos waas i": + self.bot.api.create_post(self.channel_id, data["msg_state"], props={"somecleaner_autodelete":"day"}) + if "## :white_check_mark: FsInf opening - Kumm ume!" in data["msg_state"]: + try: + self.bot.api._post("/v4/commands/execute", data={"channel_id":"e7ed3sdhbbba5xi86uaqbc4f8o", "command":"/fsinf-control open"}); + except: + pass + else: + try: + self.bot.api._post("/v4/commands/execute", data={"channel_id":"e7ed3sdhbbba5xi86uaqbc4f8o", "command":"/fsinf-control close"}); + except: + pass + self.bot.modules[list(self.bot.modules.keys())[0]][self.TRIGGER].cmd_state=data["cmd_state"] - self.bot.modules[list(self.bot.modules.keys())[0]][self.TRIGGER].live_state=data["live_state"] - self.bot.api.create_post(self.channel_id, data["live_state"]) - request.respond_public(200, {"status":"ok"}) + self.bot.modules[list(self.bot.modules.keys())[0]][self.TRIGGER].msg_state=data["msg_state"] + request.respond_public(200, {"status":"changed"}) + else: + request.respond_public(200, {"status":"unchanged"})