Files
conjurer/file_search_commands.py
T
Michal Tuszowski a64fb2da57 Restructure: promote working_copy to repo root
Make the stable 'working copy' bot the canonical code at the repository
root so the install/deploy scripts operate against it again.

- Move working_copy/* to root (bot entrypoint is bot.py)
- Restore root-level install/ops scripts from c4fa88e (deploy.sh,
  install_main_bot.sh, status_report.*, conjurer.service, etc.)
- Fix deploy.sh: copy bot.py (was thin_client.py) and add the
  conanjurer_* modules; bump command count
- Remove side-by-side variant dirs (backup_old_docker, prototype_one,
  prototype_musician_one, musician_old, working_copy) and docker cruft
- Keep components as subdirs: conjurer_librarian, conjurer_musician,
  spotify_dl, yt_dlp, fonts, utils, docs

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-28 23:50:55 +02:00

72 lines
2.8 KiB
Python

import os
import discord
from discord.ext import commands
import file_search_functions
class FileSelectView(discord.ui.View):
def __init__(self, files):
super().__init__(timeout=60)
options = [discord.SelectOption(label=os.path.basename(f)[:100], description=f, value=f) for f in files]
self.select = discord.ui.Select(
placeholder="Select files...",
min_values=1,
max_values=len(options),
options=options
)
self.select.callback = self.select_callback
self.add_item(self.select)
self.selected = []
async def select_callback(self, interaction: discord.Interaction):
# Store selected file paths
self.selected = self.select.values
await interaction.response.defer()
@discord.ui.button(label="Accept", style=discord.ButtonStyle.green)
async def accept_callback(self, interaction: discord.Interaction, button: discord.ui.Button):
# Handle acceptance
if not self.selected:
await interaction.response.send_message("No files selected.", ephemeral=True)
return
# Publish selected files
links = file_search_functions.publish(self.selected)
# Display the returned links
await interaction.response.edit_message(content="Published Links:\n" + "\n".join(links), view=None)
@discord.ui.button(label="Cancel", style=discord.ButtonStyle.red)
async def cancel_callback(self, interaction: discord.Interaction, button: discord.ui.Button):
# Handle cancellation
await interaction.response.edit_message(content="Operation cancelled.", view=None)
class FileSearchCog(commands.Cog):
"""Cog providing a file search and publish command."""
def __init__(self, bot: commands.Bot):
self.bot = bot
@commands.has_any_role("Jarl", "Thane")
@commands.command(name="tajna_biblioteka_inkwizycji")
async def findfiles(self, ctx: commands.Context, entries: int, *, keywords: str):
"""
Search for files matching keywords and publish selected ones.
Usage: !findfiles <entries 1-10> <keywords>
"""
if entries < 1 or entries > 10:
await ctx.send("❌ Entries must be between 1 and 10.")
return
keyword_list = keywords.split()
files = file_search_functions.find_matches(entries, keyword_list)
if not files:
await ctx.send("🔍 No matching files found.")
return
view = FileSelectView(files)
file_list = "\n".join(f"{i+1}. {f}" for i, f in enumerate(files))
await ctx.send(
f"🔍 Found files (select and click Accept or Cancel):\n{file_list}",
view=view
)
async def setup(bot: commands.Bot):
await bot.add_cog(FileSearchCog(bot))