Skip to content

Commit

Permalink
Add codejam suppport command group to toggle Code Jam Support role fo…
Browse files Browse the repository at this point in the history
…r admins and events team members (#128)
  • Loading branch information
AbooMinister25 authored Jun 27, 2024
1 parent b977cf4 commit 1f9a403
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
1 change: 1 addition & 0 deletions bot/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 37 additions & 1 deletion bot/exts/code_jams/_cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 1f9a403

Please sign in to comment.