diff options
author | 2019-10-11 21:17:35 +0800 | |
---|---|---|
committer | 2019-10-11 21:17:35 +0800 | |
commit | 2a1b017d5586e7646d6922c4795f8c98d20c722b (patch) | |
tree | 1896e6c43501cc54969d5a658caab5ce9c5e31e7 | |
parent | Merge pull request #467 from Ayplow/short-docs (diff) |
Add check to !otn add to prevent too similar names.
-rw-r--r-- | bot/cogs/off_topic_names.py | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/bot/cogs/off_topic_names.py b/bot/cogs/off_topic_names.py index 16717d523..362aa1b6d 100644 --- a/bot/cogs/off_topic_names.py +++ b/bot/cogs/off_topic_names.py @@ -96,14 +96,36 @@ class OffTopicNames(Cog): @otname_group.command(name='add', aliases=('a',)) @with_role(*MODERATION_ROLES) async def add_command(self, ctx: Context, *names: OffTopicName) -> None: - """Adds a new off-topic name to the rotation.""" + """ + Adds a new off-topic name to the rotation. + + The name is not added if it is too similar to an existing name. + """ # Chain multiple words to a single one name = "-".join(names) + existing_names = await self.bot.api_client.get('bot/off-topic-channel-names') + close_match = difflib.get_close_matches(name, existing_names, n=1, cutoff=0.8) + + if close_match: + match = close_match[0] + log.info( + f"{ctx.author.name}#{ctx.author.discriminator}" + f" tried to add channel name '{name}' but it was too similar to '{match}'" + ) + await ctx.send( + f":x: The channel name `{name}` is too similar to `{match}`, and thus was not added. " + f"Use `!otn forceadd` to override this check." + ) + else: + await self._add_name(ctx, name) + + async def _add_name(self, ctx: Context, name: str) -> None: + """Adds an off-topic channel name to the site storage.""" await self.bot.api_client.post(f'bot/off-topic-channel-names', params={'name': name}) log.info( f"{ctx.author.name}#{ctx.author.discriminator}" - f" added the off-topic channel name '{name}" + f" added the off-topic channel name '{name}'" ) await ctx.send(f":ok_hand: Added `{name}` to the names list.") |