aboutsummaryrefslogtreecommitdiffstats
path: root/bot/exts/backend
diff options
context:
space:
mode:
Diffstat (limited to 'bot/exts/backend')
-rw-r--r--bot/exts/backend/error_handler.py14
-rw-r--r--bot/exts/backend/security.py30
2 files changed, 41 insertions, 3 deletions
diff --git a/bot/exts/backend/error_handler.py b/bot/exts/backend/error_handler.py
index 761991488..f9ded79f0 100644
--- a/bot/exts/backend/error_handler.py
+++ b/bot/exts/backend/error_handler.py
@@ -75,7 +75,7 @@ class ErrorHandler(Cog):
elif isinstance(e, errors.CheckFailure):
log.debug(debug_message)
await self.handle_check_failure(ctx, e)
- elif isinstance(e, errors.CommandOnCooldown):
+ elif isinstance(e, (errors.CommandOnCooldown, errors.MaxConcurrencyReached)):
log.debug(debug_message)
await ctx.send(e)
elif isinstance(e, errors.CommandInvokeError):
@@ -95,7 +95,7 @@ class ErrorHandler(Cog):
elif isinstance(e, errors.DisabledCommand):
log.debug(debug_message)
else:
- # MaxConcurrencyReached, ExtensionError
+ # ExtensionError
await self.handle_unexpected_error(ctx, e)
async def send_command_help(self, ctx: Context) -> None:
@@ -116,9 +116,13 @@ class ErrorHandler(Cog):
* invoked with `unshh+` unsilence channel
Return bool depending on success of command.
"""
+ silence_command = self.bot.get_command("silence")
+ if not silence_command:
+ log.debug("Not attempting to parse message as `shh`/`unshh` as could not find `silence` command.")
+ return False
+
command = ctx.invoked_with.lower()
args = ctx.message.content.lower().split(" ")
- silence_command = self.bot.get_command("silence")
ctx.invoked_from_error_handler = True
try:
@@ -164,6 +168,10 @@ class ErrorHandler(Cog):
the context to prevent infinite recursion in the case of a CommandNotFound exception.
"""
tags_get_command = self.bot.get_command("tags get")
+ if not tags_get_command:
+ log.debug("Not attempting to parse message as a tag as could not find `tags get` command.")
+ return
+
ctx.invoked_from_error_handler = True
log_msg = "Cancelling attempt to fall back to a tag due to failed checks."
diff --git a/bot/exts/backend/security.py b/bot/exts/backend/security.py
new file mode 100644
index 000000000..27e4d9752
--- /dev/null
+++ b/bot/exts/backend/security.py
@@ -0,0 +1,30 @@
+from discord.ext.commands import Cog, Context, NoPrivateMessage
+
+from bot.bot import Bot
+from bot.log import get_logger
+
+log = get_logger(__name__)
+
+
+class Security(Cog):
+ """Security-related helpers."""
+
+ def __init__(self, bot: Bot):
+ self.bot = bot
+ self.bot.check(self.check_not_bot) # Global commands check - no bots can run any commands at all
+ self.bot.check(self.check_on_guild) # Global commands check - commands can't be run in a DM
+
+ def check_not_bot(self, ctx: Context) -> bool:
+ """Check if the context is a bot user."""
+ return not ctx.author.bot
+
+ def check_on_guild(self, ctx: Context) -> bool:
+ """Check if the context is in a guild."""
+ if ctx.guild is None:
+ raise NoPrivateMessage("This command cannot be used in private messages.")
+ return True
+
+
+async def setup(bot: Bot) -> None:
+ """Load the Security cog."""
+ await bot.add_cog(Security(bot))