From 264e7b5300c1eb5bd9191847c278813eaa55c3b2 Mon Sep 17 00:00:00 2001 From: Stijn De Clercq Date: Fri, 17 Feb 2023 00:35:40 +0100 Subject: [PATCH] Tidy up events a bit --- didier/cogs/discord.py | 7 ++++--- didier/utils/timer.py | 8 ++++++-- settings.py | 2 ++ 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/didier/cogs/discord.py b/didier/cogs/discord.py index ab00717..c7b63fb 100644 --- a/didier/cogs/discord.py +++ b/didier/cogs/discord.py @@ -63,10 +63,11 @@ class Discord(commands.Cog): return await self.client.log_error(f"Unable to find event with id {event_id}", log_to_discord=True) channel = self.client.get_channel(event.notification_channel) + human_readable_time = event.timestamp.strftime("%A, %B %d %Y - %H:%M") - embed = discord.Embed(title="Upcoming Events", colour=discord.Colour.blue()) - embed.add_field(name="Event", value=event.name, inline=False) - embed.description = event.description + embed = discord.Embed(title="Upcoming Event", colour=discord.Colour.blue()) + embed.description = f"{human_readable_time} ()" + embed.add_field(name=event.name, value=event.description, inline=False) await channel.send(embed=embed) diff --git a/didier/utils/timer.py b/didier/utils/timer.py index e5b216b..fda2cf7 100644 --- a/didier/utils/timer.py +++ b/didier/utils/timer.py @@ -1,9 +1,10 @@ import asyncio -from datetime import datetime +from datetime import datetime, timedelta from typing import Optional import discord.utils +import settings from database.crud.events import get_next_event from database.schemas import Event from didier import Didier @@ -12,6 +13,9 @@ from didier.utils.types.datetime import tz_aware_now __all__ = ["Timer"] +REMINDER_PREDELAY = timedelta(minutes=settings.REMINDER_PRE) + + class Timer: """Class for scheduled timers""" @@ -58,7 +62,7 @@ class Timer: async def end_timer(self, *, endtime: datetime, event_id: int): """Wait until a timer runs out, and then trigger an event to send the message""" - await discord.utils.sleep_until(endtime) + await discord.utils.sleep_until(endtime - REMINDER_PREDELAY) self.upcoming_timer = None self.upcoming_event_id = None self.client.dispatch("timer_end", event_id) diff --git a/settings.py b/settings.py index 3342ea0..32bd5e0 100644 --- a/settings.py +++ b/settings.py @@ -16,6 +16,7 @@ __all__ = [ "YEAR", "MENU_TIMEOUT", "EASTER_EGG_CHANCE", + "REMINDER_PRE", "POSTGRES_DB", "POSTGRES_USER", "POSTGRES_PASS", @@ -47,6 +48,7 @@ SEMESTER: int = env.int("SEMESTER", 2) YEAR: int = env.int("YEAR", 3) MENU_TIMEOUT: int = env.int("MENU_TIMEOUT", 30) EASTER_EGG_CHANCE: int = env.int("EASTER_EGG_CHANCE", 15) +REMINDER_PRE: int = env.int("REMINDER_PRE", 15) """Database""" # PostgreSQL