diff --git a/cogs/command_error.py b/cogs/command_error.py index 8ebb0b776..15b2652e0 100644 --- a/cogs/command_error.py +++ b/cogs/command_error.py @@ -44,14 +44,13 @@ async def on_application_command_error( error_code = error.original.ERROR_CODE elif isinstance(error, CheckAnyFailure): - # TODO: Remove type ignore comments once #349 is resolved # noqa: FIX002 - if CommandChecks.is_interaction_user_in_main_guild_failure(error.checks[0]): # type: ignore[arg-type] + if CommandChecks.is_interaction_user_in_main_guild_failure(error.checks[0]): message = ( f"You must be a member of the {self.bot.group_short_name} Discord server " "to use this command." ) - elif CommandChecks.is_interaction_user_has_committee_role_failure(error.checks[0]): # type: ignore[arg-type] + elif CommandChecks.is_interaction_user_has_committee_role_failure(error.checks[0]): message = ( f"Only {await self.bot.get_mention_string(self.bot.committee_role)} " "members can run this command." diff --git a/cogs/committee_actions_tracking.py b/cogs/committee_actions_tracking.py index 317456cf6..bdd9e9741 100644 --- a/cogs/committee_actions_tracking.py +++ b/cogs/committee_actions_tracking.py @@ -192,15 +192,15 @@ async def autocomplete_get_action_status( ctx: TeXBotAutocompleteContext, # noqa: ARG004 ) -> AbstractSet[discord.OptionChoice] | AbstractSet[str]: """Autocomplete callable that provides the set of possible Status' of actions.""" - status_options: Sequence[tuple[str, str]] = AssignedCommitteeAction._meta.get_field( - "status" - ).choices # type: ignore[assignment] + status_options: AbstractSet[discord.OptionChoice] = { + discord.OptionChoice(name=str(status.label), value=status.value) + for status in AssignedCommitteeAction.Status + } if not status_options: logger.error("The autocomplete could not find any action Status'!") - return set() - return {discord.OptionChoice(name=value, value=code) for code, value in status_options} + return status_options @committee_actions.command( name="create", description="Adds a new action with the specified description." diff --git a/cogs/kill.py b/cogs/kill.py index 0276b65d9..2a695fd2d 100644 --- a/cogs/kill.py +++ b/cogs/kill.py @@ -81,19 +81,18 @@ async def kill(self, ctx: TeXBotApplicationContext) -> None: interaction.type == discord.InteractionType.component # noqa: CAR180 and interaction.message.id == confirmation_message.id and ((committee_role in interaction.user.roles) if committee_role else True) - and "custom_id" in interaction.data - and interaction.data["custom_id"] in {"shutdown_confirm", "shutdown_cancel"} + and interaction.custom_id in {"shutdown_confirm", "shutdown_cancel"} ), ) - if button_interaction.data["custom_id"] == "shutdown_confirm": # type: ignore[index, typeddict-item] + if button_interaction.custom_id == "shutdown_confirm": await confirmation_message.edit( content="My battery is low and it's getting dark...", view=None, ) await self.bot.perform_kill_and_close(initiated_by_user=ctx.interaction.user) - if button_interaction.data["custom_id"] == "shutdown_cancel": # type: ignore[index, typeddict-item] + if button_interaction.custom_id == "shutdown_cancel": await confirmation_message.edit(content="Shutdown has been cancelled.", view=None) logger.info("Manual shutdown cancelled by %s.", ctx.interaction.user) return diff --git a/cogs/strike.py b/cogs/strike.py index 13756b41d..8da371ce7 100644 --- a/cogs/strike.py +++ b/cogs/strike.py @@ -290,12 +290,11 @@ async def _confirm_perform_moderation_action( interaction.type == discord.InteractionType.component # noqa: CAR180 and interaction.user == interaction_user and interaction.channel == button_callback_channel - and "custom_id" in interaction.data - and interaction.data["custom_id"] in {"yes_strike_member", "no_strike_member"} + and interaction.custom_id in {"yes_strike_member", "no_strike_member"} ), ) - if button_interaction.data["custom_id"] == "no_strike_member": # type: ignore[index, typeddict-item] + if button_interaction.custom_id == "no_strike_member": await button_interaction.edit_original_response( content=( "Aborted performing " @@ -306,7 +305,7 @@ async def _confirm_perform_moderation_action( ) return - if button_interaction.data["custom_id"] == "yes_strike_member": # type: ignore[index, typeddict-item] + if button_interaction.custom_id == "yes_strike_member": await perform_moderation_action( strike_user, actual_strike_amount, committee_member=interaction_user ) @@ -616,16 +615,12 @@ async def _confirm_manual_add_strike( # noqa: PLR0915 else (committee_role in interaction.user.roles) ) and interaction.channel == confirmation_message_channel - and "custom_id" in interaction.data - and interaction.data["custom_id"] + and interaction.custom_id in {"yes_out_of_sync_ban_member", "no_out_of_sync_ban_member"} ), ) - if ( - out_of_sync_ban_button_interaction.data["custom_id"] # type: ignore[index, typeddict-item] - == "no_out_of_sync_ban_member" - ): + if out_of_sync_ban_button_interaction.custom_id == "no_out_of_sync_ban_member": await out_of_sync_ban_confirmation_message.edit( content=( f"Aborted performing ban action upon {strike_user.mention}. " @@ -643,10 +638,7 @@ async def _confirm_manual_add_strike( # noqa: PLR0915 await out_of_sync_ban_confirmation_message.delete() return - if ( - out_of_sync_ban_button_interaction.data["custom_id"] # type: ignore[index, typeddict-item] - == "yes_out_of_sync_ban_member" - ): + if out_of_sync_ban_button_interaction.custom_id == "yes_out_of_sync_ban_member": await self._send_strike_user_message(strike_user, member_strikes) await main_guild.ban( strike_user, @@ -713,8 +705,7 @@ async def _confirm_manual_add_strike( # noqa: PLR0915 else (committee_role in interaction.user.roles) ) and interaction.channel == confirmation_message_channel - and "custom_id" in interaction.data - and interaction.data["custom_id"] + and interaction.custom_id in { "yes_manual_moderation_action", "no_manual_moderation_action", @@ -722,7 +713,7 @@ async def _confirm_manual_add_strike( # noqa: PLR0915 ), ) - if button_interaction.data["custom_id"] == "no_manual_moderation_action": # type: ignore[index, typeddict-item] + if button_interaction.custom_id == "no_manual_moderation_action": await confirmation_message.edit( content=( f"Aborted increasing {strike_user.mention}'s strikes " @@ -741,7 +732,7 @@ async def _confirm_manual_add_strike( # noqa: PLR0915 await confirmation_message.delete() return - if button_interaction.data["custom_id"] == "yes_manual_moderation_action": # type: ignore[index, typeddict-item] + if button_interaction.custom_id == "yes_manual_moderation_action": interaction_user: discord.User | None = await self.bot.get_or_fetch( discord.User, applied_action_user.id ) diff --git a/config.py b/config.py index 98383ed82..146c98229 100644 --- a/config.py +++ b/config.py @@ -25,7 +25,7 @@ lazy import json lazy import os lazy import re -lazy from collections.abc import Iterable, Mapping, Sequence +lazy from collections.abc import Collection, Mapping, Sequence lazy from collections.abc import Set as AbstractSet lazy from logging import Logger lazy from typing import IO, Any, ClassVar, Final, LiteralString @@ -462,16 +462,13 @@ def _setup_welcome_messages(cls) -> None: if "welcome_messages" not in messages_dict: raise MessagesJSONFileMissingKeyError(missing_key="welcome_messages") - WELCOME_MESSAGES_KEY_IS_VALID: Final[bool] = bool( - isinstance(messages_dict["welcome_messages"], Iterable) - and messages_dict["welcome_messages"] - ) - if not WELCOME_MESSAGES_KEY_IS_VALID: + welcome_messages: object = messages_dict["welcome_messages"] + if not isinstance(welcome_messages, Collection) or not welcome_messages: raise MessagesJSONFileValueError( - dict_key="welcome_messages", invalid_value=messages_dict["welcome_messages"] + dict_key="welcome_messages", invalid_value=welcome_messages ) - cls._settings["WELCOME_MESSAGES"] = set(messages_dict["welcome_messages"]) # type: ignore[call-overload] + cls._settings["WELCOME_MESSAGES"] = set(welcome_messages) @classmethod def _setup_roles_messages(cls) -> None: @@ -482,15 +479,13 @@ def _setup_roles_messages(cls) -> None: if "roles_messages" not in messages_dict: raise MessagesJSONFileMissingKeyError(missing_key="roles_messages") - ROLES_MESSAGES_KEY_IS_VALID: Final[bool] = isinstance( - messages_dict["roles_messages"], Iterable - ) and bool(messages_dict["roles_messages"]) - if not ROLES_MESSAGES_KEY_IS_VALID: + roles_messages: object = messages_dict["roles_messages"] + if not isinstance(roles_messages, Collection) or not roles_messages: raise MessagesJSONFileValueError( - dict_key="roles_messages", invalid_value=messages_dict["roles_messages"] + dict_key="roles_messages", invalid_value=roles_messages ) - cls._settings["ROLES_MESSAGES"] = set(messages_dict["roles_messages"]) # type: ignore[call-overload] + cls._settings["ROLES_MESSAGES"] = set(roles_messages) @classmethod def _setup_organisation_id(cls) -> None: diff --git a/utils/command_checks.py b/utils/command_checks.py index 3f0307658..a4fe854ae 100644 --- a/utils/command_checks.py +++ b/utils/command_checks.py @@ -6,7 +6,7 @@ lazy from typing import Concatenate lazy from discord.ext import commands -lazy from discord.ext.commands import CheckFailure +lazy from discord.ext.commands import Bot, Context lazy from exceptions import DiscordMemberNotInMainGuildError @@ -66,11 +66,15 @@ async def check_interaction_user_has_committee_role( )(func) @classmethod - def is_interaction_user_in_main_guild_failure(cls, check: CheckFailure) -> bool: + def is_interaction_user_in_main_guild_failure( + cls, check: Callable[[Context[Bot]], bool] + ) -> bool: """Whether the check failed due to the user not being in your Discord guild.""" - return bool(check.__name__ == cls.check_interaction_user_in_main_guild.__name__) # type: ignore[attr-defined] + return bool(check.__name__ == cls.check_interaction_user_in_main_guild.__name__) @classmethod - def is_interaction_user_has_committee_role_failure(cls, check: CheckFailure) -> bool: + def is_interaction_user_has_committee_role_failure( + cls, check: Callable[[Context[Bot]], bool] + ) -> bool: """Whether the check failed due to the user not having the committee role.""" - return bool(check.__name__ == cls.check_interaction_user_has_committee_role.__name__) # type: ignore[attr-defined] + return bool(check.__name__ == cls.check_interaction_user_has_committee_role.__name__) diff --git a/utils/tex_bot.py b/utils/tex_bot.py index 58327c153..c7da9e1ee 100644 --- a/utils/tex_bot.py +++ b/utils/tex_bot.py @@ -85,14 +85,12 @@ def main_guild(self) -> discord.Guild: Raises `GuildDoesNotExist` if the given ID does not link to a valid Discord guild. """ - MAIN_GUILD_EXISTS: Final[bool] = bool( - self._main_guild - and self._check_guild_accessible(settings["_DISCORD_MAIN_GUILD_ID"]) - ) - if not MAIN_GUILD_EXISTS: + if self._main_guild is None or not self._check_guild_accessible( + settings["_DISCORD_MAIN_GUILD_ID"] + ): raise GuildDoesNotExistError(guild_id=settings["_DISCORD_MAIN_GUILD_ID"]) - return self._main_guild # type: ignore[return-value] + return self._main_guild @property async def committee_role(self) -> discord.Role: