aboutsummaryrefslogtreecommitdiffstats
path: root/cogs/search.py
diff options
context:
space:
mode:
authorsalmonik <raisersoft@proton.me>2026-07-08 02:13:35 +0200
committersalmonik <raisersoft@proton.me>2026-07-08 02:13:35 +0200
commitcd8ed8bc5793985df2c1692072a932ceee517b95 (patch)
tree42d18a4140259b5c68b4dd05b7fcb398f78b8d7f /cogs/search.py
parentMerge pull request 'Voice related fixes, alongside simplifying assistant' (#5... (diff)
downloadsenator-sperma-cd8ed8bc5793985df2c1692072a932ceee517b95.tar.gz
senator-sperma-cd8ed8bc5793985df2c1692072a932ceee517b95.zip
OPEN THE RUST GATES
Signed-off-by: salmonik <raisersoft@proton.me>
Diffstat (limited to '')
-rw-r--r--cogs/search.py73
1 files changed, 0 insertions, 73 deletions
diff --git a/cogs/search.py b/cogs/search.py
deleted file mode 100644
index a124cbf..0000000
--- a/cogs/search.py
+++ /dev/null
@@ -1,73 +0,0 @@
1# This file is part of Senator Sperma
2# Licensed under the GPL-3.0 License
3# Copyright (C) 2026 Salmonik @ salmonik@tuta.io
4# https://codeberg.org/salmonik/senator-sperma
5
6import urllib.parse
7
8import discord
9from discord.ext import commands
10import logging
11from discord import AutocompleteContext
12from cogs.utils import file_search as search_utils
13
14logger = logging.getLogger(__name__)
15
16class Search(commands.Cog):
17 def __init__(self, bot):
18 self.bot = bot
19 self._cached_results = {}
20
21 async def file_autocomplete(self, ctx: AutocompleteContext):
22 """Autocomplete function for file search."""
23 query = ctx.value.lower() if ctx.value else ""
24 results = await search_utils.UniversalSearcher.search_copyparty_autocomplete(query, max_results=25)
25
26 user_id = ctx.interaction.user.id
27 self._cached_results[user_id] = {urllib.parse.unquote(url.split('/')[-1]): url for url in results}
28
29 choices = []
30 for url in results[:25]:
31 filename = urllib.parse.unquote(url.split('/')[-1])
32 display_name = filename[:99] + "…" if len(filename) > 100 else filename
33 choices.append(discord.OptionChoice(name=display_name, value=filename))
34 return choices
35
36 @commands.slash_command(
37 name="search",
38 description="wyszukaj pliku"
39 )
40 @discord.option(
41 name="filename",
42 description="Search for a file to send",
43 autocomplete=file_autocomplete
44 )
45 async def search(self, ctx, filename: str):
46 """Send a file via URL from autocomplete selection."""
47 if not filename:
48 await ctx.reply("Please select a file from the autocomplete options.")
49 return
50
51 await ctx.defer()
52 logger.info(f"Search command called by {ctx.author} for file: {filename}")
53
54 cached = self._cached_results.get(ctx.author.id)
55 if not cached:
56 await ctx.send_followup("Search results expired. Please search again.")
57 return
58
59 matching_url = cached.get(filename)
60 if not matching_url:
61 await ctx.send_followup(f"File '{filename}' not found.")
62 return
63
64 try:
65 await ctx.send_followup(matching_url)
66 logger.info(f"Successfully sent URL: {matching_url}")
67 del self._cached_results[ctx.author.id]
68 except Exception as e:
69 logger.error(f"Error sending URL {matching_url}: {str(e)}")
70 await ctx.send_followup(str(e))
71
72def setup(bot):
73 bot.add_cog(Search(bot))