Working version
This commit is contained in:
38
bot/main.py
38
bot/main.py
@ -29,33 +29,39 @@ async def recommend(interaction: discord.Interaction, username: str, media_type:
|
||||
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())
|
||||
# Print cached Plex titles for this media_type
|
||||
print(f"🗂️ Cached Plex {media_type}s:")
|
||||
for item in recommender.cache.data:
|
||||
if item["type"] == media_type.lower():
|
||||
print(f"- {item['title']}")
|
||||
|
||||
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."
|
||||
results = recommender.recommend(watched_titles, media_type=media_type.lower())
|
||||
available = results["available"]
|
||||
requestable = results["requestable"]
|
||||
|
||||
def format_recs(title_list):
|
||||
return "\n".join(f"• {title}" for title in title_list)
|
||||
|
||||
# Final Discord message
|
||||
response = (
|
||||
f"🎬 **Recommendations for `{username}` ({media_type}s)**\n\n"
|
||||
f"**✅ Available on Plex:**\n"
|
||||
f"{format_recs(available) or 'None found.'}\n\n"
|
||||
f"**🛒 Requestable:**\n"
|
||||
f"{format_recs(requestable) or 'None found.'}"
|
||||
)
|
||||
|
||||
await interaction.followup.send(response)
|
||||
|
||||
except Exception as e:
|
||||
await interaction.followup.send(f"❌ Error: {str(e)}")
|
||||
print("Error in /recommend:", e)
|
||||
await interaction.followup.send(f"❌ An error occurred while generating recommendations: {e}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
client.run(DISCORD_BOT_TOKEN)
|
||||
|
Reference in New Issue
Block a user