From 95e44b60f42a248e2964cabc2b3b3407a71f559f Mon Sep 17 00:00:00 2001 From: Marc Di Luzio Date: Sat, 17 Aug 2024 00:00:47 +0100 Subject: [PATCH] Send dates with discord formats! --- matchy/cogs/matcher.py | 10 +++++----- matchy/util.py | 11 ++++------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/matchy/cogs/matcher.py b/matchy/cogs/matcher.py index 08a7f85..43fb840 100644 --- a/matchy/cogs/matcher.py +++ b/matchy/cogs/matcher.py @@ -70,7 +70,7 @@ class MatcherCog(commands.Cog): interaction.user.id, interaction.channel.id, until) await interaction.response.send_message( f"Sure thing {interaction.user.mention}!\n" - + f"Paused you until {util.format_day(until)}!", + + f"Paused you until {util.datetime_as_discord_time(until)}!", ephemeral=True, silent=True) @app_commands.command(description="List the matchees for this channel") @@ -88,8 +88,8 @@ class MatcherCog(commands.Cog): tasks = self.state.get_channel_match_tasks(interaction.channel.id) for (day, hour, min) in tasks: next_run = util.get_next_datetime(day, hour) - date_str = util.format_day(next_run) - msg += f"\nNext scheduled for {date_str} at {hour:02d}:00" + date_str = util.datetime_as_discord_time(next_run) + msg += f"\nNext scheduled for {date_str}" msg += f" with {min} members per group" await interaction.response.send_message(msg, ephemeral=True, silent=True) @@ -132,10 +132,10 @@ class MatcherCog(commands.Cog): logger.info("Scheduled new match task in %s with min %s weekday %s hour %s", channel_id, members_min, weekday, hour) next_run = util.get_next_datetime(weekday, hour) - date_str = util.format_day(next_run) + date_str = util.datetime_as_discord_time(next_run) await interaction.response.send_message( - f"Done :) Next run will be on {date_str} at {hour:02d}:00\n" + f"Done :) Next run will be on {date_str}\n" + "Cancel this by re-sending the command with cancel=True", ephemeral=True, silent=True) diff --git a/matchy/util.py b/matchy/util.py index 9c19306..5e9c707 100644 --- a/matchy/util.py +++ b/matchy/util.py @@ -9,13 +9,6 @@ def get_day_with_suffix(day): return str(day) + {1: 'st', 2: 'nd', 3: 'rd'}.get(day % 10, 'th') -def format_day(time: datetime) -> str: - """Format the a given datetime""" - num = get_day_with_suffix(time.day) - day = time.strftime("%a") - return f"{day} {num}" - - def format_list(list: list) -> str: """Format a list into a human readable format of foo, bar and bob""" if len(list) > 1: @@ -39,6 +32,10 @@ def get_next_datetime(weekday, hour) -> datetime: return next_date +def datetime_as_discord_time(time: datetime) -> str: + return f"" + + def iterate_all_shifts(list: list): """Yields each shifted variation of the input list""" yield list