aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Numerlor <[email protected]>2021-06-30 22:13:17 +0200
committerGravatar Numerlor <[email protected]>2021-07-06 02:02:12 +0200
commit82160274aa63a3820f5424eeb54fef4722248293 (patch)
tree9a0616189ff370279034b4ffd5a8deab3069a717
parentAdd option to list all tags in a group (diff)
Move tag search to new design
-rw-r--r--bot/exts/info/tags.py33
1 files changed, 20 insertions, 13 deletions
diff --git a/bot/exts/info/tags.py b/bot/exts/info/tags.py
index 2c6dbd29d..854db5c5c 100644
--- a/bot/exts/info/tags.py
+++ b/bot/exts/info/tags.py
@@ -166,7 +166,12 @@ class Tags(Cog):
suggestions += self._get_suggestions(tag_identifier)
return suggestions
- def _get_tags_via_content(self, check: Callable[[Iterable], bool], keywords: str, user: Member) -> list:
+ def _get_tags_via_content(
+ self,
+ check: Callable[[Iterable], bool],
+ keywords: str,
+ user: Member,
+ ) -> list[tuple[TagIdentifier, Tag]]:
"""
Search for tags via contents.
@@ -186,27 +191,29 @@ class Tags(Cog):
keywords_processed = [keywords]
matching_tags = []
- for tag in self._cache.values():
- matches = (query in tag['embed']['description'].casefold() for query in keywords_processed)
- if self.check_accessibility(user, tag) and check(matches):
- matching_tags.append(tag)
+ for identifier, tag in self._tags.items():
+ matches = (query in tag.content.casefold() for query in keywords_processed)
+ if tag.accessible_by(user) and check(matches):
+ matching_tags.append((identifier, tag))
return matching_tags
- async def _send_matching_tags(self, ctx: Context, keywords: str, matching_tags: list) -> None:
+ async def _send_matching_tags(
+ self,
+ ctx: Context,
+ keywords: str,
+ matching_tags: list[tuple[TagIdentifier, Tag]],
+ ) -> None:
"""Send the result of matching tags to user."""
- if not matching_tags:
- pass
- elif len(matching_tags) == 1:
- await ctx.send(embed=Embed().from_dict(matching_tags[0]['embed']))
- else:
+ if len(matching_tags) == 1:
+ await ctx.send(embed=matching_tags[0][1].embed)
+ elif matching_tags:
is_plural = keywords.strip().count(' ') > 0 or keywords.strip().count(',') > 0
embed = Embed(
title=f"Here are the tags containing the given keyword{'s' * is_plural}:",
- description='\n'.join(tag['title'] for tag in matching_tags[:10])
)
await LinePaginator.paginate(
- sorted(f"**»** {tag['title']}" for tag in matching_tags),
+ sorted(f"**»** {identifier.name}" for identifier, _ in matching_tags),
ctx,
embed,
footer_text=FOOTER_TEXT,