diff options
author | 2021-07-01 00:31:56 +0200 | |
---|---|---|
committer | 2021-07-06 02:02:13 +0200 | |
commit | aafd0e614512c7ffdfaa90ad384168033549ad8a (patch) | |
tree | e1dc334e8166005be0856fae351f287502898d1c | |
parent | Do not add suggestion for tags with short names if a group is specified (diff) |
Emit tag if only one fuzzy match is found
This feature was accidentally removed when restructuring the code
-rw-r--r-- | bot/exts/info/tags.py | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/bot/exts/info/tags.py b/bot/exts/info/tags.py index 798be6543..6971397d4 100644 --- a/bot/exts/info/tags.py +++ b/bot/exts/info/tags.py @@ -263,8 +263,18 @@ class Tags(Cog): If the requested tag is on cooldown or no suggestions were found, return None. """ - if (tag := self._tags.get(tag_identifier)) is not None and tag.accessible_by(ctx.author): - + filtered_tags = [ + (ident, tag) for ident, tag in + self.get_fuzzy_matches(tag_identifier)[:10] + if tag.accessible_by(ctx.author) + ] + + if (tag := self._tags.get(tag_identifier)) is None: + if len(filtered_tags) == 1: + tag_identifier = filtered_tags[0][0] + tag = filtered_tags[0][1] + + if tag is not None: if tag.on_cooldown_in(ctx.channel): log.debug(f"Tag {str(tag_identifier)!r} is on cooldown.") return COOLDOWN.obj @@ -278,14 +288,12 @@ class Tags(Cog): return tag.embed else: - suggested_tags = self.get_fuzzy_matches(tag_identifier)[:10] - if not suggested_tags: + if not filtered_tags: return None suggested_tags_text = "\n".join( f"**\N{RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK}** {identifier}" - for identifier, tag in suggested_tags - if tag.accessible_by(ctx.author) - and not tag.on_cooldown_in(ctx.channel) + for identifier, tag in filtered_tags + if not tag.on_cooldown_in(ctx.channel) ) return Embed( title="Did you mean ...", |