]> git.somenet.org - pub/jan/mattermost-bot.git/commitdiff
modified: modules/CommandFSOpen.py master
authorSomeone <someone@somenet.org>
Tue, 3 Sep 2024 20:01:27 +0000 (22:01 +0200)
committerSomeone <someone@somenet.org>
Tue, 3 Sep 2024 20:01:27 +0000 (22:01 +0200)
modules/CommandFSOpen.py

index 3023a797143cd7070383c0cba43f009ceb2ee869..a20c495cae86913bc266c77e51364887f0be2734 100644 (file)
@@ -4,6 +4,9 @@
 
 from inspect import cleandoc
 
 
 from inspect import cleandoc
 
+import datetime
+import dateutil.parser
+import holidays
 
 # pylint: disable=wrong-import-position
 from AbstractCommand import AbstractCommand
 
 # 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?"
 
              }
     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):
 
     
     def __init__(self, team_id, channel_id):
@@ -28,9 +31,29 @@ class CommandFSOpen(AbstractCommand,AbstractPublicWS):
 
 
     def on_public_POST(self, request, data):
 
 
     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].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"})