Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 22 additions & 11 deletions redbot/cogs/audio/core/commands/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

from ..abc import MixinMeta
from ..cog_utils import CompositeMetaClass
from ..utilities.menus.now_playing import NowPlayingView

log = getLogger("red.cogs.Audio.cog.Commands.player_controller")
_ = Translator("Audio", Path(__file__))
Expand Down Expand Up @@ -82,7 +83,6 @@ async def command_disconnect(self, ctx: commands.Context):
@commands.command(name="now")
@commands.guild_only()
@commands.bot_has_permissions(embed_links=True)
@commands.bot_can_react()
Comment thread
Evanroby marked this conversation as resolved.
async def command_now(self, ctx: commands.Context):
"""Now playing."""
if not self._player_check(ctx):
Expand Down Expand Up @@ -143,22 +143,33 @@ async def command_now(self, ctx: commands.Context):
+ ("\N{WHITE HEAVY CHECK MARK}" if repeat else "\N{CROSS MARK}")
)

message = await self.send_embed_msg(ctx, embed=embed, footer=text)

player.store("np_message", message)

dj_enabled = self._dj_status_cache.setdefault(
ctx.guild.id, await self.config.guild(ctx.guild).dj_enabled()
)
vote_enabled = await self.config.guild(ctx.guild).vote_enabled()
if (
(dj_enabled or vote_enabled)
and not await self._can_instaskip(ctx, ctx.author)
and not await self.is_requester_alone(ctx)
):
can_control = (
not (dj_enabled or vote_enabled)
or await self._can_instaskip(ctx, ctx.author)
or await self.is_requester_alone(ctx)
)
has_queue = bool(player.queue) or autoplay
if await ctx.bot.use_buttons():
if (dj_enabled or vote_enabled) and not can_control:
message = await self.send_embed_msg(ctx, embed=embed, footer=text)
else:
view = NowPlayingView(ctx=ctx, cog=self, has_queue=has_queue)
message = await self.send_embed_msg(ctx, embed=embed, footer=text, view=view)
view.message = message
player.store("np_message", message)
return
if not ctx.channel.permissions_for(ctx.me).add_reactions:
raise commands.BotMissingPermissions(["add_reactions"])
message = await self.send_embed_msg(ctx, embed=embed, footer=text)
player.store("np_message", message)

if not player.queue and not autoplay:
if (dj_enabled or vote_enabled) and not can_control:
return
if not has_queue:
expected = (emoji["stop"], emoji["pause"], emoji["close"])
task: Optional[asyncio.Task]
if player.current:
Expand Down
94 changes: 94 additions & 0 deletions redbot/cogs/audio/core/utilities/menus/now_playing.py
Comment thread
Evanroby marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import contextlib
from pathlib import Path

import discord

from redbot.core import commands
from redbot.core.i18n import Translator

_ = Translator("Audio", Path(__file__))


class NowPlayingView(discord.ui.View):
"""Button-based controls for the [p]now command.

Only shown when [p]set usebuttons is enabled.
When there is no queue and autoplay is off, prev and next are hidden.
"""

def __init__(self, ctx: commands.Context, cog, has_queue: bool):
super().__init__(timeout=30.0)
self.ctx = ctx
self.cog = cog
self.message: discord.Message = None

if not has_queue:
self.remove_item(self.button_prev)
self.remove_item(self.button_next)

async def interaction_check(self, interaction: discord.Interaction) -> bool:
if interaction.user != self.ctx.author:
await interaction.response.send_message(
_("You are not the one who requested this player."), ephemeral=True
)
return False
return True

async def on_timeout(self) -> None:
if self.message:
with contextlib.suppress(discord.HTTPException):
await self.message.edit(view=None)

@discord.ui.button(
emoji="\N{BLACK LEFT-POINTING DOUBLE TRIANGLE WITH VERTICAL BAR}\N{VARIATION SELECTOR-16}",
style=discord.ButtonStyle.grey,
)
async def button_prev(self, interaction: discord.Interaction, button: discord.ui.Button):
await interaction.response.defer()
self.stop()
with contextlib.suppress(discord.HTTPException):
await self.message.edit(view=None)
await self.ctx.invoke(self.cog.command_prev)

@discord.ui.button(
emoji="\N{BLACK SQUARE FOR STOP}\N{VARIATION SELECTOR-16}",
style=discord.ButtonStyle.grey,
)
async def button_stop(self, interaction: discord.Interaction, button: discord.ui.Button):
await interaction.response.defer()
self.stop()
with contextlib.suppress(discord.HTTPException):
await self.message.edit(view=None)
await self.ctx.invoke(self.cog.command_stop)

@discord.ui.button(
emoji="\N{BLACK RIGHT-POINTING TRIANGLE WITH DOUBLE VERTICAL BAR}\N{VARIATION SELECTOR-16}",
style=discord.ButtonStyle.grey,
)
async def button_pause(self, interaction: discord.Interaction, button: discord.ui.Button):
await interaction.response.defer()
self.stop()
with contextlib.suppress(discord.HTTPException):
await self.message.edit(view=None)
await self.ctx.invoke(self.cog.command_pause)

@discord.ui.button(
emoji="\N{BLACK RIGHT-POINTING DOUBLE TRIANGLE WITH VERTICAL BAR}\N{VARIATION SELECTOR-16}",
style=discord.ButtonStyle.grey,
)
async def button_next(self, interaction: discord.Interaction, button: discord.ui.Button):
await interaction.response.defer()
self.stop()
with contextlib.suppress(discord.HTTPException):
await self.message.edit(view=None)
await self.ctx.invoke(self.cog.command_skip)

@discord.ui.button(
emoji="\N{CROSS MARK}",
style=discord.ButtonStyle.grey,
)
async def button_close(self, interaction: discord.Interaction, button: discord.ui.Button):
await interaction.response.defer()
self.stop()
with contextlib.suppress(discord.HTTPException):
await self.message.delete()
3 changes: 2 additions & 1 deletion redbot/cogs/audio/core/utilities/miscellaneous.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ async def send_embed_msg(
timestamp = kwargs.get("timestamp")
footer = kwargs.get("footer")
thumbnail = kwargs.get("thumbnail")
view = kwargs.get("view")
contents = dict(title=title, type=_type, url=url, description=description)
if hasattr(kwargs.get("embed"), "to_dict"):
embed = kwargs.get("embed")
Expand All @@ -97,7 +98,7 @@ async def send_embed_msg(
embed.set_author(name=name, icon_url=url)
elif name:
embed.set_author(name=name)
return await ctx.send(embed=embed)
return await ctx.send(embed=embed, view=view)

def _has_notify_perms(
self,
Expand Down
Loading