diff --git a/signalbot.py b/signalbot.py index d2da6ce3e9e3e0a4105cf16bd919710ea581b753..f1cf5b844bdca8c9a7582e2fd4ec39740cd13f7c 100755 --- a/signalbot.py +++ b/signalbot.py @@ -7,7 +7,7 @@ import logging import random import time import calendar -from datetime import date +from datetime import date, datetime, timedelta from threading import Thread import paho.mqtt.client as mqtt # EPL V1.0 @@ -117,7 +117,7 @@ def load_config(filename): def handle_action(timestamp, source, groupID, message, attachments): - if not message.startswith(".") or len(message) <= 2 or message[0:2] == "..": + if not message.startswith(".") or len(message) <= 2 or message[0:2] == ".." or message[0:3] == "._.": return print(timestamp) print(source) @@ -256,7 +256,6 @@ def dadjoke(msgDict): result = response.json() send(result["joke"], msgDict["receiver"]) - def links(msgDict): links = {} if msgDict["groupInfo"] is not None and "LINKS" in msgDict["groupInfo"]: @@ -488,17 +487,43 @@ def gg_remind_schichten(): def gg_remind_stundenzettel(): - today = date.today() + # Get the current date and time + now = datetime.datetime.now() + + # Calculate the last day of the current month + # If the current month is December (12), the next month would be January of the next year + # Otherwise, it's simply the next month of the current year + # We then subtract one day to get the last day of the current month + if now.month == 12: + last_day = datetime.datetime(now.year + 1, 1, 1) - datetime.timedelta(days=1) + else: + last_day = datetime.datetime(now.year, now.month + 1, 1) - datetime.timedelta(days=1) + + # Determine the last Tuesday of the month + # Here, we enter a loop that continues subtracting one day from the last day of the month + # until it hits a Tuesday. The weekday() function of a datetime object returns a number + # where Monday is 0 and Sunday is 6. Therefore, Tuesday is 1. We keep subtracting one day + # until last_day.weekday() equals 1, which signifies it's a Tuesday. + while last_day.weekday() != 1: + last_day -= datetime.timedelta(days=1) + + last_day -= datetime.timedelta(days=5) + gg_group = None for group in GROUPS: if group["NAME"] == "GGOffiziell": gg_group = group break - days_in_month= calendar.monthrange(today.year, today.month)[1] - delta = days_in_month - today.day - if 5 <= delta < 12: - send("Bitte schickt eure ausgefüllten Stundenzettel!", gg_group["ID"]) + if last_day == date.today().day: + send( + '''Bitte schickt eure ausgefüllten Stundenzettel! + • ihr müsst eure Abrechnungen jeden Monat sowohl an Sarah, als auch an Ben senden. + • sie müssen signiert und mit dem Kreuzchen im oberen Kästchen versehen sein + • eure Emails müssen einen Anhang haben (duh) + • der Betreff eurer Email sollte "Abrechnung Nachname Monat Jahr" beinhalten, das macht es leichter Sie zu finden. + • in die Zeile "Tätigkeit" muss bitte "aktivierende Arbeit im offenen Bereich" eingetragen werden. Nichts anderes!!1 + • sollten eure Abrechnungen mal falsch/ zu spät sein ist das kein Weltuntergang, dann gibt's das Geld einen Monat später - es verfällt nicht. Sollten sich dadurch persönliche Probleme ergeben sprecht uns bitte an, es gibt immer Lösungen.''', gg_group["ID"]) def start_schedule(): while True: