Tidy up events a bit

pull/169/head
Stijn De Clercq 2023-02-17 00:35:40 +01:00
parent c570cd2db2
commit 264e7b5300
3 changed files with 12 additions and 5 deletions

View File

@ -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} (<t:{round(event.timestamp.timestamp())}:R>)"
embed.add_field(name=event.name, value=event.description, inline=False)
await channel.send(embed=embed)

View File

@ -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)

View File

@ -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