feat(commands/voice/queue): add --duration
This commit is contained in:
parent
a05c14263b
commit
e85d90fb36
@ -33,24 +33,6 @@ async def uptime(message):
|
||||
if args.since:
|
||||
await utils.reply(message, f"{round(start_time)}")
|
||||
else:
|
||||
format_plural = lambda noun, count: noun if count == 1 else noun + "s"
|
||||
|
||||
segments = []
|
||||
duration = int(time.time() - start_time)
|
||||
|
||||
days, duration = divmod(duration, 86400)
|
||||
if days >= 1:
|
||||
segments.append(f"{days} {format_plural('day', days)}")
|
||||
|
||||
hours, duration = divmod(duration, 3600)
|
||||
if hours >= 1:
|
||||
segments.append(f"{hours} {format_plural('hour', hours)}")
|
||||
|
||||
minutes, duration = divmod(duration, 60)
|
||||
if minutes >= 1:
|
||||
segments.append(f"{minutes} {format_plural('minute', minutes)}")
|
||||
|
||||
if duration > 0:
|
||||
segments.append(f"{duration} {format_plural('second', duration)}")
|
||||
|
||||
await utils.reply(message, f"up {', '.join(segments)}")
|
||||
await utils.reply(
|
||||
message, f"up {utils.format_duration(int(time.time() - start_time))}"
|
||||
)
|
||||
|
@ -1,9 +1,8 @@
|
||||
import arguments
|
||||
import youtubedl
|
||||
from state import client, players
|
||||
|
||||
import commands
|
||||
import utils
|
||||
import youtubedl
|
||||
from state import client, players
|
||||
|
||||
|
||||
async def queue_or_play(message):
|
||||
@ -61,10 +60,30 @@ async def queue_or_play(message):
|
||||
type=int,
|
||||
help="remove queued songs by queuer",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-d",
|
||||
"--duration",
|
||||
action="store_true",
|
||||
help="print duration of queued songs",
|
||||
)
|
||||
if not (args := await parser.parse_args(message, tokens)):
|
||||
return
|
||||
|
||||
if args.clear:
|
||||
if args.duration:
|
||||
queued_songs = players[message.guild.id].queue
|
||||
formatted_duration = utils.format_duration(
|
||||
sum(
|
||||
[
|
||||
queued.player.duration if queued.player.duration else 0
|
||||
for queued in queued_songs
|
||||
]
|
||||
)
|
||||
)
|
||||
await utils.reply(
|
||||
message,
|
||||
f"queue is **{formatted_duration or '0 seconds'}** long (**{len(queued_songs)}** songs queued)",
|
||||
)
|
||||
elif args.clear:
|
||||
players[message.guild.id].queue.clear()
|
||||
await utils.add_check_reaction(message)
|
||||
return
|
||||
|
22
utils.py
22
utils.py
@ -3,6 +3,28 @@ import disnake
|
||||
import constants
|
||||
|
||||
|
||||
def format_duration(duration: int):
|
||||
format_plural = lambda noun, count: noun if count == 1 else noun + "s"
|
||||
segments = []
|
||||
|
||||
days, duration = divmod(duration, 86400)
|
||||
if days >= 1:
|
||||
segments.append(f"{days} {format_plural('day', days)}")
|
||||
|
||||
hours, duration = divmod(duration, 3600)
|
||||
if hours >= 1:
|
||||
segments.append(f"{hours} {format_plural('hour', hours)}")
|
||||
|
||||
minutes, duration = divmod(duration, 60)
|
||||
if minutes >= 1:
|
||||
segments.append(f"{minutes} {format_plural('minute', minutes)}")
|
||||
|
||||
if duration > 0:
|
||||
segments.append(f"{duration} {format_plural('second', duration)}")
|
||||
|
||||
return ", ".join(segments)
|
||||
|
||||
|
||||
async def add_check_reaction(message):
|
||||
await message.add_reaction("✅")
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user