fix(security): autofix Dangerous use of assert
This commit is contained in:
parent
120c88beb1
commit
4b9fd4f48d
4 changed files with 14 additions and 7 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue