aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Leon Sandøy <[email protected]>2019-09-16 21:42:47 +0200
committerGravatar GitHub <[email protected]>2019-09-16 21:42:47 +0200
commitad6b6ad1f279c790028c5a326b6e386817a709d3 (patch)
tree07309446427c5f5ed4e88a3b29f5d188c6869dfc
parentUpdate discord.py version to 1.2.3 (#433) (diff)
parentMerge branch 'master' into otn-search-command (diff)
Merge pull request #429 from python-discord/otn-search-command
Implement `!otn search`. Closes #408.
-rw-r--r--bot/cogs/off_topic_names.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/bot/cogs/off_topic_names.py b/bot/cogs/off_topic_names.py
index cadc1bf92..cb8a03374 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(Cog):
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))