From aea98a95d5dca3c69b29aaea4cbd3adaba5e24ae Mon Sep 17 00:00:00 2001 From: neoarz Date: Mon, 29 Sep 2025 08:24:14 -0400 Subject: [PATCH] refactor(idevice): cog commands and add help group Reworked the idevice cog to use a command group with subcommands for help, errorcodes, developermode, noapps, and mountddi. Added a dropdown view for help commands and improved logging for extension loading. Updated references to ideviceView and adjusted extension load conditions in bot.py. --- bot.py | 2 +- cogs/idevice/__init__.py | 67 +++++++++++++++++++++++++++++++++++----- 2 files changed, 61 insertions(+), 8 deletions(-) diff --git a/bot.py b/bot.py index 457f0a2..f9cfe5d 100644 --- a/bot.py +++ b/bot.py @@ -90,7 +90,7 @@ class DiscordBot(commands.Bot): if os.path.exists(init_file): try: await self.load_extension(f"cogs.{folder}") - if folder not in ["owner"]: + if folder in ["owner", "help"]: self.logger.info(f"Loaded extension '{folder}'") except Exception as e: exception = f"{type(e).__name__}: {e}" diff --git a/cogs/idevice/__init__.py b/cogs/idevice/__init__.py index 3bdda61..2f3cf5e 100644 --- a/cogs/idevice/__init__.py +++ b/cogs/idevice/__init__.py @@ -1,8 +1,9 @@ import discord +from discord import app_commands from discord.ext import commands from discord.ext.commands import Context -from .idevice import idevice_command +from .idevice import ideviceView from .error_codes import errorcodes_command from .developermode import developermode_command from .noapps import noapps_command @@ -13,12 +14,64 @@ class Idevice(commands.GroupCog, name="idevice"): self.bot = bot super().__init__() - @commands.hybrid_command( - name="idevice", - description="Get help with idevice commands and troubleshooting." + @commands.group(name="idevice", invoke_without_command=True) + async def idevice_group(self, context: Context): + embed = discord.Embed( + title="idevice Commands", + description="Choose a command from the dropdown below to get help with specific issues:", + color=0xfa8c4a + ) + embed.set_author(name="idevice", icon_url="https://yes.nighty.works/raw/snLMuO.png") + view = ideviceView(self.bot) + await context.send(embed=embed, view=view) + + @idevice_group.command(name="help") + async def idevice_group_help(self, context: Context): + embed = discord.Embed( + title="idevice Commands", + description="Choose a command from the dropdown below to get help with specific issues:", + color=0xfa8c4a + ) + embed.set_author(name="idevice", icon_url="https://yes.nighty.works/raw/snLMuO.png") + view = ideviceView(self.bot) + await context.send(embed=embed, view=view) + + async def _invoke_hybrid(self, context: Context, name: str): + command = self.bot.get_command(name) + if command is not None: + await context.invoke(command) + else: + await context.send(f"Unknown idevice command: {name}") + + @idevice_group.command(name="errorcodes") + async def idevice_group_errorcodes(self, context: Context): + await self._invoke_hybrid(context, "errorcodes") + + @idevice_group.command(name="developermode") + async def idevice_group_developermode(self, context: Context): + await self._invoke_hybrid(context, "developermode") + + @idevice_group.command(name="noapps") + async def idevice_group_noapps(self, context: Context): + await self._invoke_hybrid(context, "noapps") + + @idevice_group.command(name="mountddi") + async def idevice_group_mountddi(self, context: Context): + await self._invoke_hybrid(context, "mountddi") + + @app_commands.command( + name="help", + description="idevice troubleshooting help" ) - async def idevice(self, context): - return await idevice_command()(self, context) + async def help(self, interaction: discord.Interaction): + embed = discord.Embed( + title="idevice Commands", + description="Choose a command from the dropdown below to get help with specific issues:", + color=0xfa8c4a + ) + embed.set_author(name="idevice", icon_url="https://yes.nighty.works/raw/snLMuO.png") + view = ideviceView(self.bot) + await interaction.response.send_message(embed=embed, view=view, ephemeral=True) @commands.hybrid_command( name="errorcodes", @@ -52,7 +105,7 @@ async def setup(bot) -> None: cog = Idevice(bot) await bot.add_cog(cog) - bot.logger.info("Loaded extension 'idevice.idevice'") + bot.logger.info("Loaded extension 'idevice.help'") bot.logger.info("Loaded extension 'idevice.errorcodes'") bot.logger.info("Loaded extension 'idevice.developermode'") bot.logger.info("Loaded extension 'idevice.noapps'")