aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bot/cogs/error_handler.py31
-rw-r--r--bot/cogs/tags.py19
2 files changed, 42 insertions, 8 deletions
diff --git a/bot/cogs/error_handler.py b/bot/cogs/error_handler.py
index 52893b2ee..13221799b 100644
--- a/bot/cogs/error_handler.py
+++ b/bot/cogs/error_handler.py
@@ -1,4 +1,5 @@
-import contextlib
+# import contextlib
+import difflib
import logging
from discord.ext.commands import (
@@ -75,7 +76,7 @@ class ErrorHandler(Cog):
if not ctx.channel.id == Channels.verification:
tags_get_command = self.bot.get_command("tags get")
ctx.invoked_from_error_handler = True
-
+ command_name = ctx.invoked_with
log_msg = "Cancelling attempt to fall back to a tag due to failed checks."
try:
if not await tags_get_command.can_run(ctx):
@@ -87,9 +88,31 @@ class ErrorHandler(Cog):
return
# Return to not raise the exception
- with contextlib.suppress(ResponseCodeError):
- await ctx.invoke(tags_get_command, tag_name=ctx.invoked_with)
+ log.debug("Calling...")
+ tags_cog = self.bot.get_cog("Tags")
+ sent = await tags_cog._get_command(ctx, command_name)
+ # sent = await tags_get_command.callback(tags_get_command.cog, ctx, ctx.invoked_with)
+ if sent:
+ log.debug("Found")
return
+ # No similar tag found, or tag on cooldown -
+ # searching for a similar command
+ log.debug("Not Found")
+ raw_commands = [
+ (cmd.name, *cmd.aliases)
+ for cmd in self.bot.walk_commands()
+ if not cmd.hidden
+ ]
+ raw_commands = [c for data in raw_commands for c in data]
+ similar_command_data = difflib.get_close_matches(command_name, raw_commands, 1)
+ log.debug(similar_command_data)
+ similar_command = self.bot.get_command(similar_command_data[0])
+ if similar_command.can_run(ctx):
+ misspelled_content = ctx.message.content
+ await ctx.send(
+ f"Did you mean:\n**{misspelled_content.replace(command_name, similar_command.name)}**"
+ )
+
elif isinstance(e, BadArgument):
await ctx.send(f"Bad argument: {e}\n")
await ctx.invoke(*help_command)
diff --git a/bot/cogs/tags.py b/bot/cogs/tags.py
index 54a51921c..61cf55d65 100644
--- a/bot/cogs/tags.py
+++ b/bot/cogs/tags.py
@@ -92,9 +92,9 @@ class Tags(Cog):
"""Show all known tags, a single tag, or run a subcommand."""
await ctx.invoke(self.get_command, tag_name=tag_name)
- @tags_group.command(name='get', aliases=('show', 'g'))
- async def get_command(self, ctx: Context, *, tag_name: TagNameConverter = None) -> None:
- """Get a specified tag, or a list of all tags if no tag is specified."""
+ async def _get_command(self, ctx: Context, *, tag_name: TagNameConverter = None) -> None:
+ log.debug(self, ctx, tag_name)
+
def _command_on_cooldown(tag_name: str) -> bool:
"""
Check if the command is currently on cooldown, on a per-tag, per-channel basis.
@@ -118,7 +118,7 @@ class Tags(Cog):
time_left = Cooldowns.tags - (time.time() - self.tag_cooldowns[tag_name]["time"])
log.warning(f"{ctx.author} tried to get the '{tag_name}' tag, but the tag is on cooldown. "
f"Cooldown ends in {time_left:.1f} seconds.")
- return
+ return False
await self._get_tags()
@@ -133,11 +133,13 @@ class Tags(Cog):
"channel": ctx.channel.id
}
await ctx.send(embed=Embed.from_dict(tag['embed']))
+ return True
elif founds and len(tag_name) >= 3:
await ctx.send(embed=Embed(
title='Did you mean ...',
description='\n'.join(tag['title'] for tag in founds[:10])
))
+ return True
else:
tags = self._cache.values()
@@ -146,6 +148,7 @@ class Tags(Cog):
description="**There are no tags in the database!**",
colour=Colour.red()
))
+ return True
else:
embed: Embed = Embed(title="**Current tags**")
await LinePaginator.paginate(
@@ -156,6 +159,14 @@ class Tags(Cog):
empty=False,
max_lines=15
)
+ return True
+
+ return False
+
+ @tags_group.command(name='get', aliases=('show', 'g'))
+ async def get_command(self, ctx: Context, *, tag_name: TagNameConverter = None) -> None:
+ """Get a specified tag, or a list of all tags if no tag is specified."""
+ await self._get_command(ctx, tag_name)
@tags_group.command(name='set', aliases=('add', 's'))
@with_role(*MODERATION_ROLES)