Skip to content

Commit

Permalink
Stop spotify playlists fetch on clear command (#2378)
Browse files Browse the repository at this point in the history
* Exit the spotify album/playlist loops when clear is used.

* add guild to command args, fix bad ref

* ditch the sleep method. this should work well enough...
  • Loading branch information
itsTheFae committed Dec 22, 2023
1 parent a08f792 commit 0cf25c1
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions musicbot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ def __init__(self, config_file=None, perms_file=None, aliases_file=None):
"last_np_msg": None,
"availability_paused": False,
"auto_paused": False,
"halt_playlist_unpack": False,
"inactive_player_timer": (
asyncio.Event(),
False, # event state tracking.
Expand Down Expand Up @@ -2281,6 +2282,9 @@ async def _cmd_play(

song_url = song_url.strip("<>")

if self.server_specific_data[channel.guild.id]["halt_playlist_unpack"]:
self.server_specific_data[channel.guild.id]["halt_playlist_unpack"] = False

async with channel.typing():
if leftover_args:
song_url = " ".join([song_url, *leftover_args])
Expand Down Expand Up @@ -2329,8 +2333,19 @@ async def _cmd_play(
).format(res["name"], song_url),
)
for i in res["tracks"]["items"]:
if self.server_specific_data[channel.guild.id][
"halt_playlist_unpack"
]:
log.debug(
"Halting spotify album queuing due to clear command."
)
break
song_url = i["name"] + " " + i["artists"][0]["name"]
log.debug("Processing {0}".format(song_url))
log.debug(
"Processing spotify album track: {0}".format(
song_url
)
)
await self.cmd_play(
message,
player,
Expand Down Expand Up @@ -2370,12 +2385,23 @@ async def _cmd_play(
).format(parts[-1], song_url),
)
for i in res:
if self.server_specific_data[channel.guild.id][
"halt_playlist_unpack"
]:
log.debug(
"Halting spotify playlist queuing due to clear command."
)
break
song_url = (
i["track"]["name"]
+ " "
+ i["track"]["artists"][0]["name"]
)
log.debug("Processing {0}".format(song_url))
log.debug(
"Processing spotify playlist track: {0}".format(
song_url
)
)
await self.cmd_play(
message,
player,
Expand Down Expand Up @@ -3486,7 +3512,7 @@ async def cmd_shuffle(self, channel, player):
delete_after=15,
)

async def cmd_clear(self, player, author):
async def cmd_clear(self, guild, player, author):
"""
Usage:
{command_prefix}clear
Expand All @@ -3495,6 +3521,10 @@ async def cmd_clear(self, player, author):
"""

player.playlist.clear()

# This lets us signal to playlist queuing loops to stop adding to the queue.
self.server_specific_data[guild.id]["halt_playlist_unpack"] = True

return Response(
self.str.get("cmd-clear-reply", "Cleared `{0}`'s queue").format(
player.voice_client.channel.guild
Expand Down

0 comments on commit 0cf25c1

Please sign in to comment.