aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar onerandomusername <[email protected]>2021-12-03 17:28:15 -0500
committerGravatar onerandomusername <[email protected]>2021-12-03 17:28:15 -0500
commit7cb5c5517043c0006b001c15373b664b86cc6b43 (patch)
tree3bb11a45c70882f532f9270b1ad362e6c2672e33
parentMerge pull request #963 from python-discord/aoc-lb-multiword (diff)
feat: implement moving commands
add exceptions and handler for commands that move locations
-rw-r--r--bot/constants.py3
-rw-r--r--bot/exts/core/error_handler.py10
-rw-r--r--bot/utils/exceptions.py7
3 files changed, 19 insertions, 1 deletions
diff --git a/bot/constants.py b/bot/constants.py
index f4b1cab0..854fbe55 100644
--- a/bot/constants.py
+++ b/bot/constants.py
@@ -23,6 +23,7 @@ __all__ = (
"Reddit",
"RedisConfig",
"RedirectOutput",
+ "PYTHON_PREFIX"
"MODERATION_ROLES",
"STAFF_ROLES",
"WHITELISTED_CHANNELS",
@@ -34,6 +35,8 @@ __all__ = (
log = logging.getLogger(__name__)
+PYTHON_PREFIX = "!"
+
@dataclasses.dataclass
class AdventOfCodeLeaderboard:
id: str
diff --git a/bot/exts/core/error_handler.py b/bot/exts/core/error_handler.py
index fd2123e7..676a1e70 100644
--- a/bot/exts/core/error_handler.py
+++ b/bot/exts/core/error_handler.py
@@ -12,7 +12,7 @@ from sentry_sdk import push_scope
from bot.bot import Bot
from bot.constants import Channels, Colours, ERROR_REPLIES, NEGATIVE_REPLIES, RedirectOutput
from bot.utils.decorators import InChannelCheckFailure, InMonthCheckFailure
-from bot.utils.exceptions import APIError, UserNotPlayingError
+from bot.utils.exceptions import APIError, MovedCommandError, UserNotPlayingError
log = logging.getLogger(__name__)
@@ -130,6 +130,14 @@ class CommandErrorHandler(commands.Cog):
)
return
+ if isinstance(error, MovedCommandError):
+ description = (
+ f"This command, `{ctx.prefix}{ctx.command.qualified_name}` has moved to `{error.new_command_name}`.\n"
+ f"Please use `{error.new_command_name}` instead."
+ )
+ await ctx.send(embed=self.error_embed(description, NEGATIVE_REPLIES))
+ return
+
with push_scope() as scope:
scope.user = {
"id": ctx.author.id,
diff --git a/bot/utils/exceptions.py b/bot/utils/exceptions.py
index bf0e5813..3cd96325 100644
--- a/bot/utils/exceptions.py
+++ b/bot/utils/exceptions.py
@@ -15,3 +15,10 @@ class APIError(Exception):
self.api = api
self.status_code = status_code
self.error_msg = error_msg
+
+
+class MovedCommandError(Exception):
+ """Raised when a command has moved locations."""
+
+ def __init__(self, new_command_name: str):
+ self.new_command_name = new_command_name