Compare commits

...
Sign in to create a new pull request.

1 commit

Author SHA1 Message Date
aikido-autofix[bot]
4b9fd4f48d
fix(security): autofix Dangerous use of assert 2026-08-21 13:29:38 +00:00
4 changed files with 14 additions and 7 deletions

View file

@ -135,7 +135,8 @@ class UserSlash(commands.Cog):
self, before: discord.User, after: discord.User
) -> None:
"""Update the slash-command name when the bot's username changes."""
assert self.bot.user
if not self.bot.user:
raise AssertionError
if after.id != self.bot.user.id or before.name == after.name:
return

View file

@ -63,7 +63,8 @@ class InterContext(commands.Context):
try:
self = contexts.get()
if recreate_message:
assert self.prefix is not None
if self.prefix is None:
raise AssertionError
self.message._recreate_from_interaction(interaction, prefix)
view = self.view = StringView(self.message.content)
view.skip_string(self.prefix)
@ -155,7 +156,8 @@ class InterContext(commands.Context):
command = self.bot.get_command(command) or command
signature: str
if signature := getattr(command, "signature", ""):
assert not isinstance(command, str)
if isinstance(command, str):
raise AssertionError()
command = copy(command)
command.usage = f"arguments:{signature}"
return await super().send_help(command)

View file

@ -49,7 +49,8 @@ class InterMessage(discord.Message):
def _from_interaction(
cls, interaction: discord.Interaction, prefix: str
) -> "InterMessage":
assert interaction.data
if not interaction.data:
raise AssertionError
assert interaction.client.user
self = cls.__new__(cls)
@ -126,7 +127,8 @@ class InterMessage(discord.Message):
@staticmethod
def _make_dm_channel(interaction: discord.Interaction) -> discord.DMChannel:
"""Fabricate a minimal DMChannel when the real one is unavailable."""
assert interaction.client.user
if not interaction.client.user:
raise AssertionError
user = interaction.user
user_json = (
user._to_minimal_user_json()
@ -156,7 +158,8 @@ class InterMessage(discord.Message):
def _recreate_from_interaction(
self, interaction: discord.Interaction, prefix: str
) -> None:
assert interaction.data and interaction.client.user
if not (interaction.data and interaction.client.user):
raise AssertionError
self.content = f"{prefix}{interaction.namespace.command}"
if interaction.namespace.arguments:

View file

@ -357,7 +357,8 @@ async def _autocomplete(
@user_slash_command.error
async def _error(interaction: discord.Interaction, error: Exception):
assert isinstance(interaction.client, Red)
if not isinstance(interaction.client, Red):
raise AssertionError
# Log the original error for debugging
LOG.error(f"Slash command error for user {interaction.user.id}: {error}", exc_info=error)