Initial working version

This commit is contained in:
2025-05-29 15:04:36 -04:00
parent 7206661877
commit e991862a01
10 changed files with 406 additions and 0 deletions

61
bot/main.py Normal file
View File

@ -0,0 +1,61 @@
# bot/main.py
import discord
from discord.ext import commands
from discord import app_commands
from tautulli_client import TautulliClient
from recommender import Recommender
from config import DISCORD_BOT_TOKEN
intents = discord.Intents.default()
client = commands.Bot(command_prefix="!", intents=intents)
tree = client.tree
tautulli = TautulliClient()
recommender = Recommender()
@client.event
async def on_ready():
print(f"🤖 Logged in as {client.user} (ID: {client.user.id})")
await tree.sync()
print("✅ Slash commands synced.")
@tree.command(name="recommend", description="Recommend movies or TV shows for a Plex user")
@app_commands.describe(
username="Plex username (case-sensitive)",
media_type="Choose 'movie' or 'tv'"
)
async def recommend(interaction: discord.Interaction, username: str, media_type: str):
await interaction.response.defer() # Acknowledge the request
try:
#users = tautulli._request("get_users")
#print("👤 Tautulli Users:")
#for u in users:
# print(f"{u.get('username')}")
# Convert Discord input to Plex-friendly type
history = tautulli.get_user_watch_history(username=username, media_type=media_type.lower())
if not history:
await interaction.followup.send(f"⚠️ No recent {media_type} history found for `{username}`.")
return
watched_titles = [entry["title"] for entry in history]
result = recommender.recommend(watched_titles, media_type=media_type.lower())
response = f"🎬 **{media_type.title()} Recommendations for `{username}`:**\n\n"
if result["available"]:
response += "✅ **Available on Plex:**\n" + "\n".join(f"- {title}" for title in result["available"]) + "\n\n"
if result["requestable"]:
response += "🛒 **Requestable:**\n" + "\n".join(f"- {title}" for title in result["requestable"])
if not result["available"] and not result["requestable"]:
response += "❌ No recommendations found."
await interaction.followup.send(response)
except Exception as e:
await interaction.followup.send(f"❌ Error: {str(e)}")
print("Error in /recommend:", e)
if __name__ == "__main__":
client.run(DISCORD_BOT_TOKEN)