aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Shirayuki Nekomata <[email protected]>2020-03-08 12:06:10 +0700
committerGravatar Shirayuki Nekomata <[email protected]>2020-03-08 12:06:10 +0700
commit76fccc1ea47162346d60736db638eea7166222ae (patch)
treeeda534c7c5d2280af818aa7b41b96e540ade4bed
parentImplemented `search` as a subcommand for `tag` that will search in contents i... (diff)
Refactored tag searching via keywords in contents
- Refactored `if` block - change to only send result when there is any result. - Added better type hinting for `check` argument of `_get_tags_via_content` - changed from `callable` to `Callable[[Iterable], bool]`. Thanks to @markkoz 's reviews Co-Authored-By: Mark <[email protected]>
-rw-r--r--bot/cogs/tags.py14
1 files changed, 6 insertions, 8 deletions
diff --git a/bot/cogs/tags.py b/bot/cogs/tags.py
index 965a29596..63b529945 100644
--- a/bot/cogs/tags.py
+++ b/bot/cogs/tags.py
@@ -1,7 +1,7 @@
import logging
import re
import time
-from typing import Dict, List, Optional, Tuple
+from typing import Callable, Dict, Iterable, List, Optional, Tuple
from discord import Colour, Embed
from discord.ext.commands import Cog, Context, group
@@ -86,7 +86,7 @@ class Tags(Cog):
return self._get_suggestions(tag_name)
return found
- async def _get_tags_via_content(self, check: callable, keywords: str) -> Optional[Embed]:
+ async def _get_tags_via_content(self, check: Callable[[Iterable], bool], keywords: str) -> Optional[Embed]:
"""
Search for tags via contents.
@@ -124,9 +124,8 @@ class Tags(Cog):
Only search for tags that has ALL the keywords.
"""
result = await self._get_tags_via_content(all, keywords)
- if not result:
- return
- await ctx.send(embed=result)
+ if result:
+ await ctx.send(embed=result)
@search_tag_content.command(name='any')
async def search_tag_content_any_keyword(self, ctx: Context, *, keywords: Optional[str] = None) -> None:
@@ -136,9 +135,8 @@ class Tags(Cog):
Search for tags that has ANY of the keywords.
"""
result = await self._get_tags_via_content(any, keywords or 'any')
- if not result:
- return
- await ctx.send(embed=result)
+ if result:
+ await ctx.send(embed=result)
@tags_group.command(name='get', aliases=('show', 'g'))
async def get_command(self, ctx: Context, *, tag_name: TagNameConverter = None) -> None: