commit a1cb90c9638bd91ce50652771d2fe8147f63686c Author: Jonathan Jara Date: Fri Apr 18 13:59:16 2025 -0700 first push diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c66ba3a --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.env +.venv \ No newline at end of file diff --git a/bot.py b/bot.py new file mode 100644 index 0000000..eff54bb --- /dev/null +++ b/bot.py @@ -0,0 +1,70 @@ +import os +import requests +import discord +from discord.ext import commands +from discord import app_commands +from dotenv import load_dotenv +import io +import asyncio + +load_dotenv() +TOKEN = os.getenv("DISCORD_TOKEN") +GUILD_ID = discord.Object(id=1131317261202899034) +JELLYFIN_URL = os.getenv("JELLYFIN_URL") +JELLYFIN_API_KEY = os.getenv("JELLYFIN_API_KEY") + +headers= { + "X-Emby-Token": JELLYFIN_API_KEY +} + +intents = discord.Intents.default() +intents.message_content = True +intents.voice_states = True + +class JellyfinBot(commands.Bot): + def __init__(self): + super().__init__(command_prefix="/", intents=intents) + + async def setup_hook(self): + self.tree.copy_global_to(guild=GUILD_ID) + await self.tree.sync(guild=GUILD_ID) + +bot = JellyfinBot() + +@bot.event +async def on_ready(): + print(f"🪼 Logged in as {bot.user}") + +@bot.tree.command(name="search", description="Search for a song on Jellyfin") +@app_commands.describe(title="Song title to search for") +async def search(interaction: discord.Interaction, title: str): + await interaction.response.defer(ephemeral=True) + url = f"{JELLYFIN_URL}/Items" + params = { + "searchTerm": title, + "Recursive": True, + "IncludeItemTypes": "Audio", + "Limit": 5 + } + try: + response = requests.get(url, headers=headers, params=params) + response.raise_for_status() + data = response.json() + items = data.get("Items", []) + if not items: + await interaction.followup.send(f"❌ No song found matching `{title}`.") + return + + lines = [] + for item in items: + title = item.get("Name") + artist = item.get("AlbumArtist", ["Unknown Artist"]) + lines.append(f"✅ **{title}** by *{artist}*") + await interaction.followup.send("\n".join(lines)) + + except requests.RequestException as e: + await interaction.followup.send("⚠️ Failed to contact Jellyfin server.") + print(f"Error: {e}") + + +bot.run(TOKEN) diff --git a/ffmpeg.exe b/ffmpeg.exe new file mode 100644 index 0000000..50dd201 Binary files /dev/null and b/ffmpeg.exe differ diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..6b85b8c --- /dev/null +++ b/requirements.txt @@ -0,0 +1,18 @@ +aiohappyeyeballs==2.6.1 +aiohttp==3.11.16 +aiosignal==1.3.2 +attrs==25.3.0 +certifi==2025.1.31 +cffi==1.17.1 +charset-normalizer==3.4.1 +discord.py==2.5.2 +frozenlist==1.6.0 +idna==3.10 +multidict==6.4.3 +propcache==0.3.1 +pycparser==2.22 +PyNaCl==1.5.0 +python-dotenv==1.1.0 +requests==2.32.3 +urllib3==2.4.0 +yarl==1.20.0