From 8a76b4616508789217bc3044778b231ba0b2abd0 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Sat, 2 Dec 2023 15:15:38 +0100 Subject: [PATCH] Improved event time loading #410 --- bot/src/modules/base/service/event_service.py | 19 +++++++++----- bot/src/modules/base/thread/__init__.py | 26 ------------------- 2 files changed, 13 insertions(+), 32 deletions(-) delete mode 100644 bot/src/modules/base/thread/__init__.py diff --git a/bot/src/modules/base/service/event_service.py b/bot/src/modules/base/service/event_service.py index 7e298d9d..63066353 100644 --- a/bot/src/modules/base/service/event_service.py +++ b/bot/src/modules/base/service/event_service.py @@ -74,7 +74,8 @@ class EventService: active_event.participants.append(user) def _append_interval(self, interval: ScheduledEventIntervalEnum, ts: datetime) -> datetime: - if ts >= datetime.now(): + now = datetime.now().replace(tzinfo=ZoneInfo("Europe/Berlin")) + if ts >= now: return ts if interval == ScheduledEventIntervalEnum.daily: @@ -90,7 +91,7 @@ class EventService: elif interval == ScheduledEventIntervalEnum.yearly: ts = ts + timedelta(days=365) - while ts < datetime.now(): + while ts < now: ts = self._append_interval(interval, ts) return ts @@ -114,12 +115,18 @@ class EventService: kwargs["channel"] = guild.get_channel(scheduled_event.channel_id) if scheduled_event.start_time is not None: - scheduled_event.start_time = self._append_interval(scheduled_event.interval, scheduled_event.start_time) - kwargs["start_time"] = scheduled_event.start_time.replace(tzinfo=ZoneInfo("Europe/Berlin")) + start_time = self._append_interval( + scheduled_event.interval, scheduled_event.start_time.replace(tzinfo=ZoneInfo("Europe/Berlin")) + ) + kwargs["start_time"] = start_time + scheduled_event.start_time = scheduled_event.start_time.replace(tzinfo=None) if scheduled_event.end_time is not None: - scheduled_event.end_time = self._append_interval(scheduled_event.interval, scheduled_event.end_time) - kwargs["end_time"] = scheduled_event.end_time.replace(tzinfo=ZoneInfo("Europe/Berlin")) + end_time = self._append_interval( + scheduled_event.interval, scheduled_event.end_time.replace(tzinfo=ZoneInfo("Europe/Berlin")) + ) + kwargs["end_time"] = end_time + scheduled_event.end_time = scheduled_event.end_time.replace(tzinfo=None) kwargs["entity_type"] = scheduled_event.entity_type if scheduled_event.location is not None: diff --git a/bot/src/modules/base/thread/__init__.py b/bot/src/modules/base/thread/__init__.py deleted file mode 100644 index 90932b6a..00000000 --- a/bot/src/modules/base/thread/__init__.py +++ /dev/null @@ -1,26 +0,0 @@ -# -*- coding: utf-8 -*- - -""" -bot sh-edraft.de Discord bot -~~~~~~~~~~~~~~~~~~~ - -Discord bot for customers of sh-edraft.de - -:copyright: (c) 2022 - 2023 sh-edraft.de -:license: MIT, see LICENSE for more details. - -""" - -__title__ = "modules.base.thread" -__author__ = "Sven Heidemann" -__license__ = "MIT" -__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de" -__version__ = "1.2.2" - -from collections import namedtuple - - -# imports - -VersionInfo = namedtuple("VersionInfo", "major minor micro") -version_info = VersionInfo(major="1", minor="2", micro="2")