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
53 changes: 20 additions & 33 deletions redbot/cogs/audio/apis/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,39 +624,26 @@ async def spotify_enqueue(
if enqueue:
if len(player.queue) >= 10000:
continue
if guild_data["maxlength"] > 0:
if self.cog.is_track_length_allowed(single_track, guild_data["maxlength"]):
enqueued_tracks += 1
single_track.extras.update(
{
"enqueue_time": int(time.time()),
"vc": player.channel.id,
"requester": ctx.author.id,
}
)
player.add(ctx.author, single_track)
self.bot.dispatch(
"red_audio_track_enqueue",
player.guild,
single_track,
ctx.author,
)
else:
enqueued_tracks += 1
single_track.extras.update(
{
"enqueue_time": int(time.time()),
"vc": player.channel.id,
"requester": ctx.author.id,
}
)
player.add(ctx.author, single_track)
self.bot.dispatch(
"red_audio_track_enqueue",
player.guild,
single_track,
ctx.author,
)
if guild_data["maxlength"] > 0 and not self.cog.is_track_length_allowed(
single_track, guild_data["maxlength"]
):
continue

enqueued_tracks += 1
single_track.extras.update(
{
"enqueue_time": int(time.time()),
"vc": player.channel.id,
"requester": ctx.author.id,
}
)
player.add(ctx.author, single_track)
self.bot.dispatch(
"red_audio_track_enqueue",
player.guild,
single_track,
ctx.author,
)

if not player.current:
await player.play()
Expand Down
1 change: 1 addition & 0 deletions redbot/cogs/audio/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ def __init__(self, bot: Red):
prefer_lyrics=False,
repeat=False,
shuffle=False,
keep_in_queue=False,
shuffle_bumped=True,
thumbnail=False,
volume=100,
Expand Down
150 changes: 150 additions & 0 deletions redbot/cogs/audio/core/commands/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ async def command_now(self, ctx: commands.Context):
shuffle = guild_data["shuffle"]
repeat = guild_data["repeat"]
autoplay = guild_data["auto_play"]
keep_in_queue = guild_data["keep_in_queue"]
text = ""
text += (
_("Auto-Play")
Expand All @@ -142,6 +143,18 @@ async def command_now(self, ctx: commands.Context):
+ ": "
+ ("\N{WHITE HEAVY CHECK MARK}" if repeat else "\N{CROSS MARK}")
)
text += (
(" | " if text else "")
+ _("Repeat Current")
+ ": "
+ ("\N{WHITE HEAVY CHECK MARK}" if player.repeat_current else "\N{CROSS MARK}")
)
text += (
(" | " if text else "")
+ _("Keep in Queue")
+ ": "
+ ("\N{WHITE HEAVY CHECK MARK}" if keep_in_queue else "\N{CROSS MARK}")
)

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

Expand Down Expand Up @@ -602,6 +615,7 @@ async def command_stop(self, ctx: commands.Context):
if eq:
await self.config.custom("EQUALIZER", ctx.guild.id).eq_bands.set(eq.bands)
player.queue = []
player.next_queue_position = 0
player.store("playing_song", None)
player.store("prev_requester", None)
player.store("prev_song", None)
Expand Down Expand Up @@ -784,6 +798,86 @@ async def command_repeat(self, ctx: commands.Context):
if self._player_check(ctx):
await self.set_player_settings(ctx)

@commands.command(name="repeatcurrent")
@commands.guild_only()
@commands.bot_has_permissions(embed_links=True)
async def command_repeat_current(self, ctx: commands.Context):
"""Toggle repeat current."""
dj_enabled = self._dj_status_cache.setdefault(
ctx.guild.id, await self.config.guild(ctx.guild).dj_enabled()
)
can_skip = await self._can_instaskip(ctx, ctx.author)
if dj_enabled and not can_skip and not await self._has_dj_role(ctx, ctx.author):
return await self.send_embed_msg(
ctx,
title=_("Unable To Toggle Repeat Current"),
description=_("You need the DJ role to toggle repeat current."),
)
if not self._player_check(ctx):
return await self.send_embed_msg(
ctx,
title=_("Unable To Toggle Repeat Current"),
description=_("Nothing playing."),
)

await self.set_player_settings(ctx)
player = lavalink.get_player(ctx.guild.id)
if (not ctx.author.voice or ctx.author.voice.channel != player.channel) and not can_skip:
return await self.send_embed_msg(
ctx,
title=_("Unable To Toggle Repeat Current"),
description=_("You must be in the voice channel to toggle repeat current."),
)
player.store("notify_channel", ctx.channel.id)

msg = _("Repeat current track: {true_or_false}.").format(
true_or_false=_("Enabled") if not player.repeat_current else _("Disabled")
)
player.repeat_current = not player.repeat_current

embed = discord.Embed(title=_("Setting Changed"), description=msg)
await self.send_embed_msg(ctx, embed=embed)

@commands.command(name="keepinqueue")
@commands.guild_only()
@commands.bot_has_permissions(embed_links=True)
async def command_keepinqueue(self, ctx: commands.Context):
"""Toggle keep in queue."""
dj_enabled = self._dj_status_cache.setdefault(
ctx.guild.id, await self.config.guild(ctx.guild).dj_enabled()
)
can_skip = await self._can_instaskip(ctx, ctx.author)
if dj_enabled and not can_skip and not await self._has_dj_role(ctx, ctx.author):
return await self.send_embed_msg(
ctx,
title=_("Unable To Toggle Keep In Queue"),
description=_("You need the DJ role to toggle keep in queue."),
)
if self._player_check(ctx):
await self.set_player_settings(ctx)
player = lavalink.get_player(ctx.guild.id)
if (
not ctx.author.voice or ctx.author.voice.channel != player.channel
) and not can_skip:
return await self.send_embed_msg(
ctx,
title=_("Unable To Toggle Keep In Queue"),
description=_("You must be in the voice channel to toggle keep in queue."),
)
player.store("notify_channel", ctx.channel.id)

keep_in_queue = await self.config.guild(ctx.guild).keep_in_queue()
msg = ""
msg += _("Keep tracks in queue: {true_or_false}.").format(
true_or_false=_("Enabled") if not keep_in_queue else _("Disabled")
)
await self.config.guild(ctx.guild).keep_in_queue.set(not keep_in_queue)

embed = discord.Embed(title=_("Setting Changed"), description=msg)
await self.send_embed_msg(ctx, embed=embed)
if self._player_check(ctx):
await self.set_player_settings(ctx)

@commands.command(name="remove")
@commands.guild_only()
@commands.bot_has_permissions(embed_links=True)
Expand Down Expand Up @@ -822,6 +916,9 @@ async def command_remove(self, ctx: commands.Context, index_or_url: Union[int, s
)
index_or_url -= 1
removed = player.queue.pop(index_or_url)
if index_or_url < player.next_queue_position:
player.next_queue_position -= 1

await self.api_interface.persistent_queue_api.played(
ctx.guild.id, removed.extras.get("enqueue_time")
)
Expand Down Expand Up @@ -901,3 +998,56 @@ async def command_bump(self, ctx: commands.Context, index: int):
await self.send_embed_msg(
ctx, title=_("Moved track to the top of the queue."), description=description
)

@commands.command(name="move")
@commands.guild_only()
@commands.bot_has_permissions(embed_links=True)
async def command_move(self, ctx: commands.Context, from_index: int, to_index: int):
"""Move a track number to another place in the queue."""
dj_enabled = self._dj_status_cache.setdefault(
ctx.guild.id, await self.config.guild(ctx.guild).dj_enabled()
)
if not self._player_check(ctx):
return await self.send_embed_msg(ctx, title=_("Nothing playing."))
player = lavalink.get_player(ctx.guild.id)
can_skip = await self._can_instaskip(ctx, ctx.author)
if (not ctx.author.voice or ctx.author.voice.channel != player.channel) and not can_skip:
return await self.send_embed_msg(
ctx,
title=_("Unable To Move Track"),
description=_("You must be in the voice channel to move a track."),
)
if dj_enabled and not can_skip:
return await self.send_embed_msg(
ctx,
title=_("Unable To Move Track"),
description=_("You need the DJ role to move tracks."),
)
if from_index > len(player.queue) or from_index < 1:
return await self.send_embed_msg(
ctx,
title=_("Unable To Move Track"),
description=_("Song number must be greater than 1 and within the queue limit."),
)
if to_index > len(player.queue) or to_index < 1:
return await self.send_embed_msg(
ctx,
title=_("Unable To Move Track"),
description=_(
"Move target number must be greater than 1 and within the queue limit."
),
)
player.store("notify_channel", ctx.channel.id)
removed = player.queue.pop(from_index - 1)
player.queue.insert(to_index - 1, removed)
original_next = player.next_queue_position
if from_index - 1 < original_next:
player.next_queue_position -= 1
if to_index - 1 < original_next:
player.next_queue_position += 1
description = await self.get_track_description(removed, self.local_folder_current_path)
await self.send_embed_msg(
ctx,
title=_("Moved track to the position {to_index}.").format(to_index=to_index),
description=description,
)
32 changes: 9 additions & 23 deletions redbot/cogs/audio/core/commands/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,29 +295,15 @@ async def command_bumpplay(
title=_("Unable To Play Tracks"),
description=_("This track is not allowed in this server."),
)
elif guild_data["maxlength"] > 0:
if self.is_track_length_allowed(single_track, guild_data["maxlength"]):
single_track.requester = ctx.author
single_track.extras.update(
{
"enqueue_time": int(time.time()),
"vc": player.channel.id,
"requester": ctx.author.id,
}
)
player.queue.insert(0, single_track)
player.maybe_shuffle()
self.bot.dispatch(
"red_audio_track_enqueue", player.guild, single_track, ctx.author
)
else:
self.update_player_lock(ctx, False)
return await self.send_embed_msg(
ctx,
title=_("Unable To Play Tracks"),
description=_("Track exceeds maximum length."),
)

elif guild_data["maxlength"] > 0 and not self.is_track_length_allowed(
single_track, guild_data["maxlength"]
):
self.update_player_lock(ctx, False)
return await self.send_embed_msg(
ctx,
title=_("Unable To Play Tracks"),
description=_("Track exceeds maximum length."),
)
else:
single_track.requester = ctx.author
single_track.extras["bumped"] = True
Expand Down
13 changes: 13 additions & 0 deletions redbot/cogs/audio/core/commands/queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ async def _queue_menu(
shuffle = guild_data["shuffle"]
repeat = guild_data["repeat"]
autoplay = guild_data["auto_play"]
keep_in_queue = guild_data["keep_in_queue"]
text = ""
text += (
_("Auto-Play")
Expand All @@ -106,6 +107,18 @@ async def _queue_menu(
+ ": "
+ ("\N{WHITE HEAVY CHECK MARK}" if repeat else "\N{CROSS MARK}")
)
text += (
(" | " if text else "")
+ _("Repeat Current")
+ ": "
+ ("\N{WHITE HEAVY CHECK MARK}" if player.repeat_current else "\N{CROSS MARK}")
)
text += (
(" | " if text else "")
+ _("Keep in Queue")
+ ": "
+ ("\N{WHITE HEAVY CHECK MARK}" if keep_in_queue else "\N{CROSS MARK}")
)
embed.set_footer(text=text)
message = await self.send_embed_msg(ctx, embed=embed)
dj_enabled = self._dj_status_cache.setdefault(ctx.guild.id, guild_data["dj_enabled"])
Expand Down
5 changes: 4 additions & 1 deletion redbot/cogs/audio/core/utilities/miscellaneous.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,12 @@ def time_convert(self, length: Union[int, str]) -> int:

async def queue_duration(self, ctx: commands.Context) -> int:
player = lavalink.get_player(ctx.guild.id)
next_index = min(player.next_queue_position, len(player.queue))
dur = [
i.length
async for i in AsyncIter(player.queue, steps=50).filter(lambda x: not x.is_stream)
async for i in AsyncIter(player.queue[next_index:], steps=50).filter(
lambda x: not x.is_stream
)
]
queue_dur = sum(dur)
if not player.queue:
Expand Down
Loading
Loading