Skip to content

Commit

Permalink
[Discord] Separate spotify and spotify info into distinct commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Harmon758 committed Nov 20, 2023
1 parent 1e810dd commit 39f8d24
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
42 changes: 33 additions & 9 deletions Discord/cogs/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ async def cog_check(self, ctx):

@commands.hybrid_group(
aliases = [
"soundcloud", "voice", "stream", "play", "playlist", "spotify",
"budio", "music", "download"
"soundcloud", "voice", "stream", "play", "playlist", "budio",
"music", "download"
],
description = "Supports [these sites](https://rg3.github.io/youtube-dl/supportedsites.html) and Spotify",
case_insensitive = True
Expand All @@ -59,14 +59,8 @@ async def audio(self, ctx, *, song: Optional[str]): #elif options[0] == "full":
All audio subcommands are also commands
For cleanup of audio commands, the Manage Messages permission is required
'''
# Note: spotify command invokes this command
# Note: youtube command invokes this command
if song and song.lower().startswith("info "):
if ctx.invoked_with.lower() == "spotify":
await ctx.invoke(
self.bot.cogs["Information"].spotify,
song.lstrip(song.split()[0]).lstrip()
)
return
if not ctx.guild.voice_client:
if ctx.guild.id not in self.players:
self.players[ctx.guild.id] = AudioPlayer.from_context(ctx)
Expand Down Expand Up @@ -114,6 +108,36 @@ async def audio(self, ctx, *, song: Optional[str]): #elif options[0] == "full":
finally:
await response.edit(embed = embed)

@commands.group(
case_insensitive = True, invoke_without_command = True,
description = "Supports [these sites](https://rg3.github.io/youtube-dl/supportedsites.html) and Spotify"
)
@checks.not_forbidden()
async def spotify(self, ctx, *, song: Optional[str]):
'''
Audio System - play a song
All audio subcommands are also commands
For cleanup of audio commands, the Manage Messages permission is required
'''
if command := ctx.bot.get_command("audio"):
await ctx.invoke(command, song = song)
else:
raise RuntimeError(
"audio command not found when spotify command invoked"
)

@spotify.command(name = "information", aliases = ["info"])
@checks.not_forbidden()
async def spotify_information(self, ctx, url: str):
'''Information about a Spotify track'''
if command := ctx.bot.get_command("information spotify"):
await ctx.invoke(command, url = url)
else:
raise RuntimeError(
"information spotify command not found "
"when spotify information command invoked"
)

@commands.hybrid_group(
aliases = ["yt"],
case_insensitive = True, with_app_command = False,
Expand Down
1 change: 1 addition & 0 deletions Discord/cogs/information.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ async def server(self, ctx):
@information.command(with_app_command = False)
async def spotify(self, ctx, url: str):
'''Information about a Spotify track'''
# Note: spotify information command invokes this command
path = urllib.parse.urlparse(url).path

if path[:7] != "/track/":
Expand Down

0 comments on commit 39f8d24

Please sign in to comment.