From 8a278fc07eb1ab5b2f30bcef57938975394c772a Mon Sep 17 00:00:00 2001 From: andrewj-brown <92134285+andrewj-brown@users.noreply.github.com> Date: Wed, 19 Jul 2023 08:19:15 +1000 Subject: [PATCH 1/4] Add cog groups to repo --- uqcsbot/manage_cogs.py | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/uqcsbot/manage_cogs.py b/uqcsbot/manage_cogs.py index d702c7b..d066a5b 100644 --- a/uqcsbot/manage_cogs.py +++ b/uqcsbot/manage_cogs.py @@ -1,9 +1,14 @@ -from typing import Literal +from typing import Literal, List, Dict import discord from discord import app_commands from discord.ext import commands +COG_GROUPS: Dict[str, List[str]] = { + "cron": ["working_on", "holidays"], + "db": ["starboard", "remindme", "advent", "minecraft"], +} + class ManageCogs(commands.Cog): """ @@ -21,7 +26,7 @@ def __init__(self, bot: commands.Bot): async def manage_cogs( self, interaction: discord.Interaction, - action: Literal["load", "unload", "reload"], + action: Literal["load", "unload", "reload", "unload-all"], cog: str, ): """ @@ -36,6 +41,24 @@ async def manage_cogs( await self.bot.unload_extension(f"uqcsbot.{cog}") case "reload": await self.bot.reload_extension(f"uqcsbot.{cog}") + case "load-all": + if (cogs := COG_GROUPS.get(cog)) is not None: + for x in cogs: + await self.bot.load_extension(f"uqcsbot.{x}") + else: + raise RuntimeError(f"Unknown cog group {cog}") + case "unload-all": + if (cogs := COG_GROUPS.get(cog)) is not None: + for x in cogs: + await self.bot.unload_extension(f"uqcsbot.{x}") + else: + raise RuntimeError(f"Unknown cog group {cog}") + case "load-all": + if (cogs := COG_GROUPS.get(cog)) is not None: + for x in cogs: + await self.bot.reload_extension(f"uqcsbot.{x}") + else: + raise RuntimeError(f"Unknown cog group {cog}") except Exception as error: # Many errors can be caught during loading/unloading/reloading the bot, so it would be painful to separate by exception type await interaction.response.send_message( From eba9285196d3b3df919572457d0358ee4ec5d42c Mon Sep 17 00:00:00 2001 From: andrewj-brown <92134285+andrewj-brown@users.noreply.github.com> Date: Wed, 19 Jul 2023 08:34:29 +1000 Subject: [PATCH 2/4] add actions to literal list --- uqcsbot/manage_cogs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uqcsbot/manage_cogs.py b/uqcsbot/manage_cogs.py index d066a5b..907fcf9 100644 --- a/uqcsbot/manage_cogs.py +++ b/uqcsbot/manage_cogs.py @@ -26,7 +26,7 @@ def __init__(self, bot: commands.Bot): async def manage_cogs( self, interaction: discord.Interaction, - action: Literal["load", "unload", "reload", "unload-all"], + action: Literal["load", "unload", "reload", "load-all", "unload-all", "reload-all"], cog: str, ): """ From b5445b2d40d8078178bf9d5a68b4e70ea73ff48d Mon Sep 17 00:00:00 2001 From: andrewj-brown <92134285+andrewj-brown@users.noreply.github.com> Date: Wed, 19 Jul 2023 08:36:46 +1000 Subject: [PATCH 3/4] fix black --- uqcsbot/manage_cogs.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/uqcsbot/manage_cogs.py b/uqcsbot/manage_cogs.py index 907fcf9..b3fcedd 100644 --- a/uqcsbot/manage_cogs.py +++ b/uqcsbot/manage_cogs.py @@ -26,7 +26,9 @@ def __init__(self, bot: commands.Bot): async def manage_cogs( self, interaction: discord.Interaction, - action: Literal["load", "unload", "reload", "load-all", "unload-all", "reload-all"], + action: Literal[ + "load", "unload", "reload", "load-all", "unload-all", "reload-all" + ], cog: str, ): """ From d8d64e9bcaad35cd4fe877b995fb3bf0c794ae36 Mon Sep 17 00:00:00 2001 From: andrewj-brown <92134285+andrewj-brown@users.noreply.github.com> Date: Wed, 19 Jul 2023 09:13:32 +1000 Subject: [PATCH 4/4] yeah nah righto --- uqcsbot/manage_cogs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uqcsbot/manage_cogs.py b/uqcsbot/manage_cogs.py index b3fcedd..7b0c238 100644 --- a/uqcsbot/manage_cogs.py +++ b/uqcsbot/manage_cogs.py @@ -55,7 +55,7 @@ async def manage_cogs( await self.bot.unload_extension(f"uqcsbot.{x}") else: raise RuntimeError(f"Unknown cog group {cog}") - case "load-all": + case "reload-all": if (cogs := COG_GROUPS.get(cog)) is not None: for x in cogs: await self.bot.reload_extension(f"uqcsbot.{x}")