feat(utils): add support for short formatting
This commit is contained in:
parent
be77e62e53
commit
6afbce5d8f
12
utils.py
12
utils.py
@ -35,9 +35,11 @@ class MessageInteractionWrapper:
|
|||||||
await self.response.edit_message(content=content, embed=embed, view=view)
|
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):
|
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 = []
|
segments = []
|
||||||
|
|
||||||
@ -60,10 +62,10 @@ def format_duration(duration: int, natural: bool = False):
|
|||||||
if duration > 0:
|
if duration > 0:
|
||||||
segments.append(f"{duration}{format_plural('second', duration)}")
|
segments.append(f"{duration}{format_plural('second', duration)}")
|
||||||
|
|
||||||
|
separator = " " if short else ", "
|
||||||
if not natural or len(segments) <= 1:
|
if not natural or len(segments) <= 1:
|
||||||
return ", ".join(segments)
|
return separator.join(segments)
|
||||||
|
return separator.join(segments[:-1]) + f" and {segments[-1]}"
|
||||||
return ", ".join(segments[:-1]) + f" and {segments[-1]}"
|
|
||||||
|
|
||||||
|
|
||||||
async def add_check_reaction(message):
|
async def add_check_reaction(message):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user