feat(utils/format_duration): add natural
This commit is contained in:
parent
74629ad984
commit
5333559b25
@ -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):
|
||||||
|
5
utils.py
5
utils.py
@ -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,8 +29,11 @@ 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)}")
|
||||||
|
|
||||||
|
if not natural or len(segments) <= 1:
|
||||||
return ", ".join(segments)
|
return ", ".join(segments)
|
||||||
|
|
||||||
|
return ", ".join(segments[:-1]) + f" and {segments[-1]}"
|
||||||
|
|
||||||
|
|
||||||
async def add_check_reaction(message):
|
async def add_check_reaction(message):
|
||||||
await message.add_reaction("✅")
|
await message.add_reaction("✅")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user