Skip to content

Commit

Permalink
♻️ refactor autocomplete of extensions to only show loaded extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
jb3 committed Apr 28, 2023
1 parent d047448 commit 0417ba7
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions wopr/exts/extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,32 +37,22 @@ async def unload(self, interaction: discord.Interaction, extension: str) -> None
await self.bot.unload_extension(f"wopr.exts.{extension}")
await interaction.response.send_message(f":white_check_mark: Unloaded {extension}!")

@unload.autocomplete("extension")
async def ext_unload_autocomplete(
self, interaction: discord.Interaction, current: str
) -> list[app_commands.Choice[str]]:
"""Autocomplete for the extension argument."""
return [
app_commands.Choice(name=ext.stem.lower(), value=ext.stem.lower())
for ext in Path("wopr/exts").glob("*.py")
if current.lower() in ext.stem.lower()
]

@app_commands.command()
async def reload(self, interaction: discord.Interaction, extension: str) -> None:
"""Reload an extension."""
await self.bot.reload_extension(f"wopr.exts.{extension}")
await interaction.response.send_message(f":white_check_mark: Reloaded {extension}!")

@reload.autocomplete("extension")
@unload.autocomplete("extension")
async def ext_reload_autocomplete(
self, interaction: discord.Interaction, current: str
) -> list[app_commands.Choice[str]]:
"""Autocomplete for the extension argument."""
return [
app_commands.Choice(name=ext.stem.lower(), value=ext.stem.lower())
for ext in Path("wopr/exts").glob("*.py")
if current.lower() in ext.stem.lower()
app_commands.Choice(name=ext.split(".")[::-1][0], value=ext.split(".")[::-1][0])
for ext in self.bot.extensions
if current.lower() in ext.split(".")[::-1][0]
]


Expand Down

0 comments on commit 0417ba7

Please sign in to comment.