aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bot/decorators.py15
-rw-r--r--bot/seasons/evergreen/error_handler.py4
2 files changed, 15 insertions, 4 deletions
diff --git a/bot/decorators.py b/bot/decorators.py
index 8a1f00ee..f031d404 100644
--- a/bot/decorators.py
+++ b/bot/decorators.py
@@ -21,6 +21,12 @@ class InChannelCheckFailure(CheckFailure):
pass
+class InMonthCheckFailure(CheckFailure):
+ """Check failure for when a command is invoked outside of its allowed month."""
+
+ pass
+
+
def in_month(*allowed_months: Month) -> typing.Callable:
"""
Check whether the command was invoked in one of `enabled_months`.
@@ -31,11 +37,16 @@ def in_month(*allowed_months: Month) -> typing.Callable:
current_month = datetime.utcnow().month
can_run = current_month in allowed_months
+ human_months = ", ".join(m.name for m in allowed_months)
log.debug(
- f"Command '{ctx.command}' is locked to months {allowed_months}. "
+ f"Command '{ctx.command}' is locked to months {human_months}. "
f"Invoking it in month {current_month} is {'allowed' if can_run else 'disallowed'}."
)
- return can_run
+ if can_run:
+ return True
+ else:
+ raise InMonthCheckFailure(f"Command can only be used in {human_months}")
+
return commands.check(predicate)
diff --git a/bot/seasons/evergreen/error_handler.py b/bot/seasons/evergreen/error_handler.py
index 0d8bb0bb..ba6ca5ec 100644
--- a/bot/seasons/evergreen/error_handler.py
+++ b/bot/seasons/evergreen/error_handler.py
@@ -7,7 +7,7 @@ from discord import Embed, Message
from discord.ext import commands
from bot.constants import Colours, ERROR_REPLIES, NEGATIVE_REPLIES
-from bot.decorators import InChannelCheckFailure
+from bot.decorators import InChannelCheckFailure, InMonthCheckFailure
log = logging.getLogger(__name__)
@@ -55,7 +55,7 @@ class CommandErrorHandler(commands.Cog):
if isinstance(error, commands.CommandNotFound):
return
- if isinstance(error, InChannelCheckFailure):
+ if isinstance(error, (InChannelCheckFailure, InMonthCheckFailure)):
await ctx.send(embed=self.error_embed(str(error), NEGATIVE_REPLIES), delete_after=7.5)
return