aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Boris Muratov <[email protected]>2020-12-12 05:27:13 +0200
committerGravatar GitHub <[email protected]>2020-12-12 05:27:13 +0200
commitd56ec4ba3969b84a78cc9f22a1eca5bb7e8d5a77 (patch)
tree9933ee13de2ae72ede93e8f04133196e810e4bcc
parentMerge pull request #540 from RohanJnr/error_handler_changes (diff)
parentChange AOC_WHITELIST names for clarity (diff)
Merge pull request #541 from janine9vn/aoc2020
Aoc2020
-rw-r--r--bot/constants.py1
-rw-r--r--bot/exts/christmas/advent_of_code/_cog.py20
2 files changed, 16 insertions, 5 deletions
diff --git a/bot/constants.py b/bot/constants.py
index 9e6db7a6..a58801f7 100644
--- a/bot/constants.py
+++ b/bot/constants.py
@@ -95,6 +95,7 @@ class Branding:
class Channels(NamedTuple):
admins = 365960823622991872
advent_of_code = int(environ.get("AOC_CHANNEL_ID", 782715290437943306))
+ advent_of_code_commands = int(environ.get("AOC_COMMANDS_CHANNEL_ID", 607247579608121354))
announcements = int(environ.get("CHANNEL_ANNOUNCEMENTS", 354619224620138496))
big_brother_logs = 468507907357409333
bot = 267659945086812160
diff --git a/bot/exts/christmas/advent_of_code/_cog.py b/bot/exts/christmas/advent_of_code/_cog.py
index 0bcd9f42..0968dd26 100644
--- a/bot/exts/christmas/advent_of_code/_cog.py
+++ b/bot/exts/christmas/advent_of_code/_cog.py
@@ -13,7 +13,7 @@ from bot.constants import (
AdventOfCode as AocConfig, Channels, Colours, Emojis, Month, Roles, WHITELISTED_CHANNELS,
)
from bot.exts.christmas.advent_of_code import _helpers
-from bot.utils.decorators import in_month, override_in_channel, with_role
+from bot.utils.decorators import InChannelCheckFailure, in_month, override_in_channel, with_role
log = logging.getLogger(__name__)
@@ -21,7 +21,11 @@ AOC_REQUEST_HEADER = {"user-agent": "PythonDiscord AoC Event Bot"}
COUNTDOWN_STEP = 60 * 5
-AOC_WHITELIST = WHITELISTED_CHANNELS + (Channels.advent_of_code,)
+AOC_WHITELIST_RESTRICTED = WHITELISTED_CHANNELS + (Channels.advent_of_code_commands,)
+
+# Some commands can be run in the regular advent of code channel
+# They aren't spammy and foster discussion
+AOC_WHITELIST = AOC_WHITELIST_RESTRICTED + (Channels.advent_of_code,)
async def countdown_status(bot: commands.Bot) -> None:
@@ -256,7 +260,7 @@ class AdventOfCode(commands.Cog):
aliases=("board", "lb"),
brief="Get a snapshot of the PyDis private AoC leaderboard",
)
- @override_in_channel(AOC_WHITELIST)
+ @override_in_channel(AOC_WHITELIST_RESTRICTED)
async def aoc_leaderboard(self, ctx: commands.Context) -> None:
"""Get the current top scorers of the Python Discord Leaderboard."""
async with ctx.typing():
@@ -281,7 +285,7 @@ class AdventOfCode(commands.Cog):
aliases=("globalboard", "gb"),
brief="Get a link to the global leaderboard",
)
- @override_in_channel(AOC_WHITELIST)
+ @override_in_channel(AOC_WHITELIST_RESTRICTED)
async def aoc_global_leaderboard(self, ctx: commands.Context) -> None:
"""Get a link to the global Advent of Code leaderboard."""
url = self.global_leaderboard_url
@@ -297,7 +301,7 @@ class AdventOfCode(commands.Cog):
aliases=("dailystats", "ds"),
brief="Get daily statistics for the Python Discord leaderboard"
)
- @override_in_channel(AOC_WHITELIST)
+ @override_in_channel(AOC_WHITELIST_RESTRICTED)
async def private_leaderboard_daily_stats(self, ctx: commands.Context) -> None:
"""Send an embed with daily completion statistics for the Python Discord leaderboard."""
try:
@@ -366,3 +370,9 @@ class AdventOfCode(commands.Cog):
about_embed.set_footer(text="Last Updated")
return about_embed
+
+ async def cog_command_error(self, ctx: commands.Context, error: Exception) -> None:
+ """Custom error handler if an advent of code command was posted in the wrong channel."""
+ if isinstance(error, InChannelCheckFailure):
+ await ctx.send(f":x: Please use <#{Channels.advent_of_code_commands}> for aoc commands instead.")
+ error.handled = True