From 735eb68ed5554b317031e76be04d42fb0b83a783 Mon Sep 17 00:00:00 2001 From: Harmon Date: Fri, 28 Jul 2023 23:04:44 -0500 Subject: [PATCH] [Discord] Separate search youtube and audio search commands Separate search youtube and audio search into distinct commands --- Discord/cogs/audio.py | 13 +++++++++++++ Discord/cogs/search.py | 10 ++-------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/Discord/cogs/audio.py b/Discord/cogs/audio.py index 9de11fcd9a..e74c5e2bd7 100644 --- a/Discord/cogs/audio.py +++ b/Discord/cogs/audio.py @@ -356,6 +356,19 @@ async def radio_off(self, ctx): else: await ctx.embed_reply(":no_entry: Radio is already off") + @audio.command(name = "search") + @checks.not_forbidden() + async def audio_search(self, ctx, *, search): + '''Find a Youtube video''' + # TODO: Only invoke when parent command invoked with youtube or yt + if command := ctx.bot.get_command("search youtube"): + await ctx.invoke(command, search = search) + else: + raise RuntimeError( + "search youtube command not found " + "when audio search command invoked" + ) + @commands.command(aliases = ["set_text"]) @checks.is_voice_connected() @commands.check_any(checks.is_permitted(), checks.is_guild_owner()) diff --git a/Discord/cogs/search.py b/Discord/cogs/search.py index 26ba8c03b6..49a9908019 100644 --- a/Discord/cogs/search.py +++ b/Discord/cogs/search.py @@ -34,14 +34,6 @@ def __init__(self, bot): if isinstance(command, commands.Command) and command.parent is None and name != "search": self.bot.add_command(command) self.search.add_command(command) - # Add search youtube / youtube (audio) search subcommands - command = commands.Command(self.youtube, aliases = ["yt"], checks = [checks.not_forbidden().predicate]) - command.error(self.youtube_error) - self.search.add_command(command) - if (cog := self.bot.get_cog("Audio")) and (parent := getattr(cog, "audio")): - command = commands.Command(self.youtube, name = "search", checks = [checks.not_forbidden().predicate]) - command.error(self.youtube_error) - parent.add_command(command) def cog_unload(self): if (cog := self.bot.get_cog("Audio")) and (parent := getattr(cog, "audio")): @@ -58,8 +50,10 @@ async def search(self, ctx): ''' await ctx.embed_reply(":grey_question: Search what?") + @search.command(aliases = ["yt"]) async def youtube(self, ctx, *, search: str): '''Find a Youtube video''' + # Note: audio search command invokes this command ydl = youtube_dl.YoutubeDL( {"default_search": "auto", "noplaylist": True, "quiet": True} )