From b13802eee203560c6f4cc9e535f94fd9976b223c Mon Sep 17 00:00:00 2001 From: Harmon Date: Mon, 20 Nov 2023 15:11:36 -0600 Subject: [PATCH] [Discord] Separate youtube and youtube info into distinct commands --- Discord/cogs/audio.py | 51 ++++++++++++++++++++++++++++++++++------- Discord/cogs/youtube.py | 2 +- 2 files changed, 44 insertions(+), 9 deletions(-) diff --git a/Discord/cogs/audio.py b/Discord/cogs/audio.py index 4a241311b1..b7d106f171 100644 --- a/Discord/cogs/audio.py +++ b/Discord/cogs/audio.py @@ -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 @@ -59,6 +59,7 @@ 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( @@ -66,12 +67,6 @@ async def audio(self, ctx, *, song: Optional[str]): #elif options[0] == "full": 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) @@ -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(), diff --git a/Discord/cogs/youtube.py b/Discord/cogs/youtube.py index a3242012fa..47bade492a 100644 --- a/Discord/cogs/youtube.py +++ b/Discord/cogs/youtube.py @@ -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: