From f00a4fe39ca76a5fe017fb7504b30b55706902e4 Mon Sep 17 00:00:00 2001 From: TimJentzsch Date: Mon, 29 May 2023 11:49:41 +0200 Subject: [PATCH] Fix feed parameter in `/search` command (#203) * Fix query parameter to filter by feed * Make /r/ prefix optional in feed parameter * Fix lint errors --- buttercup/cogs/search.py | 9 ++++++--- buttercup/strings/en_US.yaml | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/buttercup/cogs/search.py b/buttercup/cogs/search.py index 2828004..fb3a708 100644 --- a/buttercup/cogs/search.py +++ b/buttercup/cogs/search.py @@ -18,6 +18,7 @@ from buttercup.cogs.helpers import ( BlossomException, BlossomUser, + extract_sub_name, get_discord_time_str, get_duration_str, get_initial_username, @@ -269,7 +270,8 @@ async def _search_from_cache( from_str = after_time.isoformat() if after_time else None until_str = before_time.isoformat() if before_time else None - feed = feed if feed else None + feed = "/r/" + extract_sub_name(feed) if feed else None + feed_str = feed if feed else "all feeds" request_page = (discord_page * self.discord_page_size) // self.request_page_size @@ -280,7 +282,7 @@ async def _search_from_cache( "author": user_id, "create_time__gte": from_str, "create_time__lte": until_str, - "feed": feed, + "submission__feed__iexact": feed, "url__isnull": False, "ordering": "-create_time", "page_size": self.request_page_size, @@ -299,7 +301,7 @@ async def _search_from_cache( query=query, user=get_username(user), time_str=time_str, - feed_str=feed if feed else "all feeds", + feed_str=feed_str, duration_str=get_duration_str(start), ) ) @@ -344,6 +346,7 @@ async def _search_from_cache( query=query, user=get_username(user), time_str=time_str, + feed_str=feed_str, duration_str=get_duration_str(start), ), embed=Embed( diff --git a/buttercup/strings/en_US.yaml b/buttercup/strings/en_US.yaml index 57df44c..112f925 100755 --- a/buttercup/strings/en_US.yaml +++ b/buttercup/strings/en_US.yaml @@ -290,7 +290,7 @@ search: more_occurrences: |- ... and {count} more occurrence(s). embed_message: |- - Here are your results for `{query}` in transcriptions by {user} {time_str}! ({duration_str}) + Here are your results for `{query}` in transcriptions by {user} {time_str} in {feed_str}! ({duration_str}) embed_title: |- Results for `{query}` by {user} embed_footer: |-