Skip to content

Commit

Permalink
Merge pull request #68 from joao-conde/feature/show-current-playing
Browse files Browse the repository at this point in the history
feat: _cp (currently playing command)
  • Loading branch information
amanjha8100 committed Oct 11, 2021
2 parents 6233364 + 1b611ee commit f3872d9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ Go to the [Discord Developer Portal](https://discord.com/developers/docs/intro)
**You will currently need a discord role _DJ_ to use all the available commands**

```
_p : Plays the song with search keyword following the command
_p : Plays the song with search keyword following the command
_cp: Shows the currently playing song
_pn : Moves the song to the top of the queue
_pause : Pause the currently playing song
_resume : Resume the currently playing song
Expand Down
20 changes: 16 additions & 4 deletions music.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def __init__(self, bot):
self.bot = bot

self.is_playing = False
self.current_song = None
self.music_queue = []
self.skip_votes = set()

Expand Down Expand Up @@ -61,14 +62,15 @@ def play_next(self):

m_url = self.music_queue[0][0]["source"]

self.music_queue.pop(0)
self.current_song = self.music_queue.pop(0)

self.vc.play(
discord.FFmpegPCMAudio(m_url, **self.FFMPEG_OPTIONS),
after=lambda e: self.play_next(),
)
else:
self.is_playing = False
self.current_song = None

async def play_music(self, ctx):
if len(self.music_queue) > 0:
Expand All @@ -89,10 +91,11 @@ async def play_music(self, ctx):
discord.FFmpegPCMAudio(m_url, **self.FFMPEG_OPTIONS),
after=lambda e: self.play_next(),
)
self.music_queue.pop(0)
self.current_song = self.music_queue.pop(0)

else:
self.is_playing = False
self.current_song = None

@commands.command(
name="p",
Expand Down Expand Up @@ -121,15 +124,24 @@ async def p(self, ctx, *args):
if self.is_playing == False:
await self.play_music(ctx)

@commands.command(
name="cp",
help="Shows the currently playing song \U0001F440",
aliases=["playing"],
)
async def cp(self, ctx):
msg = "No music playing" if self.current_song is None else f"""Currently Playing: **{self.current_song[0]['title']}** -- added by {self.current_song[2]}\n"""
await ctx.send(msg)

@commands.command(
name="q",
help="Shows the music added in list/queue \U0001F440",
aliases=["queue"],
)
async def q(self, ctx):
retval = ""
for i in range(0, len(self.music_queue)):
retval += f"""{i+1}. **{self.music_queue[i][0]['title']}** -- added by {self.music_queue[i][2]}\n"""
for (i, m) in enumerate(self.music_queue):
retval += f"""{i+1}. **{m[0]['title']}** -- added by {m[2]}\n"""

if retval != "":
await ctx.send(retval)
Expand Down

0 comments on commit f3872d9

Please sign in to comment.