Skip to content

Commit

Permalink
[Discord] Separate search youtube and audio search commands
Browse files Browse the repository at this point in the history
Separate search youtube and audio search into distinct commands
  • Loading branch information
Harmon758 committed Jul 29, 2023
1 parent 4ca46d1 commit 735eb68
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
13 changes: 13 additions & 0 deletions Discord/cogs/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
10 changes: 2 additions & 8 deletions Discord/cogs/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")):
Expand All @@ -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}
)
Expand Down

0 comments on commit 735eb68

Please sign in to comment.