Merge pull request #13 from mdiluz/date-formats
Send dates with discord formats
This commit is contained in:
commit
eeede2e74a
2 changed files with 9 additions and 12 deletions
|
@ -70,7 +70,7 @@ class MatcherCog(commands.Cog):
|
||||||
interaction.user.id, interaction.channel.id, until)
|
interaction.user.id, interaction.channel.id, until)
|
||||||
await interaction.response.send_message(
|
await interaction.response.send_message(
|
||||||
f"Sure thing {interaction.user.mention}!\n"
|
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)
|
ephemeral=True, silent=True)
|
||||||
|
|
||||||
@app_commands.command(description="List the matchees for this channel")
|
@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)
|
tasks = self.state.get_channel_match_tasks(interaction.channel.id)
|
||||||
for (day, hour, min) in tasks:
|
for (day, hour, min) in tasks:
|
||||||
next_run = util.get_next_datetime(day, hour)
|
next_run = util.get_next_datetime(day, hour)
|
||||||
date_str = util.format_day(next_run)
|
date_str = util.datetime_as_discord_time(next_run)
|
||||||
msg += f"\nNext scheduled for {date_str} at {hour:02d}:00"
|
msg += f"\nNext scheduled for {date_str}"
|
||||||
msg += f" with {min} members per group"
|
msg += f" with {min} members per group"
|
||||||
|
|
||||||
await interaction.response.send_message(msg, ephemeral=True, silent=True)
|
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",
|
logger.info("Scheduled new match task in %s with min %s weekday %s hour %s",
|
||||||
channel_id, members_min, weekday, hour)
|
channel_id, members_min, weekday, hour)
|
||||||
next_run = util.get_next_datetime(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(
|
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",
|
+ "Cancel this by re-sending the command with cancel=True",
|
||||||
ephemeral=True, silent=True)
|
ephemeral=True, silent=True)
|
||||||
|
|
||||||
|
|
|
@ -9,13 +9,6 @@ def get_day_with_suffix(day):
|
||||||
return str(day) + {1: 'st', 2: 'nd', 3: 'rd'}.get(day % 10, 'th')
|
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:
|
def format_list(list: list) -> str:
|
||||||
"""Format a list into a human readable format of foo, bar and bob"""
|
"""Format a list into a human readable format of foo, bar and bob"""
|
||||||
if len(list) > 1:
|
if len(list) > 1:
|
||||||
|
@ -39,6 +32,10 @@ def get_next_datetime(weekday, hour) -> datetime:
|
||||||
return next_date
|
return next_date
|
||||||
|
|
||||||
|
|
||||||
|
def datetime_as_discord_time(time: datetime) -> str:
|
||||||
|
return f"<t:{int(time.timestamp())}>"
|
||||||
|
|
||||||
|
|
||||||
def iterate_all_shifts(list: list):
|
def iterate_all_shifts(list: list):
|
||||||
"""Yields each shifted variation of the input list"""
|
"""Yields each shifted variation of the input list"""
|
||||||
yield list
|
yield list
|
||||||
|
|
Loading…
Add table
Reference in a new issue