diff options
| author | salmonik <raisersoft@proton.me> | 2026-04-18 00:24:50 +0200 |
|---|---|---|
| committer | salmonik <raisersoft@proton.me> | 2026-04-18 00:24:50 +0200 |
| commit | a2b5b10625126b7e98643af9fe40569c9e004047 (patch) | |
| tree | 2b59a929d068bc28bbc21e8c8d8836e4d29270c0 /cogs/search.py | |
| parent | add mathematical plotting (diff) | |
| download | senator-sperma-a2b5b10625126b7e98643af9fe40569c9e004047.tar.gz senator-sperma-a2b5b10625126b7e98643af9fe40569c9e004047.zip | |
refactor + preparing bot for public use
Signed-off-by: salmonik <raisersoft@proton.me>
Diffstat (limited to '')
| -rw-r--r-- | cogs/search.py | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/cogs/search.py b/cogs/search.py index 2f8373b..a124cbf 100644 --- a/cogs/search.py +++ b/cogs/search.py | |||
| @@ -22,10 +22,10 @@ class Search(commands.Cog): | |||
| 22 | """Autocomplete function for file search.""" | 22 | """Autocomplete function for file search.""" |
| 23 | query = ctx.value.lower() if ctx.value else "" | 23 | query = ctx.value.lower() if ctx.value else "" |
| 24 | results = await search_utils.UniversalSearcher.search_copyparty_autocomplete(query, max_results=25) | 24 | results = await search_utils.UniversalSearcher.search_copyparty_autocomplete(query, max_results=25) |
| 25 | 25 | ||
| 26 | user_id = ctx.interaction.user.id | 26 | user_id = ctx.interaction.user.id |
| 27 | self._cached_results[user_id] = {urllib.parse.unquote(url.split('/')[-1]): url for url in results} | 27 | self._cached_results[user_id] = {urllib.parse.unquote(url.split('/')[-1]): url for url in results} |
| 28 | 28 | ||
| 29 | choices = [] | 29 | choices = [] |
| 30 | for url in results[:25]: | 30 | for url in results[:25]: |
| 31 | filename = urllib.parse.unquote(url.split('/')[-1]) | 31 | filename = urllib.parse.unquote(url.split('/')[-1]) |
| @@ -47,20 +47,20 @@ class Search(commands.Cog): | |||
| 47 | if not filename: | 47 | if not filename: |
| 48 | await ctx.reply("Please select a file from the autocomplete options.") | 48 | await ctx.reply("Please select a file from the autocomplete options.") |
| 49 | return | 49 | return |
| 50 | 50 | ||
| 51 | await ctx.defer() | 51 | await ctx.defer() |
| 52 | logger.info(f"Search command called by {ctx.author} for file: {filename}") | 52 | logger.info(f"Search command called by {ctx.author} for file: {filename}") |
| 53 | 53 | ||
| 54 | cached = self._cached_results.get(ctx.author.id) | 54 | cached = self._cached_results.get(ctx.author.id) |
| 55 | if not cached: | 55 | if not cached: |
| 56 | await ctx.send_followup("Search results expired. Please search again.") | 56 | await ctx.send_followup("Search results expired. Please search again.") |
| 57 | return | 57 | return |
| 58 | 58 | ||
| 59 | matching_url = cached.get(filename) | 59 | matching_url = cached.get(filename) |
| 60 | if not matching_url: | 60 | if not matching_url: |
| 61 | await ctx.send_followup(f"File '{filename}' not found.") | 61 | await ctx.send_followup(f"File '{filename}' not found.") |
| 62 | return | 62 | return |
| 63 | 63 | ||
| 64 | try: | 64 | try: |
| 65 | await ctx.send_followup(matching_url) | 65 | await ctx.send_followup(matching_url) |
| 66 | logger.info(f"Successfully sent URL: {matching_url}") | 66 | logger.info(f"Successfully sent URL: {matching_url}") |
