Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions cogs/command_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
10 changes: 5 additions & 5 deletions cogs/committee_actions_tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment thread
MattyTheHacker marked this conversation as resolved.
Resolved
}

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."
Expand Down
7 changes: 3 additions & 4 deletions cogs/kill.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 9 additions & 18 deletions cogs/strike.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand All @@ -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
)
Expand Down Expand Up @@ -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}. "
Expand All @@ -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,
Expand Down Expand Up @@ -713,16 +705,15 @@ 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",
}
),
)

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 "
Expand All @@ -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
)
Expand Down
23 changes: 9 additions & 14 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down
14 changes: 9 additions & 5 deletions utils/command_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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__)
10 changes: 4 additions & 6 deletions utils/tex_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down