Skip to content
Merged
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 bot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ async def setup_hook(self) -> None:
site_api_token=constants.Client.code_jam_token
)
await super().setup_hook()
create_task(self.load_extensions(exts))
await self.load_extensions(exts)
create_task(self.check_channels())
create_task(self.send_log(constants.Client.name, "Connected!"))
self.add_view(JamTeamInfoView(self))
Expand Down
37 changes: 22 additions & 15 deletions bot/exts/advent_of_code/_cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import arrow
import discord
from async_rediscache import RedisCache
from discord import app_commands
from discord.ext import commands, tasks

from bot.bot import SirRobin
Expand Down Expand Up @@ -42,6 +43,12 @@ class AdventOfCode(commands.Cog):
# RedisCache[member_id: None]
completionist_block_list = RedisCache()

aoc_slash_group = app_commands.Group(
name="aoc",
description="All of the Advent of Code commands.",
guild_ids=[Client.guild],
)

def __init__(self, bot: SirRobin):
self.bot = bot

Expand Down Expand Up @@ -183,22 +190,25 @@ async def about_aoc(self, ctx: commands.Context) -> None:
"""Respond with an explanation of all things Advent of Code."""
await ctx.send(embed=self.cached_about_aoc)

@commands.guild_only()
@adventofcode_group.command(name="join", aliases=("j",), brief="Learn how to join the leaderboard (via DM)")
@aoc_slash_group.command(name="join", description="Get the join code for our community Advent of Code leaderboard")
@whitelist_override(channels=AOC_WHITELIST)
async def join_leaderboard(self, ctx: commands.Context) -> None:
"""DM the user the information for joining the Python Discord leaderboard."""
@app_commands.guild_only()
async def join_leaderboard(self, interaction: discord.Interaction) -> None:
"""Send the user an ephemeral message with the information for joining the Python Discord leaderboard."""
current_date = datetime.now()
allowed_months = (Month.NOVEMBER.value, Month.DECEMBER.value)
if not (
current_date.month in allowed_months and current_date.year == AocConfig.year
or current_date.month == Month.JANUARY.value and current_date.year == AocConfig.year + 1
):
# Only allow joining the leaderboard in the run up to AOC and the January following.
await ctx.send(f"The Python Discord leaderboard for {current_date.year} is not yet available!")
await interaction.response.send_message(
f"The Python Discord leaderboard for {current_date.year} is not yet available!",
ephemeral=True,
)
return

author = ctx.author
author = interaction.user
log.info(f"{author.name} ({author.id}) has requested a PyDis AoC leaderboard code")

if AocConfig.staff_leaderboard_id and any(r.id == Roles.helpers for r in author.roles):
Expand All @@ -207,7 +217,10 @@ async def join_leaderboard(self, ctx: commands.Context) -> None:
try:
join_code = await _helpers.get_public_join_code(author)
except _helpers.FetchingLeaderboardFailedError:
await ctx.send(":x: Failed to get join code! Notified maintainers.")
await interaction.response.send_message(
":x: Failed to get join code! Notified maintainers.",
ephemeral=True,
)
return

if not join_code:
Expand All @@ -217,7 +230,7 @@ async def join_leaderboard(self, ctx: commands.Context) -> None:
description="Failed to get a join code to one of our boards. Please notify staff.",
colour=discord.Colour.red(),
)
await ctx.send(embed=error_embed)
await interaction.response.send_message(embed=error_embed, ephemeral=True)
return

info_str = [
Expand All @@ -226,13 +239,7 @@ async def join_leaderboard(self, ctx: commands.Context) -> None:
"• Head over to https://adventofcode.com/leaderboard/private",
f"• Use this code `{join_code}` to join the Python Discord leaderboard!",
]
try:
await author.send("\n".join(info_str))
except discord.errors.Forbidden:
log.debug(f"{author.name} ({author.id}) has disabled DMs from server members")
await ctx.send(f":x: {author.mention}, please (temporarily) enable DMs to receive the join code")
else:
await ctx.message.add_reaction(Emojis.envelope)
await interaction.response.send_message("\n".join(info_str), ephemeral=True)

@in_month(Month.NOVEMBER, Month.DECEMBER, Month.JANUARY)
@adventofcode_group.command(
Expand Down
Loading