Skip to content
This repository has been archived by the owner on Aug 25, 2024. It is now read-only.

Commit

Permalink
Send dates with discord formats!
Browse files Browse the repository at this point in the history
  • Loading branch information
mdiluz committed Aug 16, 2024
1 parent 21d004e commit 95e44b6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
10 changes: 5 additions & 5 deletions matchy/cogs/matcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ async def pause(self, interaction: discord.Interaction, days: int | None = None)
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")
Expand All @@ -88,8 +88,8 @@ async def list(self, interaction: discord.Interaction):
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)
Expand Down Expand Up @@ -132,10 +132,10 @@ async def schedule(self,
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)

Expand Down
11 changes: 4 additions & 7 deletions matchy/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -39,6 +32,10 @@ def get_next_datetime(weekday, hour) -> datetime:
return next_date


def datetime_as_discord_time(time: datetime) -> str:
return f"<t:{int(time.timestamp())}>"


def iterate_all_shifts(list: list):
"""Yields each shifted variation of the input list"""
yield list
Expand Down

0 comments on commit 95e44b6

Please sign in to comment.