Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/remove #89

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
4 changes: 3 additions & 1 deletion config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@
HELP_RESUME_LONG = "Resumes the AudioPlayer."
HELP_SKIP_SHORT = "Skip a song"
HELP_SKIP_LONG = "Skips the currently playing song and goes to the next item in the queue."
HELP_REMOVE_SHORT = "Remove a song fomm the queue."
HELP_REMOVE_LONG = "Enter a queue position number to remove the song."
HELP_SONGINFO_SHORT = "Info about current Song"
HELP_SONGINFO_LONG = "Shows details about the song currently being played and posts a link to the song."
HELP_STOP_SHORT = "Stop Music"
Expand All @@ -90,4 +92,4 @@
HELP_CHANGECHANNEL_SHORT = "Change the bot channel"
HELP_CHANGECHANNEL_LONG = "Change the bot channel to the VC you are in"

ABSOLUTE_PATH = '' #do not modify
ABSOLUTE_PATH = '' #do not modify
8 changes: 8 additions & 0 deletions musicbot/audiocontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ def track_history(self):
history_string += "\n" + trackname
return history_string

def remove_song(self, queue_number):
removed_title = self.playlist.get_title(queue_number)
if removed_title is None:
return "Queue position \"" + str(queue_number) + "\" does not exist."
success_str = "Removed track \#" + str(queue_number) + ": " + removed_title
self.playlist.remove(queue_number)
return success_str

def next_song(self, error):
"""Invoked after a song is finished. Plays the next song if there is one."""

Expand Down
12 changes: 12 additions & 0 deletions musicbot/commands/music.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,18 @@ async def _skip(self, ctx):
current_guild.voice_client.stop()
await ctx.send("Skipped current song :fast_forward:")

@commands.command(name='remove', description=config.HELP_REMOVE_LONG, help=config.HELP_REMOVE_SHORT, aliases=['rm'])
async def _remove(self, ctx, *, queue_number: int):
current_guild = utils.get_guild(self.bot, ctx.message)

if queue_number is None:
ctx.send("You must enter a queue position to remove a song.")

audiocontroller = utils.guild_to_audiocontroller[current_guild]

response = audiocontroller.remove_song(queue_number)
await ctx.send(response)

@commands.command(name='clear', description=config.HELP_CLEAR_LONG, help=config.HELP_CLEAR_SHORT, aliases=['cl'])
async def _clear(self, ctx):
current_guild = utils.get_guild(self.bot, ctx.message)
Expand Down
10 changes: 10 additions & 0 deletions musicbot/playlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ def add_name(self, trackname):
def add(self, track):
self.playque.append(track)

def remove(self, queue_number):
if queue_number > len(self.playque):
return
del self.playque[queue_number-1]

def next(self, song_played):

if self.loop == True:
Expand Down Expand Up @@ -62,3 +67,8 @@ def shuffle(self):
def empty(self):
self.playque.clear()
self.playhistory.clear()

def get_title(self, queue_number):
if queue_number > len(self.playque):
return None
return self.playque[queue_number-1].info.title