feat(utils/format_duration): add natural

This commit is contained in:
Ryan 2025-01-06 12:07:26 -05:00
parent 74629ad984
commit 5333559b25
Signed by: ErrorNoInternet
GPG Key ID: 2486BFB7B1E6A4A3
2 changed files with 7 additions and 3 deletions

View File

@ -175,7 +175,8 @@ async def queue_or_play(message, edited=False):
queued.player.duration if queued.player.duration else 0 queued.player.duration if queued.player.duration else 0
for queued in players[message.guild.id].queue for queued in players[message.guild.id].queue
] ]
) ),
natural=True,
) )
def embed(description): def embed(description):

View File

@ -4,7 +4,7 @@ import constants
from state import message_responses from state import message_responses
def format_duration(duration: int): def format_duration(duration: int, natural: bool = False):
def format_plural(noun, count): def format_plural(noun, count):
return noun if count == 1 else noun + "s" return noun if count == 1 else noun + "s"
@ -29,7 +29,10 @@ def format_duration(duration: int):
if duration > 0: if duration > 0:
segments.append(f"{duration} {format_plural('second', duration)}") segments.append(f"{duration} {format_plural('second', duration)}")
return ", ".join(segments) if not natural or len(segments) <= 1:
return ", ".join(segments)
return ", ".join(segments[:-1]) + f" and {segments[-1]}"
async def add_check_reaction(message): async def add_check_reaction(message):