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
2 changes: 1 addition & 1 deletion .python-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.13
3.14
4 changes: 2 additions & 2 deletions cogs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@

from utils import TeXBot, TeXBotBaseCog

__all__: "Sequence[str]" = (
__all__: Sequence[str] = (
"AddUsersToThreadsAndChannelsCommandCog",
"AnnualRolesResetCommandCog",
"AnnualYearChannelsIncrementCommandCog",
Expand Down Expand Up @@ -91,7 +91,7 @@
)


def setup(bot: "TeXBot") -> None:
def setup(bot: TeXBot) -> None:
"""Add all the cogs to the bot, at bot startup."""
cogs: Iterable[type[TeXBotBaseCog]] = (
AddUsersToThreadsAndChannelsCommandsCog,
Expand Down
18 changes: 9 additions & 9 deletions cogs/add_users_to_threads_and_channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,24 @@
from utils import TeXBotApplicationContext, TeXBotAutocompleteContext


__all__: "Sequence[str]" = ("AddUsersToThreadsAndChannelsCommandsCog",)
__all__: Sequence[str] = ("AddUsersToThreadsAndChannelsCommandsCog",)


logger: "Final[Logger]" = logging.getLogger("TeX-Bot")
logger: Final[Logger] = logging.getLogger("TeX-Bot")


class AddUsersToThreadsAndChannelsCommandsCog(TeXBotBaseCog):
"""Cog for adding users to threads."""

@staticmethod
async def autocomplete_get_members(
ctx: "TeXBotAutocompleteContext",
) -> "AbstractSet[discord.OptionChoice] | AbstractSet[str]":
ctx: TeXBotAutocompleteContext,
) -> AbstractSet[discord.OptionChoice] | AbstractSet[str]:
"""Autocomplete callable that generates the set of available selectable members."""
try:
main_guild: discord.Guild = ctx.bot.main_guild
guest_role: discord.Role = await ctx.bot.guest_role
except (GuildDoesNotExistError, GuestRoleDoesNotExistError):
except GuildDoesNotExistError, GuestRoleDoesNotExistError:
Comment thread
MattyTheHacker marked this conversation as resolved.
return set()

members: set[discord.Member] = {
Expand All @@ -58,8 +58,8 @@ async def autocomplete_get_members(

@staticmethod
async def autocomplete_get_roles(
ctx: "TeXBotAutocompleteContext",
) -> "AbstractSet[discord.OptionChoice] | AbstractSet[str]":
ctx: TeXBotAutocompleteContext,
) -> AbstractSet[discord.OptionChoice] | AbstractSet[str]:
"""Autocomplete callable that generates the set of available selectable roles."""
try:
main_guild: discord.Guild = ctx.bot.main_guild
Expand Down Expand Up @@ -205,7 +205,7 @@ async def on_thread_create(self, thread: discord.Thread) -> None:
@CommandChecks.check_interaction_user_in_main_guild
async def add_user_to_channel(
self,
ctx: "TeXBotApplicationContext",
ctx: TeXBotApplicationContext,
user_id_str: str,
silent: bool, # noqa: FBT001
) -> None:
Expand Down Expand Up @@ -260,7 +260,7 @@ async def add_user_to_channel(
@CommandChecks.check_interaction_user_in_main_guild
async def add_role_to_channel(
self,
ctx: "TeXBotApplicationContext",
ctx: TeXBotApplicationContext,
role_id_str: str,
silent: bool, # noqa: FBT001
) -> None:
Expand Down
12 changes: 6 additions & 6 deletions cogs/annual_handover_and_reset.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@

from utils import AllChannelTypes, TeXBotApplicationContext

__all__: "Sequence[str]" = (
__all__: Sequence[str] = (
"AnnualRolesResetCommandCog",
"AnnualYearChannelsIncrementCommandCog",
"CommitteeHandoverCommandCog",
)


logger: "Final[Logger]" = logging.getLogger("TeX-Bot")
logger: Final[Logger] = logging.getLogger("TeX-Bot")


class CommitteeHandoverCommandCog(TeXBotBaseCog):
Expand All @@ -36,7 +36,7 @@ class CommitteeHandoverCommandCog(TeXBotBaseCog):
)
@CommandChecks.check_interaction_user_has_committee_role
@CommandChecks.check_interaction_user_in_main_guild
async def committee_handover(self, ctx: "TeXBotApplicationContext") -> None:
async def committee_handover(self, ctx: TeXBotApplicationContext) -> None:
"""
Definition & callback response of the "committee_handover" command.

Expand Down Expand Up @@ -165,7 +165,7 @@ async def committee_handover(self, ctx: "TeXBotApplicationContext") -> None:
class AnnualRolesResetCommandCog(TeXBotBaseCog):
"""Cog class that defines the "/annual-roles-reset" command."""

ACADEMIC_YEAR_ROLE_NAMES: "Final[frozenset[str]]" = frozenset(
ACADEMIC_YEAR_ROLE_NAMES: Final[frozenset[str]] = frozenset(
{
"Foundation Year",
"First Year",
Expand All @@ -184,7 +184,7 @@ class AnnualRolesResetCommandCog(TeXBotBaseCog):
)
@CommandChecks.check_interaction_user_has_committee_role
@CommandChecks.check_interaction_user_in_main_guild
async def annual_roles_reset(self, ctx: "TeXBotApplicationContext") -> None:
async def annual_roles_reset(self, ctx: TeXBotApplicationContext) -> None:
"""
Definition & callback response of the "annual_roles_reset" command.

Expand Down Expand Up @@ -273,7 +273,7 @@ class AnnualYearChannelsIncrementCommandCog(TeXBotBaseCog):
)
@CommandChecks.check_interaction_user_has_committee_role
@CommandChecks.check_interaction_user_in_main_guild
async def increment_year_channels(self, ctx: "TeXBotApplicationContext") -> None:
async def increment_year_channels(self, ctx: TeXBotApplicationContext) -> None:
"""
Definition and callback response of the "increment_year_channels" command.

Expand Down
20 changes: 10 additions & 10 deletions cogs/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@

from utils import AllChannelTypes, TeXBotApplicationContext, TeXBotAutocompleteContext

__all__: "Sequence[str]" = ("ArchiveCommandsCog",)
__all__: Sequence[str] = ("ArchiveCommandsCog",)


logger: "Final[Logger]" = logging.getLogger("TeX-Bot")
logger: Final[Logger] = logging.getLogger("TeX-Bot")


class ArchiveCommandsCog(TeXBotBaseCog):
"""Cog class that defines the "/archive" command and its call-back method."""

@staticmethod
async def autocomplete_get_non_archival_categories(
ctx: "TeXBotAutocompleteContext",
) -> "AbstractSet[discord.OptionChoice] | AbstractSet[str]":
ctx: TeXBotAutocompleteContext,
) -> AbstractSet[discord.OptionChoice] | AbstractSet[str]:
"""
Autocomplete callable that generates the set of available selectable categories.

Expand All @@ -50,8 +50,8 @@ async def autocomplete_get_non_archival_categories(

@staticmethod
async def autocomplete_get_archival_categories(
ctx: "TeXBotAutocompleteContext",
) -> "AbstractSet[discord.OptionChoice] | AbstractSet[str]":
ctx: TeXBotAutocompleteContext,
) -> AbstractSet[discord.OptionChoice] | AbstractSet[str]:
"""
Autocomplete callable that generates the set of categories to hold archived channels.

Expand All @@ -72,8 +72,8 @@ async def autocomplete_get_archival_categories(

@staticmethod
async def autocomplete_get_non_archived_channels(
ctx: "TeXBotAutocompleteContext",
) -> "AbstractSet[discord.OptionChoice] | AbstractSet[str]":
ctx: TeXBotAutocompleteContext,
) -> AbstractSet[discord.OptionChoice] | AbstractSet[str]:
"""
Autocomplete callable that generates the set of channels that the user can archive.

Expand Down Expand Up @@ -123,7 +123,7 @@ async def autocomplete_get_non_archived_channels(
@CommandChecks.check_interaction_user_in_main_guild
async def archive_category(
self,
ctx: "TeXBotApplicationContext",
ctx: TeXBotApplicationContext,
str_category_id: str,
allow_archivist: bool, # noqa: FBT001
) -> None:
Expand Down Expand Up @@ -236,7 +236,7 @@ async def archive_category(
@CommandChecks.check_interaction_user_has_committee_role
@CommandChecks.check_interaction_user_in_main_guild
async def archive_channel(
self, ctx: "TeXBotApplicationContext", str_channel_id: str, str_category_id: str
self, ctx: TeXBotApplicationContext, str_channel_id: str, str_category_id: str
) -> None:
"""
Definition & callback response of the "archive-channel" command.
Expand Down
16 changes: 7 additions & 9 deletions cogs/check_su_platform_authorisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,17 @@

from utils import TeXBot, TeXBotApplicationContext

__all__: "Sequence[str]" = (
__all__: Sequence[str] = (
"CheckSUPlatformAuthorisationCommandCog",
"CheckSUPlatformAuthorisationTaskCog",
)


logger: "Final[Logger]" = logging.getLogger("TeX-Bot")
logger: Final[Logger] = logging.getLogger("TeX-Bot")


SU_PLATFORM_PROFILE_URL: "Final[str]" = "https://guildofstudents.com/profile"
SU_PLATFORM_ORGANISATION_URL: "Final[str]" = (
"https://www.guildofstudents.com/organisation/admin"
)
SU_PLATFORM_PROFILE_URL: Final[str] = "https://guildofstudents.com/profile"
SU_PLATFORM_ORGANISATION_URL: Final[str] = "https://www.guildofstudents.com/organisation/admin"


class SUPlatformAccessCookieStatus(Enum):
Expand Down Expand Up @@ -93,7 +91,7 @@ async def get_su_platform_access_cookie_status(self) -> SUPlatformAccessCookieSt
)
return SUPlatformAccessCookieStatus.INVALID

async def get_su_platform_organisations(self) -> "Iterable[str]":
async def get_su_platform_organisations(self) -> Iterable[str]:
"""Retrieve the MSL organisations the current SU platform cookie has access to."""
response_object: bs4.BeautifulSoup = bs4.BeautifulSoup(
await fetch_url_content_with_session(SU_PLATFORM_PROFILE_URL), "html.parser"
Expand Down Expand Up @@ -170,7 +168,7 @@ class CheckSUPlatformAuthorisationCommandCog(CheckSUPlatformAuthorisationBaseCog
)
@CommandChecks.check_interaction_user_has_committee_role
@CommandChecks.check_interaction_user_in_main_guild
async def check_su_platform_authorisation(self, ctx: "TeXBotApplicationContext") -> None:
async def check_su_platform_authorisation(self, ctx: TeXBotApplicationContext) -> None:
"""
Definition of the "check_su_platform_authorisation" command.

Expand Down Expand Up @@ -209,7 +207,7 @@ class CheckSUPlatformAuthorisationTaskCog(CheckSUPlatformAuthorisationBaseCog):
"""Cog class defining a repeated task for checking SU platform access cookie."""

@override
def __init__(self, bot: "TeXBot") -> None:
def __init__(self, bot: TeXBot) -> None:
"""Start all task managers when this cog is initialised."""
if settings["AUTO_SU_PLATFORM_ACCESS_COOKIE_CHECKING"]:
_ = self.su_platform_access_cookie_check_task.start()
Expand Down
11 changes: 6 additions & 5 deletions cogs/command_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@

from utils import TeXBotApplicationContext

__all__: "Sequence[str]" = ("CommandErrorCog",)
__all__: Sequence[str] = ("CommandErrorCog",)


logger: "Final[Logger]" = logging.getLogger("TeX-Bot")
logger: Final[Logger] = logging.getLogger("TeX-Bot")


class CommandErrorCog(TeXBotBaseCog):
"""Cog class that defines additional code to execute upon a command error."""

@TeXBotBaseCog.listener()
async def on_application_command_error(
self, ctx: "TeXBotApplicationContext", error: discord.ApplicationCommandError
self, ctx: TeXBotApplicationContext, error: discord.ApplicationCommandError
) -> None:
"""Log any major command errors in the logging channel & stderr."""
error_code: str | None = None
Expand Down Expand Up @@ -75,10 +75,11 @@ async def on_application_command_error(
command_name: str = (
ctx.command.callback.__name__
if (
hasattr(ctx.command, "callback")
ctx.command
and hasattr(ctx.command, "callback")
and not ctx.command.callback.__name__.startswith("_")
)
else ctx.command.qualified_name
else (ctx.command.qualified_name if ctx.command else "unknown")
)
logger.critical(
" ".join(
Expand Down
Loading
Loading