diff --git a/cogs/idevice/error_codes.py b/cogs/idevice/error_codes.py index 8334f5d..e41b08f 100644 --- a/cogs/idevice/error_codes.py +++ b/cogs/idevice/error_codes.py @@ -1,83 +1,28 @@ +import json +import os import discord from discord import app_commands from discord.ext import commands -ERRORS = [ - ("socket", "device socket io failed", -1), - ("pem_parse_failed", "PEM parse failed", -2), - ("rustls", "TLS error", -3), - ("tls_builder_failed", "TLS verifiction build failed", -4), - ("plist", "io on plist", -5), - ("utf8", "can't convert bytes to utf8", -6), - ("unexpected_response", "unexpected response from device", -7), - ("get_prohibited", "this request was prohibited", -8), - ("session_inactive", "no SSL session is active", -9), - ("invalid_host_id", "device does not have pairing file", -10), - ("no_established_connection", "no established connection", -11), - ("heartbeat_sleepy_time", "device went to sleep", -12), - ("heartbeat_timeout", "heartbeat timeout", -13), - ("not_found", "not found", -14), - ("service_not_found", "service not found", -15), - ("cdtunnel_packet_too_short", "CDTunnel packet too short", -16), - ("cdtunnel_packet_invalid_magic", "CDTunnel packet invalid magic", -17), - ("packet_size_mismatch", "Proclaimed packet size does not match actual size", -18), - ("json", "JSON serialization failed", -19), - ("device_not_found", "device not found", -20), - ("device_locked", "device lockded", -21), - ("usb_connection_refused", "device refused connection", -22), - ("usb_bad_command", "bad command", -23), - ("usb_bad_device", "bad device", -24), - ("usb_bad_version", "usb bad version", -25), - ("bad_build_manifest", "bad build manifest", -26), - ("image_not_mounted", "image not mounted", -27), - ("pairing_dialog_response_pending", "pairing trust dialog pending", -28), - ("user_denied_pairing", "user denied pairing trust", -29), - ("password_protected", "device is locked", -30), - ("misagent_failure", "misagent operation failed", -31), - ("installation_proxy_operation_failed", "installation proxy operation failed", -32), - ("afc", "afc error", -33), - ("unknown_afc_opcode", "unknown afc opcode", -34), - ("invalid_afc_magic", "invalid afc magic", -35), - ("afc_missing_attribute", "missing file attribute", -36), - ("crash_report_mover_bad_response", "crash report mover sent the wrong response", -37), - ("reqwest", "http reqwest error", -38), - ("internal_error", "internal error", -39), - ("unknown_frame", "unknown http frame type", -40), - ("unknown_http_setting", "unknown http setting type", -41), - ("uninitialized_stream_id", "Unintialized stream ID", -42), - ("unknown_xpc_type", "unknown XPC type", -43), - ("malformed_xpc", "malformed XPC message", -44), - ("invalid_xpc_magic", "invalid XPC magic", -45), - ("unexpected_xpc_version", "unexpected XPC version", -46), - ("invalid_c_string", "invalid C string", -47), - ("http_stream_reset", "stream reset", -48), - ("http_go_away", "go away packet received", -49), - ("ns_keyed_archive_error", "NSKeyedArchive error", -50), - ("unknown_aux_value_type", "Unknown aux value type", -51), - ("unknown_channel", "unknown channel", -52), - ("addr_parse_error", "cannot parse string as IpAddr", -53), - ("disable_memory_limit_failed", "disable memory limit failed", -54), - ("not_enough_bytes", "not enough bytes", -55), - ("utf8_error", "failed to parse bytes as valid utf8", -56), - ("invalid_argument", "invalid argument passed", -57), - ("unknown_error_type", "unknown error returned from device", -59), - ("ffi_invalid_arg", "invalid arguments were passed", -60), - ("ffi_invalid_string", "invalid string was passed", -61), - ("ffi_buffer_too_small", "buffer passed is too small", -62), - ("unsupported_watch_key", "unsupported watch key", -63), - ("malformed_command", "malformed command", -64), - ("integer_overflow", "integer overflow", -65), - ("canceled_by_user", "canceled by user", -66), - ("malformed_package_archive", "malformed package archive", -67), -] - - class ErrorCodes(commands.Cog, name="errorcodes"): def __init__(self, bot) -> None: self.bot = bot - self.key_to_data = {k: (t, c) for k, t, c in ERRORS} - self.code_to_key = {c: k for k, _, c in ERRORS} + self.errors = self.load_errors() + self.key_to_data = {error['name']: (error['description'], error['code']) for error in self.errors} + self.code_to_key = {error['code']: error['name'] for error in self.errors} + + def load_errors(self): + json_path = os.path.join(os.path.dirname(__file__), 'errorcodes.json') + try: + with open(json_path, 'r', encoding='utf-8') as f: + return json.load(f) + except FileNotFoundError: + self.bot.logger.error(f"Error codes JSON file not found: {json_path}") + return [] + except json.JSONDecodeError as e: + self.bot.logger.error(f"Error parsing error codes JSON: {e}") + return [] async def errorcode_autocomplete(self, interaction: discord.Interaction, current: str): current_lower = current.lower() @@ -103,7 +48,9 @@ class ErrorCodes(commands.Cog, name="errorcodes"): if key is None or key not in self.key_to_data: await interaction.response.send_message("Error not found.", ephemeral=True) return + title, code = self.key_to_data[key] + embed = discord.Embed( description=f"## Error Code: {code}\n\n**Name**: `{key}`\n**Description**: {title}", color=0xfa8c4a, diff --git a/cogs/idevice/errorcodes.json b/cogs/idevice/errorcodes.json new file mode 100644 index 0000000..afeb44f --- /dev/null +++ b/cogs/idevice/errorcodes.json @@ -0,0 +1,332 @@ +[ + { + "name": "socket", + "description": "device socket io failed", + "code": -1 + }, + { + "name": "pem_parse_failed", + "description": "PEM parse failed", + "code": -2 + }, + { + "name": "rustls", + "description": "TLS error", + "code": -3 + }, + { + "name": "tls_builder_failed", + "description": "TLS verifiction build failed", + "code": -4 + }, + { + "name": "plist", + "description": "io on plist", + "code": -5 + }, + { + "name": "utf8", + "description": "can't convert bytes to utf8", + "code": -6 + }, + { + "name": "unexpected_response", + "description": "unexpected response from device", + "code": -7 + }, + { + "name": "get_prohibited", + "description": "this request was prohibited", + "code": -8 + }, + { + "name": "session_inactive", + "description": "no SSL session is active", + "code": -9 + }, + { + "name": "invalid_host_id", + "description": "device does not have pairing file", + "code": -10 + }, + { + "name": "no_established_connection", + "description": "no established connection", + "code": -11 + }, + { + "name": "heartbeat_sleepy_time", + "description": "device went to sleep", + "code": -12 + }, + { + "name": "heartbeat_timeout", + "description": "heartbeat timeout", + "code": -13 + }, + { + "name": "not_found", + "description": "not found", + "code": -14 + }, + { + "name": "service_not_found", + "description": "service not found", + "code": -15 + }, + { + "name": "cdtunnel_packet_too_short", + "description": "CDTunnel packet too short", + "code": -16 + }, + { + "name": "cdtunnel_packet_invalid_magic", + "description": "CDTunnel packet invalid magic", + "code": -17 + }, + { + "name": "packet_size_mismatch", + "description": "Proclaimed packet size does not match actual size", + "code": -18 + }, + { + "name": "json", + "description": "JSON serialization failed", + "code": -19 + }, + { + "name": "device_not_found", + "description": "device not found", + "code": -20 + }, + { + "name": "device_locked", + "description": "device lockded", + "code": -21 + }, + { + "name": "usb_connection_refused", + "description": "device refused connection", + "code": -22 + }, + { + "name": "usb_bad_command", + "description": "bad command", + "code": -23 + }, + { + "name": "usb_bad_device", + "description": "bad device", + "code": -24 + }, + { + "name": "usb_bad_version", + "description": "usb bad version", + "code": -25 + }, + { + "name": "bad_build_manifest", + "description": "bad build manifest", + "code": -26 + }, + { + "name": "image_not_mounted", + "description": "image not mounted", + "code": -27 + }, + { + "name": "pairing_dialog_response_pending", + "description": "pairing trust dialog pending", + "code": -28 + }, + { + "name": "user_denied_pairing", + "description": "user denied pairing trust", + "code": -29 + }, + { + "name": "password_protected", + "description": "device is locked", + "code": -30 + }, + { + "name": "misagent_failure", + "description": "misagent operation failed", + "code": -31 + }, + { + "name": "installation_proxy_operation_failed", + "description": "installation proxy operation failed", + "code": -32 + }, + { + "name": "afc", + "description": "afc error", + "code": -33 + }, + { + "name": "unknown_afc_opcode", + "description": "unknown afc opcode", + "code": -34 + }, + { + "name": "invalid_afc_magic", + "description": "invalid afc magic", + "code": -35 + }, + { + "name": "afc_missing_attribute", + "description": "missing file attribute", + "code": -36 + }, + { + "name": "crash_report_mover_bad_response", + "description": "crash report mover sent the wrong response", + "code": -37 + }, + { + "name": "reqwest", + "description": "http reqwest error", + "code": -38 + }, + { + "name": "internal_error", + "description": "internal error", + "code": -39 + }, + { + "name": "unknown_frame", + "description": "unknown http frame type", + "code": -40 + }, + { + "name": "unknown_http_setting", + "description": "unknown http setting type", + "code": -41 + }, + { + "name": "uninitialized_stream_id", + "description": "Unintialized stream ID", + "code": -42 + }, + { + "name": "unknown_xpc_type", + "description": "unknown XPC type", + "code": -43 + }, + { + "name": "malformed_xpc", + "description": "malformed XPC message", + "code": -44 + }, + { + "name": "invalid_xpc_magic", + "description": "invalid XPC magic", + "code": -45 + }, + { + "name": "unexpected_xpc_version", + "description": "unexpected XPC version", + "code": -46 + }, + { + "name": "invalid_c_string", + "description": "invalid C string", + "code": -47 + }, + { + "name": "http_stream_reset", + "description": "stream reset", + "code": -48 + }, + { + "name": "http_go_away", + "description": "go away packet received", + "code": -49 + }, + { + "name": "ns_keyed_archive_error", + "description": "NSKeyedArchive error", + "code": -50 + }, + { + "name": "unknown_aux_value_type", + "description": "Unknown aux value type", + "code": -51 + }, + { + "name": "unknown_channel", + "description": "unknown channel", + "code": -52 + }, + { + "name": "addr_parse_error", + "description": "cannot parse string as IpAddr", + "code": -53 + }, + { + "name": "disable_memory_limit_failed", + "description": "disable memory limit failed", + "code": -54 + }, + { + "name": "not_enough_bytes", + "description": "not enough bytes", + "code": -55 + }, + { + "name": "utf8_error", + "description": "failed to parse bytes as valid utf8", + "code": -56 + }, + { + "name": "invalid_argument", + "description": "invalid argument passed", + "code": -57 + }, + { + "name": "unknown_error_type", + "description": "unknown error returned from device", + "code": -59 + }, + { + "name": "ffi_invalid_arg", + "description": "invalid arguments were passed", + "code": -60 + }, + { + "name": "ffi_invalid_string", + "description": "invalid string was passed", + "code": -61 + }, + { + "name": "ffi_buffer_too_small", + "description": "buffer passed is too small", + "code": -62 + }, + { + "name": "unsupported_watch_key", + "description": "unsupported watch key", + "code": -63 + }, + { + "name": "malformed_command", + "description": "malformed command", + "code": -64 + }, + { + "name": "integer_overflow", + "description": "integer overflow", + "code": -65 + }, + { + "name": "canceled_by_user", + "description": "canceled by user", + "code": -66 + }, + { + "name": "malformed_package_archive", + "description": "malformed package archive", + "code": -67 + } +] \ No newline at end of file diff --git a/cogs/idevice/idevice.py b/cogs/idevice/idevice.py index ae0f6cc..04c3e22 100644 --- a/cogs/idevice/idevice.py +++ b/cogs/idevice/idevice.py @@ -16,7 +16,7 @@ class ideviceSelect(discord.ui.Select): discord.SelectOption( label="Error Codes", value="errorcodes_ephemeral", - description="Browse idevice error code slash commands", + description="Browse idevice error codes", ), ] super().__init__(placeholder="Choose an idevice command...", options=options) @@ -27,13 +27,12 @@ class ideviceSelect(discord.ui.Select): if command_name == "errorcodes_ephemeral": embed = discord.Embed( - title="Idevice Error Codes", - description="Use /errorcode to search errors by name or number.", - color=0xfa8c4a, + title="Command Executed", + description=f"Successfully executed `/{command_name}`", + color=0x00FF00 ) embed.set_author(name="idevice", icon_url="https://yes.nighty.works/raw/snLMuO.png") await interaction.response.edit_message(embed=embed, view=None) - await interaction.followup.send(embed=embed, ephemeral=True) return if command: