diff --git a/commands/voice/__init__.py b/commands/voice/__init__.py index 58a0dba..530a6ec 100644 --- a/commands/voice/__init__.py +++ b/commands/voice/__init__.py @@ -1,6 +1,5 @@ from .channel import join, leave -from .playback import fast_forward, pause, resume, volume -from .playing import playing +from .playback import fast_forward, pause, playing, resume, volume from .queue import queue_or_play, skip from .utils import remove_queued diff --git a/commands/voice/playback.py b/commands/voice/playback.py index 4ac108a..34218bf 100644 --- a/commands/voice/playback.py +++ b/commands/voice/playback.py @@ -1,10 +1,62 @@ import arguments import commands +import constants +import disnake_paginator import utils +from state import players from .utils import command_allowed +async def playing(message): + tokens = commands.tokenize(message.content) + parser = arguments.ArgumentParser( + tokens[0], "get information about the currently playing song" + ) + parser.add_argument( + "-d", + "--description", + action="store_true", + help="get the description", + ) + if not (args := await parser.parse_args(message, tokens)): + return + + if not command_allowed(message, immutable=True): + return + + if source := message.guild.voice_client.source: + if args.description: + if description := source.description: + paginator = disnake_paginator.ButtonPaginator( + invalid_user_function=utils.invalid_user_handler, + color=constants.EMBED_COLOR, + title=source.title, + segments=disnake_paginator.split(description), + ) + for embed in paginator.embeds: + embed.url = source.original_url + await paginator.start(utils.MessageInteractionWrapper(message)) + else: + await utils.reply( + message, + source.description or "no description found!", + ) + return + + await utils.reply( + message, + embed=players[message.guild.id].current.embed( + is_paused=message.guild.voice_client.is_paused() + ), + ) + else: + await utils.reply( + message, + "nothing is playing!", + ) + + async def resume(message): if not command_allowed(message): return diff --git a/commands/voice/playing.py b/commands/voice/playing.py deleted file mode 100644 index f8a5ac0..0000000 --- a/commands/voice/playing.py +++ /dev/null @@ -1,75 +0,0 @@ -import disnake -import disnake_paginator - -import arguments -import commands -import constants -import utils -import youtubedl -from state import players - -from .utils import command_allowed - - -async def playing(message): - tokens = commands.tokenize(message.content) - parser = arguments.ArgumentParser( - tokens[0], "get information about the currently playing song" - ) - parser.add_argument( - "-d", - "--description", - action="store_true", - help="get the description", - ) - if not (args := await parser.parse_args(message, tokens)): - return - - if not command_allowed(message, immutable=True): - return - - if source := message.guild.voice_client.source: - if args.description: - if description := source.description: - paginator = disnake_paginator.ButtonPaginator( - invalid_user_function=utils.invalid_user_handler, - color=constants.EMBED_COLOR, - title=source.title, - segments=disnake_paginator.split(description), - ) - for embed in paginator.embeds: - embed.url = source.original_url - await paginator.start(utils.MessageInteractionWrapper(message)) - else: - await utils.reply( - message, - source.description or "no description found!", - ) - return - - progress = source.original.progress / source.duration - embed = disnake.Embed( - color=constants.EMBED_COLOR, - title=source.title, - url=source.original_url, - description=f"{'⏸️ ' if message.guild.voice_client.is_paused() else ''}" - f"`[{'#'*int(progress * constants.BAR_LENGTH)}{'-'*int((1 - progress) * constants.BAR_LENGTH)}]` " - f"**{youtubedl.format_duration(int(source.original.progress))}** / **{youtubedl.format_duration(source.duration)}** (**{round(progress * 100)}%**)", - ) - embed.add_field(name="Volume", value=f"{int(source.volume*100)}%") - embed.add_field(name="Views", value=f"{source.view_count:,}") - embed.add_field( - name="Queuer", - value=players[message.guild.id].current.trigger_message.author.mention, - ) - embed.set_image(source.thumbnail_url) - - await utils.reply( - message, - embed=embed, - ) - else: - await utils.reply( - message, - "nothing is playing!", - ) diff --git a/commands/voice/utils.py b/commands/voice/utils.py index 336a910..9ff0a49 100644 --- a/commands/voice/utils.py +++ b/commands/voice/utils.py @@ -1,9 +1,7 @@ -import constants import disnake -import youtubedl -from state import client, players import utils +from state import client, players def play_after_callback(e, message, once): @@ -30,20 +28,7 @@ def play_next(message, once=False, first=False): queued.player, after=lambda e: play_after_callback(e, message, once) ) - embed = disnake.Embed( - color=constants.EMBED_COLOR, - title=queued.player.title, - url=queued.player.original_url, - description=f"`[{'-'*constants.BAR_LENGTH}]` **{youtubedl.format_duration(0)}** / **{youtubedl.format_duration(queued.player.duration)}**", - ) - embed.add_field(name="Volume", value=f"{int(queued.player.volume*100)}%") - embed.add_field(name="Views", value=f"{queued.player.view_count:,}") - embed.add_field( - name="Queuer", - value=players[message.guild.id].current.trigger_message.author.mention, - ) - embed.set_image(queued.player.thumbnail_url) - + embed = queued.embed() if first and len(players[message.guild.id].queue) == 0: client.loop.create_task(utils.reply(message, embed=embed)) else: diff --git a/constants.py b/constants.py index b43a152..ac15c0a 100644 --- a/constants.py +++ b/constants.py @@ -26,6 +26,11 @@ RELOADABLE_MODULES = [ "commands.tools", "commands.utils", "commands.voice", + "commands.voice.channel", + "commands.voice.playback", + "commands.voice.playing", + "commands.voice.queue", + "commands.voice.utils", "constants", "core", "events", diff --git a/youtubedl.py b/youtubedl.py index 729ee9b..ae9c403 100644 --- a/youtubedl.py +++ b/youtubedl.py @@ -99,6 +99,34 @@ class QueuedSong: + (f" (<@{self.trigger_message.author.id}>)" if show_queuer else "") ) + def embed(self, is_paused=False): + progress = 0 + if self.player.duration: + progress = self.player.original.progress / self.player.duration + + embed = disnake.Embed( + color=constants.EMBED_COLOR, + title=self.player.title, + url=self.player.original_url, + description=( + f"{'⏸️ ' if is_paused else ''}" + f"`[{'#'*int(progress * constants.BAR_LENGTH)}{'-'*int((1 - progress) * constants.BAR_LENGTH)}]` " + + ( + f"**{format_duration(int(self.player.original.progress))}** / **{format_duration(self.player.duration)}** (**{round(progress * 100)}%**)" + if self.player.duration + else "[**live**]" + ) + ), + ) + embed.add_field(name="Volume", value=f"{int(self.player.volume*100)}%") + embed.add_field(name="Views", value=f"{self.player.view_count:,}") + embed.add_field( + name="Queuer", + value=self.trigger_message.author.mention, + ) + embed.set_image(self.player.thumbnail_url) + return embed + def __str__(self): return self.__repr__()