diff options
-rw-r--r-- | bot/cogs/off_topic_names.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/bot/cogs/off_topic_names.py b/bot/cogs/off_topic_names.py index 5a61425be..8f5f9c2e5 100644 --- a/bot/cogs/off_topic_names.py +++ b/bot/cogs/off_topic_names.py @@ -1,4 +1,5 @@ import asyncio +import difflib import logging from datetime import datetime, timedelta @@ -141,6 +142,27 @@ class OffTopicNames: embed.description = "Hmmm, seems like there's nothing here yet." await ctx.send(embed=embed) + @otname_group.command(name='search', aliases=('s',)) + @with_role(*MODERATION_ROLES) + async def search_command(self, ctx, *, query: str): + """ + Search for an off-topic name. + """ + + result = await self.bot.api_client.get('bot/off-topic-channel-names') + matches = difflib.get_close_matches(query, result, n=10, cutoff=0.35) + lines = sorted(f"• {name}" for name in matches) + embed = Embed( + title=f"Query results", + colour=Colour.blue() + ) + + if matches: + await LinePaginator.paginate(lines, ctx, embed, max_size=400, empty=False) + else: + embed.description = "Nothing found." + await ctx.send(embed=embed) + def setup(bot: Bot): bot.add_cog(OffTopicNames(bot)) |