Skip to content

Commit

Permalink
Merge pull request #84 from lk2322/move
Browse files Browse the repository at this point in the history
Added the ability to move a track in the queue
  • Loading branch information
Raptor123471 authored Jan 18, 2022
2 parents eb18e0f + 0cba799 commit 6790bbb
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 7 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ $p [link/video title/key words/playlist-link/soundcloud link/spotify link/bandca
- A link to a YouTube playlist
* If a song is playing, it will be added to queue

#### Playlist Commands

```
$skip / $s
```
Expand All @@ -97,6 +99,14 @@ $l / $loop

* Loop the current playing song, toggle on/off

```
$mv / $move
```

* Move song position in queue

#### Audio Commands

```
$pause
```
Expand Down
2 changes: 2 additions & 0 deletions config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@
HELP_SONGINFO_LONG = "Shows details about the song currently being played and posts a link to the song."
HELP_STOP_SHORT = "Stop Music"
HELP_STOP_LONG = "Stops the AudioPlayer and clears the songqueue"
HELP_MOVE_LONG = f"{BOT_PREFIX}move [position] [new position]"
HELP_MOVE_SHORT = 'Moves a track in the queue'
HELP_YT_SHORT = "Play a supported link or search on youtube"
HELP_YT_LONG = ("$p [link/video title/key words/playlist-link/soundcloud link/spotify link/bandcamp link/twitter link]")
HELP_PING_SHORT = "Pong"
Expand Down
43 changes: 36 additions & 7 deletions musicbot/commands/music.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ class Music(commands.Cog):
def __init__(self, bot):
self.bot = bot

@commands.command(name='play', description=config.HELP_YT_LONG, help=config.HELP_YT_SHORT, aliases=['p', 'yt', 'pl'])
@commands.command(name='play', description=config.HELP_YT_LONG, help=config.HELP_YT_SHORT,
aliases=['p', 'yt', 'pl'])
async def _play_song(self, ctx, *, track: str):

current_guild = utils.get_guild(self.bot, ctx.message)
audiocontroller = utils.guild_to_audiocontroller[current_guild]

if(await utils.is_connected(ctx) == None):
if (await utils.is_connected(ctx) == None):
if await audiocontroller.uconnect(ctx) == False:
return

Expand Down Expand Up @@ -76,7 +77,8 @@ async def _loop(self, ctx):
audiocontroller.playlist.loop = False
await ctx.send("Loop disabled :x:")

@commands.command(name='shuffle', description=config.HELP_SHUFFLE_LONG, help=config.HELP_SHUFFLE_SHORT, aliases=["sh"])
@commands.command(name='shuffle', description=config.HELP_SHUFFLE_LONG, help=config.HELP_SHUFFLE_SHORT,
aliases=["sh"])
async def _shuffle(self, ctx):
current_guild = utils.get_guild(self.bot, ctx.message)
audiocontroller = utils.guild_to_audiocontroller[current_guild]
Expand Down Expand Up @@ -112,7 +114,8 @@ async def _pause(self, ctx):
current_guild.voice_client.pause()
await ctx.send("Playback Paused :pause_button:")

@commands.command(name='queue', description=config.HELP_QUEUE_LONG, help=config.HELP_QUEUE_SHORT, aliases=['playlist', 'q'])
@commands.command(name='queue', description=config.HELP_QUEUE_LONG, help=config.HELP_QUEUE_SHORT,
aliases=['playlist', 'q'])
async def _queue(self, ctx):
current_guild = utils.get_guild(self.bot, ctx.message)

Expand Down Expand Up @@ -145,7 +148,7 @@ async def _queue(self, ctx):

await ctx.send(embed=embed)

@commands.command(name='stop', description=config.HELP_STOP_LONG, help=config. HELP_STOP_SHORT, aliases=['st'])
@commands.command(name='stop', description=config.HELP_STOP_LONG, help=config.HELP_STOP_SHORT, aliases=['st'])
async def _stop(self, ctx):
current_guild = utils.get_guild(self.bot, ctx.message)

Expand All @@ -160,6 +163,31 @@ async def _stop(self, ctx):
await utils.guild_to_audiocontroller[current_guild].stop_player()
await ctx.send("Stopped all sessions :octagonal_sign:")

@commands.command(name='move', description=config.HELP_MOVE_LONG, help=config.HELP_MOVE_SHORT, aliases=['mv'])
async def _move(self, ctx, *args):
if len(args) != 2:
ctx.send("Wrong number of arguments")
return

try:
oldindex, newindex = map(int, args)
except ValueError:
ctx.send("Wrong argument")
return

current_guild = utils.get_guild(self.bot, ctx.message)
audiocontroller = utils.guild_to_audiocontroller[current_guild]
if current_guild.voice_client is None or (
not current_guild.voice_client.is_paused() and not current_guild.voice_client.is_playing()):
await ctx.send("Queue is empty :x:")
return
try:
audiocontroller.playlist.move(oldindex - 1, newindex - 1)
except IndexError:
await ctx.send("Wrong position")
return
await ctx.send("Moved")

@commands.command(name='skip', description=config.HELP_SKIP_LONG, help=config.HELP_SKIP_SHORT, aliases=['s'])
async def _skip(self, ctx):
current_guild = utils.get_guild(self.bot, ctx.message)
Expand All @@ -178,7 +206,7 @@ async def _skip(self, ctx):
return
if current_guild.voice_client is None or (
not current_guild.voice_client.is_paused() and not current_guild.voice_client.is_playing()):
await ctx.send("Queue is empty :x:")
await ctx.send("Queue is empty :x:")
return
current_guild.voice_client.stop()
await ctx.send("Skipped current song :fast_forward:")
Expand Down Expand Up @@ -228,7 +256,8 @@ async def _resume(self, ctx):
current_guild.voice_client.resume()
await ctx.send("Resumed playback :arrow_forward:")

@commands.command(name='songinfo', description=config.HELP_SONGINFO_LONG, help=config.HELP_SONGINFO_SHORT, aliases=["np"])
@commands.command(name='songinfo', description=config.HELP_SONGINFO_LONG, help=config.HELP_SONGINFO_SHORT,
aliases=["np"])
async def _songinfo(self, ctx):
current_guild = utils.get_guild(self.bot, ctx.message)

Expand Down
5 changes: 5 additions & 0 deletions musicbot/playlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ def prev(self, current_song):
def shuffle(self):
random.shuffle(self.playque)

def move(self, oldindex: int, newindex: int):
temp = self.playque[oldindex]
del self.playque[oldindex]
self.playque.insert(newindex, temp)

def empty(self):
self.playque.clear()
self.playhistory.clear()

0 comments on commit 6790bbb

Please sign in to comment.