Skip to content

Commit

Permalink
[Discord] Separate youtube and youtube 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 b46566e commit b13802e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 9 deletions.
51 changes: 43 additions & 8 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 = [
"yt", "youtube", "soundcloud", "voice", "stream", "play",
"playlist", "spotify", "budio", "music", "download"
"soundcloud", "voice", "stream", "play", "playlist", "spotify",
"budio", "music", "download"
],
description = "Supports [these sites](https://rg3.github.io/youtube-dl/supportedsites.html) and Spotify",
case_insensitive = True
Expand All @@ -59,19 +59,14 @@ 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: 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
elif ctx.invoked_with.lower() in ("yt", "youtube"):
await ctx.invoke(
self.bot.cogs["Information"].youtube,
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 @@ -119,6 +114,46 @@ async def audio(self, ctx, *, song: Optional[str]): #elif options[0] == "full":
finally:
await response.edit(embed = embed)

@commands.hybrid_group(
aliases = ["yt"],
case_insensitive = True, with_app_command = False,
description = "Supports [these sites](https://rg3.github.io/youtube-dl/supportedsites.html) and Spotify",
)
@checks.not_forbidden()
async def youtube(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 youtube command invoked"
)

@youtube.command(
name = "information", aliases = ["info"], with_app_command = False
)
@checks.not_forbidden()
async def youtube_information(self, ctx, url: str):
"""
Show information about a YouTube video
Parameters
----------
url
YouTube video URL
"""
if command := ctx.bot.get_command("information youtube"):
await ctx.invoke(command, url = url)
else:
raise RuntimeError(
"information youtube command not found "
"when youtube information command invoked"
)

@audio.command(name = "join", aliases = ["summon", "move"])
@commands.check_any(
checks.is_permitted(),
Expand Down
2 changes: 1 addition & 1 deletion Discord/cogs/youtube.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def __init__(self, bot):
)
)
"""
if (cog := self.bot.get_cog("Audio")) and (parent := getattr(cog, "audio")):
if (cog := self.bot.get_cog("Audio")) and (parent := getattr(cog, "youtube")):
parent.add_command(streams_command)
# parent.add_command(uploads_command)
else:
Expand Down

0 comments on commit b13802e

Please sign in to comment.