diff options
| author | 2020-03-08 12:37:42 +0700 | |
|---|---|---|
| committer | 2020-03-08 12:37:42 +0700 | |
| commit | 89f86f873d7cd6ade626a0a91c5d9e09c5c14102 (patch) | |
| tree | 74b5a335a53e9f114f093d8ce715801db778e1aa | |
| parent | Refactored tag searching via keywords in contents (diff) | |
Fixed searching for `,` returing all tags. Made it more descriptive when multiple tags are found.
- Added a truthy check for each `query` since `','.split()` returns a list of two empty strings.
- Changed from `Did you mean ...` to `Here are the tags containing the given keyword(s):` to be much more descriptive about the results - they are `tag` and not `term` to be searched.
| -rw-r--r-- | bot/cogs/tags.py | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/bot/cogs/tags.py b/bot/cogs/tags.py index 63b529945..49ed87c92 100644 --- a/bot/cogs/tags.py +++ b/bot/cogs/tags.py @@ -94,7 +94,8 @@ class Tags(Cog): """ await self._get_tags() - keywords_processed: Tuple[str] = tuple(query.strip().casefold() for query in keywords.split(',')) + keywords_processed: Tuple[str] = tuple(query.strip().casefold() for query in keywords.split(',') if query) + keywords_processed = keywords_processed or (keywords,) founds: list = [ tag for tag in self._cache.values() @@ -106,10 +107,13 @@ class Tags(Cog): elif len(founds) == 1: return Embed().from_dict(founds[0]['embed']) else: - return Embed( - title='Did you mean ...', + is_plural: bool = len(keywords_processed) > 1 or any(kw.count(' ') for kw in keywords_processed) + embed = Embed( + title=f"Here are the tags containing the given keyword{'s' * is_plural}:", description='\n'.join(tag['title'] for tag in founds[:10]) ) + embed.set_footer(text=f"Keyword{'s' * is_plural} used: {keywords}"[:1024]) + return embed @group(name='tags', aliases=('tag', 't'), invoke_without_command=True) async def tags_group(self, ctx: Context, *, tag_name: TagNameConverter = None) -> None: |