mirror of
https://github.com/neoarz/Syntrel.git
synced 2025-12-25 03:40:11 +01:00
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 <email@neoarz.dev>
This commit is contained in:
6
bot.py
6
bot.py
@@ -280,6 +280,6 @@ if __name__ == "__main__":
|
|||||||
try:
|
try:
|
||||||
bot.run(os.getenv("TOKEN"))
|
bot.run(os.getenv("TOKEN"))
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
pass
|
logger.info("Received keyboard interrupt")
|
||||||
except Exception:
|
except Exception as e:
|
||||||
pass
|
logger.critical(f"Fatal error during bot execution: {type(e).__name__}: {e}")
|
||||||
@@ -30,39 +30,9 @@ class Idevice(commands.GroupCog, name="idevice"):
|
|||||||
view = ideviceView(self.bot)
|
view = ideviceView(self.bot)
|
||||||
await context.send(embed=embed, view=view)
|
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")
|
@idevice_group.command(name="errorcodes")
|
||||||
async def idevice_group_errorcodes(self, context: Context):
|
async def idevice_group_errorcodes(self, context: Context, *, error_code: str = None):
|
||||||
await self._invoke_hybrid(context, "errorcodes")
|
await self._invoke_hybrid(context, "errorcodes", error_code=error_code)
|
||||||
|
|
||||||
@idevice_group.command(name="developermode")
|
@idevice_group.command(name="developermode")
|
||||||
async def idevice_group_developermode(self, context: Context):
|
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):
|
async def idevice_group_mountddi(self, context: Context):
|
||||||
await self._invoke_hybrid(context, "mountddi")
|
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")
|
@app_commands.command(name="help", description="idevice troubleshooting help")
|
||||||
async def help(self, interaction: discord.Interaction):
|
async def help(self, interaction: discord.Interaction):
|
||||||
embed = discord.Embed(
|
embed = discord.Embed(
|
||||||
@@ -94,7 +81,7 @@ class Idevice(commands.GroupCog, name="idevice"):
|
|||||||
name="errorcodes", description="Look up error codes and their meanings."
|
name="errorcodes", description="Look up error codes and their meanings."
|
||||||
)
|
)
|
||||||
async def errorcodes(self, context, *, error_code: str = None):
|
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.check(_require_group_prefix)
|
||||||
@commands.hybrid_command(
|
@commands.hybrid_command(
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import os
|
|||||||
import discord
|
import discord
|
||||||
from discord import app_commands
|
from discord import app_commands
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
from discord.ext.commands import Context
|
|
||||||
|
|
||||||
|
|
||||||
def errorcodes_command():
|
def errorcodes_command():
|
||||||
@@ -11,7 +10,16 @@ def errorcodes_command():
|
|||||||
name="errorcodes", description="Look up an idevice error code by name or number"
|
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")
|
@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():
|
def load_errors():
|
||||||
json_path = os.path.join(os.path.dirname(__file__), "files/errorcodes.json")
|
json_path = os.path.join(os.path.dirname(__file__), "files/errorcodes.json")
|
||||||
try:
|
try:
|
||||||
@@ -35,6 +43,8 @@ def errorcodes_command():
|
|||||||
try:
|
try:
|
||||||
num = int(name)
|
num = int(name)
|
||||||
key = code_to_key.get(num)
|
key = code_to_key.get(num)
|
||||||
|
if key is None and num > 0:
|
||||||
|
key = code_to_key.get(-num)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
key = None
|
key = None
|
||||||
if key is None or key not in key_to_data:
|
if key is None or key not in key_to_data:
|
||||||
|
|||||||
@@ -172,7 +172,7 @@ class ideviceSelect(discord.ui.Select):
|
|||||||
|
|
||||||
success_embed = discord.Embed(
|
success_embed = discord.Embed(
|
||||||
title="Command Executed",
|
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,
|
color=0x00FF00,
|
||||||
)
|
)
|
||||||
success_embed.set_author(
|
success_embed.set_author(
|
||||||
|
|||||||
Reference in New Issue
Block a user