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

feat: _cp (currently playing command) #68

Merged
merged 1 commit into from
Oct 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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