feat(utils): add support for short formatting

This commit is contained in:
Ryan 2025-01-08 09:25:37 -05:00
parent be77e62e53
commit 6afbce5d8f
Signed by: ErrorNoInternet
GPG Key ID: 2486BFB7B1E6A4A3

View File

@ -35,9 +35,11 @@ class MessageInteractionWrapper:
await self.response.edit_message(content=content, embed=embed, view=view)
def format_duration(duration: int, natural: bool = False):
def format_duration(duration: int, natural: bool = False, short: bool = False):
def format_plural(noun, count):
return noun if count == 1 else noun + "s"
if short:
return noun[0]
return " " + (noun if count == 1 else noun + "s")
segments = []
@ -60,10 +62,10 @@ def format_duration(duration: int, natural: bool = False):
if duration > 0:
segments.append(f"{duration}{format_plural('second', duration)}")
separator = " " if short else ", "
if not natural or len(segments) <= 1:
return ", ".join(segments)
return ", ".join(segments[:-1]) + f" and {segments[-1]}"
return separator.join(segments)
return separator.join(segments[:-1]) + f" and {segments[-1]}"
async def add_check_reaction(message):