From 1f9a40370d6e996714a24ac915e0be6f1a353acb Mon Sep 17 00:00:00 2001 From: Rayyan Cyclegar <67297584+AbooMinister25@users.noreply.github.com> Date: Thu, 27 Jun 2024 18:20:28 -0400 Subject: [PATCH] Add codejam suppport command group to toggle Code Jam Support role for admins and events team members (#128) --- bot/constants.py | 1 + bot/exts/code_jams/_cog.py | 38 +++++++++++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/bot/constants.py b/bot/constants.py index 1826f5f..f88f67b 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -181,6 +181,7 @@ class _Roles(EnvConfig, env_prefix="ROLE_"): event_runner: int = 940911658799333408 summer_aoc: int = 988801794668908655 code_jam_participants: int = 991678713093705781 + code_jam_support: int = 1254657197535920141 helpers: int = 267630620367257601 aoc_completionist: int = 1191547731873894440 bots: int = 277546923144249364 diff --git a/bot/exts/code_jams/_cog.py b/bot/exts/code_jams/_cog.py index 52b40a3..d9644ad 100644 --- a/bot/exts/code_jams/_cog.py +++ b/bot/exts/code_jams/_cog.py @@ -11,11 +11,12 @@ from pydis_core.utils.paste_service import PasteFile, PasteTooLongError, PasteUploadError, send_to_paste_service from bot.bot import SirRobin -from bot.constants import Roles +from bot.constants import Emojis, Roles from bot.exts.code_jams import _creation_utils from bot.exts.code_jams._flows import add_flow, creation_flow, deletion_flow, move_flow, pin_flow, remove_flow from bot.exts.code_jams._views import JamConfirmation, JamInfoView, JamTeamInfoConfirmation from bot.utils.checks import in_code_jam_category +from bot.utils.decorators import with_role log = get_logger(__name__) PIN_ALLOWED_ROLES: tuple[int, ...] = (Roles.admins, Roles.code_jam_event_team) @@ -222,6 +223,41 @@ async def unpin(self, ctx: commands.Context, message: discord.Message | None = N """Lets Code Jam Participants to unpin messages in their team channels.""" await pin_flow(ctx, PIN_ALLOWED_ROLES, self.bot.code_jam_mgmt_api, message, True) + @codejam.group() + @with_role(Roles.admins, Roles.code_jam_event_team, fail_silently=True) + async def support(self, ctx: commands.Context) -> None: + """Apply or remove the Code Jam Support role.""" + if ctx.invoked_subcommand is None: + await ctx.send_help(ctx.command) + + @support.command() + @with_role(Roles.admins, Roles.code_jam_event_team, fail_silently=True) + async def off(self, ctx: commands.Context) -> None: + """Remove the Code Jam Support role.""" + user = ctx.author + cj_support_role = ctx.guild.get_role(Roles.code_jam_support) + + if cj_support_role not in user.roles: + await ctx.send(":question: You don't have the role.") + return + + await user.remove_roles(cj_support_role) + await ctx.send(f"{Emojis.check_mark} Code Jam Support role has been removed.") + + @support.command() + @with_role(Roles.admins, Roles.code_jam_event_team, fail_silently=True) + async def on(self, ctx: commands.Context) -> None: + """Add the Code Jam Support role.""" + user = ctx.author + cj_support_role = ctx.guild.get_role(Roles.code_jam_support) + + if cj_support_role in user.roles: + await ctx.send(":question: You already have the role.") + return + + await user.add_roles(cj_support_role) + await ctx.send(f"{Emojis.check_mark} Code Jam Support role has been applied.") + @codejam.command("ping") @commands.has_any_role(Roles.admins, Roles.events_lead, Roles.code_jam_event_team, Roles.code_jam_participants) @in_code_jam_category(_creation_utils.CATEGORY_NAME)