From 3c7f21459d0c3520c5fee45b68b25aa8b6a74500 Mon Sep 17 00:00:00 2001 From: Matty Widdop <18513864+MattyTheHacker@users.noreply.github.com> Date: Wed, 30 Sep 2026 20:27:33 +0100 Subject: [PATCH 1/8] Add automatic creation of final year module threads --- cogs/annual_handover_and_reset.py | 35 +++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/cogs/annual_handover_and_reset.py b/cogs/annual_handover_and_reset.py index 064d0b699..c46811be1 100644 --- a/cogs/annual_handover_and_reset.py +++ b/cogs/annual_handover_and_reset.py @@ -12,6 +12,7 @@ if TYPE_CHECKING: from collections.abc import Collection, Mapping, Sequence + from collections.abc import Set as AbstractSet from logging import Logger from typing import Final @@ -290,6 +291,30 @@ async def increment_year_channels(self, ctx: TeXBotApplicationContext) -> None: f'{ctx.user} used TeX-Bot slash-command: "/increment-year-channels"' ) + MODULE_THREAD_NAMES: Final[AbstractSet[str]] = { + "Advanced Cryptography", + "Advanced Functional Programming (AFP)", + "Advanced Networking", + "Algorithms and Complexity", + "Computer Vision and Imaging", + "Computer-Aided Verification", + "Dependable and Distributed Systems", + "Evolutionary Computation", + "Game Theory", + "High Performance Computing", + "Intelligent Data Analysis", + "Intelligent Interactive Systems", + "Intelligent Robotics", + "Intelligent Software Engineering", + "Machine Learning", + "Mobile and Ubiquitous Computing", + "Natural Language Processing", + "Neural Computation", + "PLPDI", + "Security of Real-World Systems", + "Teaching Computer Science in Schools", + } + async with ctx.typing(): initial_message: discord.Interaction | discord.WebhookMessage = await ctx.respond( content=":hourglass: Incrementing year channels... :hourglass:" @@ -340,6 +365,16 @@ async def increment_year_channels(self, ctx: TeXBotApplicationContext) -> None: topic="Channel for final-years to chat and ask questions.", reason=INCREMENT_YEAR_CHANNELS_AUDIT_MESSAGE, ) + for thread in MODULE_THREAD_NAMES: + thread_channel: discord.TextChannel | None = discord.utils.get( + main_guild.text_channels, name=thread + ) + if not thread_channel: + await second_years_channel.create_thread( + name=thread, + type=discord.ChannelType.public_thread, + reason=INCREMENT_YEAR_CHANNELS_AUDIT_MESSAGE, + ) first_year_channel: discord.TextChannel | None = discord.utils.get( main_guild.text_channels, name="first-years" From d854e119999903da175ea4469706c024ae67da0c Mon Sep 17 00:00:00 2001 From: Matty Widdop <18513864+MattyTheHacker@users.noreply.github.com> Date: Fri, 20 Nov 2026 16:35:37 +0000 Subject: [PATCH 2/8] Fixes and improvements --- cogs/annual_handover_and_reset.py | 81 ++++++++++++++++++------------- 1 file changed, 47 insertions(+), 34 deletions(-) diff --git a/cogs/annual_handover_and_reset.py b/cogs/annual_handover_and_reset.py index 499232043..3d2ce7ea6 100644 --- a/cogs/annual_handover_and_reset.py +++ b/cogs/annual_handover_and_reset.py @@ -9,7 +9,6 @@ import logging lazy import datetime 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 Final @@ -265,6 +264,30 @@ async def annual_roles_reset(self, ctx: TeXBotApplicationContext) -> None: class AnnualYearChannelsIncrementCommandCog(TeXBotBaseCog): """Cog class that defines the "/increment-year-channels" command.""" + MODULE_THREAD_NAMES: Final[Sequence[str]] = ( + "Advanced Cryptography", + "Advanced Functional Programming", + "Advanced Networking", + "Algorithms and Complexity", + "Computer Vision and Imaging", + "Computer-Aided Verification", + "Dependable and Distributed Systems", + "Evolutionary Computation", + "Game Theory", + "High Performance Computing", + "Intelligent Data Analysis", + "Intelligent Interactive Systems", + "Intelligent Robotics", + "Intelligent Software Engineering", + "Machine Learning", + "Mobile and Ubiquitous Computing", + "Natural Language Processing", + "Neural Computation", + "Programming Language Principles, Design, and Implementation", + "Security of Real-World Systems", + "Teaching Computer Science in Schools", + ) + @discord.slash_command( name="increment-year-channels", description="Increments the year channels, archiving and creating channels as needed.", @@ -278,6 +301,7 @@ async def increment_year_channels(self, ctx: TeXBotApplicationContext) -> None: The "increment_year_channels" command: - Archives the current "final-years" channel - Renames the current "second-years" channel to "final-years" + - Creates a thread for each final-year module in the new "final-years" channel - Renames the current "first-years" channel to "second-years" - Creates a new "first-years" channel """ @@ -288,30 +312,6 @@ async def increment_year_channels(self, ctx: TeXBotApplicationContext) -> None: f'{ctx.user} used TeX-Bot slash-command: "/increment-year-channels"' ) - MODULE_THREAD_NAMES: Final[AbstractSet[str]] = { - "Advanced Cryptography", - "Advanced Functional Programming (AFP)", - "Advanced Networking", - "Algorithms and Complexity", - "Computer Vision and Imaging", - "Computer-Aided Verification", - "Dependable and Distributed Systems", - "Evolutionary Computation", - "Game Theory", - "High Performance Computing", - "Intelligent Data Analysis", - "Intelligent Interactive Systems", - "Intelligent Robotics", - "Intelligent Software Engineering", - "Machine Learning", - "Mobile and Ubiquitous Computing", - "Natural Language Processing", - "Neural Computation", - "PLPDI", - "Security of Real-World Systems", - "Teaching Computer Science in Schools", - } - async with ctx.typing(): initial_message: discord.Interaction | discord.WebhookMessage = await ctx.respond( content=":hourglass: Incrementing year channels... :hourglass:" @@ -362,16 +362,29 @@ async def increment_year_channels(self, ctx: TeXBotApplicationContext) -> None: topic="Channel for final-years to chat and ask questions.", reason=INCREMENT_YEAR_CHANNELS_AUDIT_MESSAGE, ) - for thread in MODULE_THREAD_NAMES: - thread_channel: discord.TextChannel | None = discord.utils.get( - main_guild.text_channels, name=thread + + await initial_message.edit( + content=":hourglass: Creating threads... :hourglass:" + ) + + for module_thread_name in self.MODULE_THREAD_NAMES: + existing_thread: discord.Thread | None = discord.utils.get( + second_years_channel.threads, name=module_thread_name ) - if not thread_channel: - await second_years_channel.create_thread( - name=thread, - type=discord.ChannelType.public_thread, - reason=INCREMENT_YEAR_CHANNELS_AUDIT_MESSAGE, - ) + if not existing_thread: + try: + await second_years_channel.create_thread( + name=module_thread_name, + type=discord.ChannelType.public_thread, + auto_archive_duration=10080, + reason=INCREMENT_YEAR_CHANNELS_AUDIT_MESSAGE, + ) + except discord.HTTPException as e: + logger.warning( + 'Failed to create "%s" thread in "final-years" channel: %s', + module_thread_name, + e, + ) first_year_channel: discord.TextChannel | None = discord.utils.get( main_guild.text_channels, name="first-years" From 464d43875da087c86e0a001fbb6940a50f7c219e Mon Sep 17 00:00:00 2001 From: Matty Widdop <18513864+MattyTheHacker@users.noreply.github.com> Date: Fri, 20 Nov 2026 16:54:29 +0000 Subject: [PATCH 3/8] Add first and second year threads --- cogs/annual_handover_and_reset.py | 98 ++++++++++++++++++++++++------- 1 file changed, 78 insertions(+), 20 deletions(-) diff --git a/cogs/annual_handover_and_reset.py b/cogs/annual_handover_and_reset.py index 3d2ce7ea6..b989173f2 100644 --- a/cogs/annual_handover_and_reset.py +++ b/cogs/annual_handover_and_reset.py @@ -264,7 +264,25 @@ async def annual_roles_reset(self, ctx: TeXBotApplicationContext) -> None: class AnnualYearChannelsIncrementCommandCog(TeXBotBaseCog): """Cog class that defines the "/increment-year-channels" command.""" - MODULE_THREAD_NAMES: Final[Sequence[str]] = ( + FIRST_YEAR_MODULE_THREAD_NAMES: Final[Sequence[str]] = ( + "Artificial Intelligence 1", + "Computer Systems and Professional Practice", + "Data Structures and Algorithms", + "Mathematical and Logical Foundations of Computer Science", + "Object Oriented Programming", + "Theories of Computation", + ) + + SECOND_YEAR_MODULE_THREAD_NAMES: Final[Sequence[str]] = ( + "Artificial Intelligence 2", + "Databases and Web Programming", + "Functional Programming", + "Operating Systems and Systems Programming", + "Security and Networks", + "Software Engineering for Global Challenges", + ) + + FINAL_YEAR_MODULE_THREAD_NAMES: Final[Sequence[str]] = ( "Advanced Cryptography", "Advanced Functional Programming", "Advanced Networking", @@ -288,6 +306,34 @@ class AnnualYearChannelsIncrementCommandCog(TeXBotBaseCog): "Teaching Computer Science in Schools", ) + @staticmethod + async def _create_module_threads( + channel: discord.TextChannel, + channel_name: str, + module_thread_names: Sequence[str], + reason: str, + ) -> None: + """Create a public thread in the given channel for each module without one.""" + for module_thread_name in module_thread_names: + existing_thread: discord.Thread | None = discord.utils.get( + channel.threads, name=module_thread_name + ) + if not existing_thread: + try: + await channel.create_thread( + name=module_thread_name, + type=discord.ChannelType.public_thread, + auto_archive_duration=10080, + reason=reason, + ) + except discord.HTTPException as e: + logger.warning( + 'Failed to create "%s" thread in "%s" channel: %s', + module_thread_name, + channel_name, + e, + ) + @discord.slash_command( name="increment-year-channels", description="Increments the year channels, archiving and creating channels as needed.", @@ -303,7 +349,9 @@ async def increment_year_channels(self, ctx: TeXBotApplicationContext) -> None: - Renames the current "second-years" channel to "final-years" - Creates a thread for each final-year module in the new "final-years" channel - Renames the current "first-years" channel to "second-years" + - Creates a thread for each second-year module in the new "second-years" channel - Creates a new "first-years" channel + - Creates a thread for each first-year module in the new "first-years" channel """ # NOTE: Shortcut accessors are placed at the top of the function so that the exceptions they raise are displayed before any further errors may be sent main_guild: discord.Guild = self.bot.main_guild @@ -364,27 +412,15 @@ async def increment_year_channels(self, ctx: TeXBotApplicationContext) -> None: ) await initial_message.edit( - content=":hourglass: Creating threads... :hourglass:" + content=':hourglass: Creating "final-years" threads... :hourglass:' ) - for module_thread_name in self.MODULE_THREAD_NAMES: - existing_thread: discord.Thread | None = discord.utils.get( - second_years_channel.threads, name=module_thread_name - ) - if not existing_thread: - try: - await second_years_channel.create_thread( - name=module_thread_name, - type=discord.ChannelType.public_thread, - auto_archive_duration=10080, - reason=INCREMENT_YEAR_CHANNELS_AUDIT_MESSAGE, - ) - except discord.HTTPException as e: - logger.warning( - 'Failed to create "%s" thread in "final-years" channel: %s', - module_thread_name, - e, - ) + await self._create_module_threads( + channel=second_years_channel, + channel_name="final-years", + module_thread_names=self.FINAL_YEAR_MODULE_THREAD_NAMES, + reason=INCREMENT_YEAR_CHANNELS_AUDIT_MESSAGE, + ) first_year_channel: discord.TextChannel | None = discord.utils.get( main_guild.text_channels, name="first-years" @@ -397,6 +433,17 @@ async def increment_year_channels(self, ctx: TeXBotApplicationContext) -> None: reason=INCREMENT_YEAR_CHANNELS_AUDIT_MESSAGE, ) + await initial_message.edit( + content=':hourglass: Creating "second-years" threads... :hourglass:' + ) + + await self._create_module_threads( + channel=first_year_channel, + channel_name="second-years", + module_thread_names=self.SECOND_YEAR_MODULE_THREAD_NAMES, + reason=INCREMENT_YEAR_CHANNELS_AUDIT_MESSAGE, + ) + year_channels_category: discord.CategoryChannel | None = discord.utils.get( main_guild.categories, name="Year Chats" ) @@ -431,6 +478,17 @@ async def increment_year_channels(self, ctx: TeXBotApplicationContext) -> None: reason=INCREMENT_YEAR_CHANNELS_AUDIT_MESSAGE, ) + await initial_message.edit( + content=':hourglass: Creating "first-years" threads... :hourglass:' + ) + + await self._create_module_threads( + channel=new_first_years_channel, + channel_name="first-years", + module_thread_names=self.FIRST_YEAR_MODULE_THREAD_NAMES, + reason=INCREMENT_YEAR_CHANNELS_AUDIT_MESSAGE, + ) + await initial_message.edit( content=( ":white_check_mark: Year channels were successfully incremented" From 630bc6033f70bf05801422b9b6e32080f3bc5081 Mon Sep 17 00:00:00 2001 From: Matty Widdop <18513864+MattyTheHacker@users.noreply.github.com> Date: Tue, 24 Nov 2026 20:02:39 +0000 Subject: [PATCH 4/8] Apply batched suggestions from code review Co-authored-by: Matt Norton Signed-off-by: Matty Widdop <18513864+MattyTheHacker@users.noreply.github.com> --- cogs/annual_handover_and_reset.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cogs/annual_handover_and_reset.py b/cogs/annual_handover_and_reset.py index b989173f2..056d28046 100644 --- a/cogs/annual_handover_and_reset.py +++ b/cogs/annual_handover_and_reset.py @@ -310,10 +310,11 @@ class AnnualYearChannelsIncrementCommandCog(TeXBotBaseCog): async def _create_module_threads( channel: discord.TextChannel, channel_name: str, - module_thread_names: Sequence[str], + module_thread_names: Set[str], reason: str, ) -> None: """Create a public thread in the given channel for each module without one.""" + module_thread_name: str for module_thread_name in module_thread_names: existing_thread: discord.Thread | None = discord.utils.get( channel.threads, name=module_thread_name From 0034d8b47e5e219ef074ad57044087fc33356b81 Mon Sep 17 00:00:00 2001 From: Matty Widdop <18513864+MattyTheHacker@users.noreply.github.com> Date: Tue, 24 Nov 2026 20:18:19 +0000 Subject: [PATCH 5/8] Review fixes --- cogs/annual_handover_and_reset.py | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/cogs/annual_handover_and_reset.py b/cogs/annual_handover_and_reset.py index 056d28046..4ab42051d 100644 --- a/cogs/annual_handover_and_reset.py +++ b/cogs/annual_handover_and_reset.py @@ -9,6 +9,7 @@ import logging lazy import datetime 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 Final @@ -264,25 +265,25 @@ async def annual_roles_reset(self, ctx: TeXBotApplicationContext) -> None: class AnnualYearChannelsIncrementCommandCog(TeXBotBaseCog): """Cog class that defines the "/increment-year-channels" command.""" - FIRST_YEAR_MODULE_THREAD_NAMES: Final[Sequence[str]] = ( + FIRST_YEAR_MODULE_THREAD_NAMES: Final[AbstractSet[str]] = { # TODO: Move to config later # noqa: FIX002 "Artificial Intelligence 1", "Computer Systems and Professional Practice", "Data Structures and Algorithms", "Mathematical and Logical Foundations of Computer Science", "Object Oriented Programming", "Theories of Computation", - ) + } - SECOND_YEAR_MODULE_THREAD_NAMES: Final[Sequence[str]] = ( + SECOND_YEAR_MODULE_THREAD_NAMES: Final[AbstractSet[str]] = { # TODO: Move to config later # noqa: FIX002 "Artificial Intelligence 2", "Databases and Web Programming", "Functional Programming", "Operating Systems and Systems Programming", "Security and Networks", "Software Engineering for Global Challenges", - ) + } - FINAL_YEAR_MODULE_THREAD_NAMES: Final[Sequence[str]] = ( + FINAL_YEAR_MODULE_THREAD_NAMES: Final[AbstractSet[str]] = { # TODO: Move to config later # noqa: FIX002 "Advanced Cryptography", "Advanced Functional Programming", "Advanced Networking", @@ -304,13 +305,12 @@ class AnnualYearChannelsIncrementCommandCog(TeXBotBaseCog): "Programming Language Principles, Design, and Implementation", "Security of Real-World Systems", "Teaching Computer Science in Schools", - ) + } @staticmethod async def _create_module_threads( channel: discord.TextChannel, - channel_name: str, - module_thread_names: Set[str], + module_thread_names: AbstractSet[str], reason: str, ) -> None: """Create a public thread in the given channel for each module without one.""" @@ -327,12 +327,12 @@ async def _create_module_threads( auto_archive_duration=10080, reason=reason, ) - except discord.HTTPException as e: + except discord.HTTPException as http_exception_error: logger.warning( 'Failed to create "%s" thread in "%s" channel: %s', module_thread_name, - channel_name, - e, + channel.name, + http_exception_error, ) @discord.slash_command( @@ -418,7 +418,6 @@ async def increment_year_channels(self, ctx: TeXBotApplicationContext) -> None: await self._create_module_threads( channel=second_years_channel, - channel_name="final-years", module_thread_names=self.FINAL_YEAR_MODULE_THREAD_NAMES, reason=INCREMENT_YEAR_CHANNELS_AUDIT_MESSAGE, ) @@ -440,7 +439,6 @@ async def increment_year_channels(self, ctx: TeXBotApplicationContext) -> None: await self._create_module_threads( channel=first_year_channel, - channel_name="second-years", module_thread_names=self.SECOND_YEAR_MODULE_THREAD_NAMES, reason=INCREMENT_YEAR_CHANNELS_AUDIT_MESSAGE, ) @@ -485,7 +483,6 @@ async def increment_year_channels(self, ctx: TeXBotApplicationContext) -> None: await self._create_module_threads( channel=new_first_years_channel, - channel_name="first-years", module_thread_names=self.FIRST_YEAR_MODULE_THREAD_NAMES, reason=INCREMENT_YEAR_CHANNELS_AUDIT_MESSAGE, ) From ac8cd582e494fa1850499ef14f0651a773fe0b92 Mon Sep 17 00:00:00 2001 From: Matty Widdop <18513864+MattyTheHacker@users.noreply.github.com> Date: Thu, 26 Nov 2026 17:07:38 +0000 Subject: [PATCH 6/8] Implement message and pin for threads --- cogs/annual_handover_and_reset.py | 139 ++++++++++++++++++++---------- 1 file changed, 95 insertions(+), 44 deletions(-) diff --git a/cogs/annual_handover_and_reset.py b/cogs/annual_handover_and_reset.py index 4ab42051d..bce73606e 100644 --- a/cogs/annual_handover_and_reset.py +++ b/cogs/annual_handover_and_reset.py @@ -265,47 +265,56 @@ async def annual_roles_reset(self, ctx: TeXBotApplicationContext) -> None: class AnnualYearChannelsIncrementCommandCog(TeXBotBaseCog): """Cog class that defines the "/increment-year-channels" command.""" - FIRST_YEAR_MODULE_THREAD_NAMES: Final[AbstractSet[str]] = { # TODO: Move to config later # noqa: FIX002 - "Artificial Intelligence 1", - "Computer Systems and Professional Practice", - "Data Structures and Algorithms", - "Mathematical and Logical Foundations of Computer Science", - "Object Oriented Programming", - "Theories of Computation", - } - - SECOND_YEAR_MODULE_THREAD_NAMES: Final[AbstractSet[str]] = { # TODO: Move to config later # noqa: FIX002 - "Artificial Intelligence 2", - "Databases and Web Programming", - "Functional Programming", - "Operating Systems and Systems Programming", - "Security and Networks", - "Software Engineering for Global Challenges", - } - - FINAL_YEAR_MODULE_THREAD_NAMES: Final[AbstractSet[str]] = { # TODO: Move to config later # noqa: FIX002 - "Advanced Cryptography", - "Advanced Functional Programming", - "Advanced Networking", - "Algorithms and Complexity", - "Computer Vision and Imaging", - "Computer-Aided Verification", - "Dependable and Distributed Systems", - "Evolutionary Computation", - "Game Theory", - "High Performance Computing", - "Intelligent Data Analysis", - "Intelligent Interactive Systems", - "Intelligent Robotics", - "Intelligent Software Engineering", - "Machine Learning", - "Mobile and Ubiquitous Computing", - "Natural Language Processing", - "Neural Computation", - "Programming Language Principles, Design, and Implementation", - "Security of Real-World Systems", - "Teaching Computer Science in Schools", - } + # TODO: Move to config later # noqa: FIX002 + FIRST_YEAR_MODULE_THREAD_NAMES: Final[AbstractSet[str]] = frozenset( + { + "Artificial Intelligence 1", + "Computer Systems and Professional Practice", + "Data Structures and Algorithms", + "Mathematical and Logical Foundations of Computer Science", + "Object Oriented Programming", + "Theories of Computation", + } + ) + + # TODO: Move to config later # noqa: FIX002 + SECOND_YEAR_MODULE_THREAD_NAMES: Final[AbstractSet[str]] = frozenset( + { + "Artificial Intelligence 2", + "Databases and Web Programming", + "Functional Programming", + "Operating Systems and Systems Programming", + "Security and Networks", + "Software Engineering for Global Challenges", + } + ) + + # TODO: Move to config later # noqa: FIX002 + FINAL_YEAR_MODULE_THREAD_NAMES: Final[AbstractSet[str]] = frozenset( + { + "Advanced Cryptography", + "Advanced Functional Programming", + "Advanced Networking", + "Algorithms and Complexity", + "Computer Vision and Imaging", + "Computer-Aided Verification", + "Dependable and Distributed Systems", + "Evolutionary Computation", + "Game Theory", + "High Performance Computing", + "Intelligent Data Analysis", + "Intelligent Interactive Systems", + "Intelligent Robotics", + "Intelligent Software Engineering", + "Machine Learning", + "Mobile and Ubiquitous Computing", + "Natural Language Processing", + "Neural Computation", + "Programming Language Principles, Design, and Implementation", + "Security of Real-World Systems", + "Teaching Computer Science in Schools", + } + ) @staticmethod async def _create_module_threads( @@ -313,15 +322,22 @@ async def _create_module_threads( module_thread_names: AbstractSet[str], reason: str, ) -> None: - """Create a public thread in the given channel for each module without one.""" + """ + Create a public thread in the given channel for each module without one. + + A message linking to every newly created thread is then sent & pinned + in the given channel. + """ + created_module_threads: list[discord.Thread] = [] + module_thread_name: str - for module_thread_name in module_thread_names: + for module_thread_name in sorted(module_thread_names): existing_thread: discord.Thread | None = discord.utils.get( channel.threads, name=module_thread_name ) if not existing_thread: try: - await channel.create_thread( + created_module_thread: discord.Thread = await channel.create_thread( name=module_thread_name, type=discord.ChannelType.public_thread, auto_archive_duration=10080, @@ -334,6 +350,40 @@ async def _create_module_threads( channel.name, http_exception_error, ) + else: + created_module_threads.append(created_module_thread) + + if not created_module_threads: + return + + try: + module_thread_links_message: discord.Message = await channel.send( + content=( + "## Module Threads" + f"\n{ + '\n'.join( + f'- {module_thread.mention}' + for module_thread in created_module_threads + ) + }" + ) + ) + except discord.HTTPException as http_exception_error: + logger.warning( + 'Failed to send module thread links message in "%s" channel: %s', + channel.name, + http_exception_error, + ) + return + + try: + await module_thread_links_message.pin(reason=reason) + except discord.HTTPException as http_exception_error: + logger.warning( + 'Failed to pin module thread links message in "%s" channel: %s', + channel.name, + http_exception_error, + ) @discord.slash_command( name="increment-year-channels", @@ -353,6 +403,7 @@ async def increment_year_channels(self, ctx: TeXBotApplicationContext) -> None: - Creates a thread for each second-year module in the new "second-years" channel - Creates a new "first-years" channel - Creates a thread for each first-year module in the new "first-years" channel + - Sends & pins a message in each channel linking to its newly created threads """ # NOTE: Shortcut accessors are placed at the top of the function so that the exceptions they raise are displayed before any further errors may be sent main_guild: discord.Guild = self.bot.main_guild From 48a51c05c5369678c73786a02bb340f52bc0ed1e Mon Sep 17 00:00:00 2001 From: Matty Widdop <18513864+MattyTheHacker@users.noreply.github.com> Date: Thu, 26 Nov 2026 18:10:24 +0000 Subject: [PATCH 7/8] Apply batched suggestions from code review Co-authored-by: Matt Norton Signed-off-by: Matty Widdop <18513864+MattyTheHacker@users.noreply.github.com> --- cogs/annual_handover_and_reset.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/cogs/annual_handover_and_reset.py b/cogs/annual_handover_and_reset.py index bce73606e..a50368675 100644 --- a/cogs/annual_handover_and_reset.py +++ b/cogs/annual_handover_and_reset.py @@ -276,8 +276,6 @@ class AnnualYearChannelsIncrementCommandCog(TeXBotBaseCog): "Theories of Computation", } ) - - # TODO: Move to config later # noqa: FIX002 SECOND_YEAR_MODULE_THREAD_NAMES: Final[AbstractSet[str]] = frozenset( { "Artificial Intelligence 2", @@ -288,8 +286,6 @@ class AnnualYearChannelsIncrementCommandCog(TeXBotBaseCog): "Software Engineering for Global Challenges", } ) - - # TODO: Move to config later # noqa: FIX002 FINAL_YEAR_MODULE_THREAD_NAMES: Final[AbstractSet[str]] = frozenset( { "Advanced Cryptography", @@ -466,7 +462,6 @@ async def increment_year_channels(self, ctx: TeXBotApplicationContext) -> None: await initial_message.edit( content=':hourglass: Creating "final-years" threads... :hourglass:' ) - await self._create_module_threads( channel=second_years_channel, module_thread_names=self.FINAL_YEAR_MODULE_THREAD_NAMES, @@ -487,7 +482,6 @@ async def increment_year_channels(self, ctx: TeXBotApplicationContext) -> None: await initial_message.edit( content=':hourglass: Creating "second-years" threads... :hourglass:' ) - await self._create_module_threads( channel=first_year_channel, module_thread_names=self.SECOND_YEAR_MODULE_THREAD_NAMES, @@ -531,7 +525,6 @@ async def increment_year_channels(self, ctx: TeXBotApplicationContext) -> None: await initial_message.edit( content=':hourglass: Creating "first-years" threads... :hourglass:' ) - await self._create_module_threads( channel=new_first_years_channel, module_thread_names=self.FIRST_YEAR_MODULE_THREAD_NAMES, From b1b8ea20d3e5a4f3470f601e5feedc3ce4312e28 Mon Sep 17 00:00:00 2001 From: Matty Widdop <18513864+MattyTheHacker@users.noreply.github.com> Date: Thu, 26 Nov 2026 18:11:37 +0000 Subject: [PATCH 8/8] switch to use guard --- cogs/annual_handover_and_reset.py | 37 +++++++++++++++++-------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/cogs/annual_handover_and_reset.py b/cogs/annual_handover_and_reset.py index a50368675..5998cb5ca 100644 --- a/cogs/annual_handover_and_reset.py +++ b/cogs/annual_handover_and_reset.py @@ -331,23 +331,26 @@ async def _create_module_threads( existing_thread: discord.Thread | None = discord.utils.get( channel.threads, name=module_thread_name ) - if not existing_thread: - try: - created_module_thread: discord.Thread = await channel.create_thread( - name=module_thread_name, - type=discord.ChannelType.public_thread, - auto_archive_duration=10080, - reason=reason, - ) - except discord.HTTPException as http_exception_error: - logger.warning( - 'Failed to create "%s" thread in "%s" channel: %s', - module_thread_name, - channel.name, - http_exception_error, - ) - else: - created_module_threads.append(created_module_thread) + + if existing_thread is not None: + continue + + try: + created_module_thread: discord.Thread = await channel.create_thread( + name=module_thread_name, + type=discord.ChannelType.public_thread, + auto_archive_duration=10080, + reason=reason, + ) + except discord.HTTPException as http_exception_error: + logger.warning( + 'Failed to create "%s" thread in "%s" channel: %s', + module_thread_name, + channel.name, + http_exception_error, + ) + else: + created_module_threads.append(created_module_thread) if not created_module_threads: return