From 5333559b25883ac4c6a00bb0ebfe95ef22cf45e1 Mon Sep 17 00:00:00 2001 From: ErrorNoInternet Date: Mon, 6 Jan 2025 12:07:26 -0500 Subject: [PATCH] feat(utils/format_duration): add `natural` --- commands/voice.py | 3 ++- utils.py | 7 +++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/commands/voice.py b/commands/voice.py index 6d02aa8..b4412b7 100644 --- a/commands/voice.py +++ b/commands/voice.py @@ -175,7 +175,8 @@ async def queue_or_play(message, edited=False): queued.player.duration if queued.player.duration else 0 for queued in players[message.guild.id].queue ] - ) + ), + natural=True, ) def embed(description): diff --git a/utils.py b/utils.py index 7902b3e..b451748 100644 --- a/utils.py +++ b/utils.py @@ -4,7 +4,7 @@ import constants from state import message_responses -def format_duration(duration: int): +def format_duration(duration: int, natural: bool = False): def format_plural(noun, count): return noun if count == 1 else noun + "s" @@ -29,7 +29,10 @@ def format_duration(duration: int): if duration > 0: 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):