]> git.somenet.org - pub/jan/mattermost-bot.git/blob - modules/CommandFSOpen.py
modified: modules/CommandFSOpen.py
[pub/jan/mattermost-bot.git] / modules / CommandFSOpen.py
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
4
5 from inspect import cleandoc
6
7 import datetime
8 import dateutil.parser
9 import holidays
10
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": "",
18              }
19     USEINFO = CONFIG["auto_complete_desc"] = CONFIG["description"] = "Is fsinf open?"
20
21     cmd_state = msg_state = "Wos waas i" # unknown
22
23     
24     def __init__(self, team_id, channel_id):
25         super().__init__(team_id)
26         self.channel_id = channel_id
27
28
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)
31
32
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"})
38             return
39
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"]:
44                     try:
45                         self.bot.api._post("/v4/commands/execute", data={"channel_id":"e7ed3sdhbbba5xi86uaqbc4f8o", "command":"/fsinf-control open"});
46                     except:
47                         pass
48                 else:
49                     try:
50                         self.bot.api._post("/v4/commands/execute", data={"channel_id":"e7ed3sdhbbba5xi86uaqbc4f8o", "command":"/fsinf-control close"});
51                     except:
52                         pass
53
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"})
57         else:
58             request.respond_public(200, {"status":"unchanged"})
59