From bafd8fc19abd9a49e005ea999e3d22970cb152cb Mon Sep 17 00:00:00 2001 From: Daisuke <144384874+daisuke1227@users.noreply.github.com> Date: Sat, 15 Nov 2025 20:46:39 -0500 Subject: [PATCH] fix: idevice errorcodes bug (#24) * very easy fix * Added self hosting instructions * nvm this was the actual fix nooo way * removed instructions :3 * fix: some stuff --------- Co-authored-by: neoarz --- bot.py | 6 ++--- cogs/idevice/__init__.py | 53 ++++++++++++++----------------------- cogs/idevice/error_codes.py | 14 ++++++++-- cogs/idevice/idevice.py | 2 +- 4 files changed, 36 insertions(+), 39 deletions(-) diff --git a/bot.py b/bot.py index 2840600..eafa03f 100644 --- a/bot.py +++ b/bot.py @@ -280,6 +280,6 @@ if __name__ == "__main__": try: bot.run(os.getenv("TOKEN")) except KeyboardInterrupt: - pass - except Exception: - pass + logger.info("Received keyboard interrupt") + except Exception as e: + logger.critical(f"Fatal error during bot execution: {type(e).__name__}: {e}") \ No newline at end of file diff --git a/cogs/idevice/__init__.py b/cogs/idevice/__init__.py index ecd4d90..e44fc53 100644 --- a/cogs/idevice/__init__.py +++ b/cogs/idevice/__init__.py @@ -30,39 +30,9 @@ class Idevice(commands.GroupCog, name="idevice"): 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}") - - def _require_group_prefix(context: Context) -> bool: - if getattr(context, "interaction", None): - return True - group = getattr(getattr(context, "cog", None), "qualified_name", "").lower() - if not group: - return True - prefix = context.prefix or "" - content = context.message.content.strip().lower() - return content.startswith(f"{prefix}{group} ") - @idevice_group.command(name="errorcodes") - async def idevice_group_errorcodes(self, context: Context): - await self._invoke_hybrid(context, "errorcodes") + async def idevice_group_errorcodes(self, context: Context, *, error_code: str = None): + await self._invoke_hybrid(context, "errorcodes", error_code=error_code) @idevice_group.command(name="developermode") async def idevice_group_developermode(self, context: Context): @@ -76,6 +46,23 @@ class Idevice(commands.GroupCog, name="idevice"): async def idevice_group_mountddi(self, context: Context): await self._invoke_hybrid(context, "mountddi") + async def _invoke_hybrid(self, context: Context, name: str, **kwargs): + command = self.bot.get_command(name) + if command is not None: + await context.invoke(command, **kwargs) + else: + await context.send(f"Unknown idevice command: {name}") + + def _require_group_prefix(context: Context) -> bool: + if getattr(context, "interaction", None): + return True + group = getattr(getattr(context, "cog", None), "qualified_name", "").lower() + if not group: + return True + prefix = context.prefix or "" + content = context.message.content.strip().lower() + return content.startswith(f"{prefix}{group} ") + @app_commands.command(name="help", description="idevice troubleshooting help") async def help(self, interaction: discord.Interaction): embed = discord.Embed( @@ -94,7 +81,7 @@ class Idevice(commands.GroupCog, name="idevice"): name="errorcodes", description="Look up error codes and their meanings." ) async def errorcodes(self, context, *, error_code: str = None): - return await errorcodes_command()(self, context, error_code=error_code) + return await errorcodes_command()(self, context, name=error_code) @commands.check(_require_group_prefix) @commands.hybrid_command( diff --git a/cogs/idevice/error_codes.py b/cogs/idevice/error_codes.py index e22bbd5..2e857ed 100644 --- a/cogs/idevice/error_codes.py +++ b/cogs/idevice/error_codes.py @@ -3,7 +3,6 @@ import os import discord from discord import app_commands from discord.ext import commands -from discord.ext.commands import Context def errorcodes_command(): @@ -11,7 +10,16 @@ def errorcodes_command(): name="errorcodes", description="Look up an idevice error code by name or number" ) @app_commands.describe(name="Start typing to search all error names and codes") - async def errorcodes(self, context, name: str): + async def errorcodes(self, context, name: str | None = None): + if name is None: + if context.interaction: + await context.interaction.response.send_message( + "Please provide an error code.", ephemeral=True + ) + else: + await context.send("Please provide an error code.") + return + def load_errors(): json_path = os.path.join(os.path.dirname(__file__), "files/errorcodes.json") try: @@ -35,6 +43,8 @@ def errorcodes_command(): try: num = int(name) key = code_to_key.get(num) + if key is None and num > 0: + key = code_to_key.get(-num) except ValueError: key = None if key is None or key not in key_to_data: diff --git a/cogs/idevice/idevice.py b/cogs/idevice/idevice.py index f1a152f..cb3c344 100644 --- a/cogs/idevice/idevice.py +++ b/cogs/idevice/idevice.py @@ -172,7 +172,7 @@ class ideviceSelect(discord.ui.Select): success_embed = discord.Embed( title="Command Executed", - description="Successfully executed `/errorcodes`. Please run /[errorcode_name] to get more information about an error code, and send it in chat", + description="Successfully executed `/errorcodes`. Please run /[errorcode_number] to get more information about an error code, and send it in chat", color=0x00FF00, ) success_embed.set_author(