refactor(commands/voice): move embed generation into separate file
This commit is contained in:
parent
8ee5d01bf6
commit
41f9beb6e8
@ -1,6 +1,5 @@
|
|||||||
from .channel import join, leave
|
from .channel import join, leave
|
||||||
from .playback import fast_forward, pause, resume, volume
|
from .playback import fast_forward, pause, playing, resume, volume
|
||||||
from .playing import playing
|
|
||||||
from .queue import queue_or_play, skip
|
from .queue import queue_or_play, skip
|
||||||
from .utils import remove_queued
|
from .utils import remove_queued
|
||||||
|
|
||||||
|
@ -1,10 +1,62 @@
|
|||||||
import arguments
|
import arguments
|
||||||
import commands
|
import commands
|
||||||
|
import constants
|
||||||
|
import disnake_paginator
|
||||||
import utils
|
import utils
|
||||||
|
from state import players
|
||||||
|
|
||||||
from .utils import command_allowed
|
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):
|
async def resume(message):
|
||||||
if not command_allowed(message):
|
if not command_allowed(message):
|
||||||
return
|
return
|
||||||
|
@ -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!",
|
|
||||||
)
|
|
@ -1,9 +1,7 @@
|
|||||||
import constants
|
|
||||||
import disnake
|
import disnake
|
||||||
import youtubedl
|
|
||||||
from state import client, players
|
|
||||||
|
|
||||||
import utils
|
import utils
|
||||||
|
from state import client, players
|
||||||
|
|
||||||
|
|
||||||
def play_after_callback(e, message, once):
|
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)
|
queued.player, after=lambda e: play_after_callback(e, message, once)
|
||||||
)
|
)
|
||||||
|
|
||||||
embed = disnake.Embed(
|
embed = queued.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)
|
|
||||||
|
|
||||||
if first and len(players[message.guild.id].queue) == 0:
|
if first and len(players[message.guild.id].queue) == 0:
|
||||||
client.loop.create_task(utils.reply(message, embed=embed))
|
client.loop.create_task(utils.reply(message, embed=embed))
|
||||||
else:
|
else:
|
||||||
|
@ -26,6 +26,11 @@ RELOADABLE_MODULES = [
|
|||||||
"commands.tools",
|
"commands.tools",
|
||||||
"commands.utils",
|
"commands.utils",
|
||||||
"commands.voice",
|
"commands.voice",
|
||||||
|
"commands.voice.channel",
|
||||||
|
"commands.voice.playback",
|
||||||
|
"commands.voice.playing",
|
||||||
|
"commands.voice.queue",
|
||||||
|
"commands.voice.utils",
|
||||||
"constants",
|
"constants",
|
||||||
"core",
|
"core",
|
||||||
"events",
|
"events",
|
||||||
|
28
youtubedl.py
28
youtubedl.py
@ -99,6 +99,34 @@ class QueuedSong:
|
|||||||
+ (f" (<@{self.trigger_message.author.id}>)" if show_queuer else "")
|
+ (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):
|
def __str__(self):
|
||||||
return self.__repr__()
|
return self.__repr__()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user