From 8aa556384765f91fb78668266928e61551e1d6cd Mon Sep 17 00:00:00 2001 From: sevi-kun Date: Sun, 25 May 2025 16:51:17 +0200 Subject: [PATCH] Improving request command handeling --- commands.py | 98 ++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 89 insertions(+), 9 deletions(-) diff --git a/commands.py b/commands.py index 3afcf67..a49e81d 100644 --- a/commands.py +++ b/commands.py @@ -137,8 +137,32 @@ class MediaCommands(commands.Cog): status_str = status_map.get(status, "Unknown") embed.add_field(name="Status", value=status_str, inline=True) - # Add request button info - if not media_info or media_info.get('status') < 5: + # Add request button info or status + if not media_info: + embed.add_field( + name="Request this Movie", + value=f"Use `{config.BOT_PREFIX}request movie {media_id}` to request this movie", + inline=False + ) + elif media_info.get('status') == 5: # Available + embed.add_field( + name="Status", + value="✅ This movie is available in your library", + inline=False + ) + elif media_info.get('status') == 3: # Processing + embed.add_field( + name="Status", + value="⏳ This movie is being processed", + inline=False + ) + elif media_info.get('status') == 2: # Pending + embed.add_field( + name="Status", + value="⏳ This movie has been requested and is pending", + inline=False + ) + elif media_info.get('status') < 5: embed.add_field( name="Request this Movie", value=f"Use `{config.BOT_PREFIX}request movie {media_id}` to request this movie", @@ -230,8 +254,44 @@ class MediaCommands(commands.Cog): inline=False ) - # Add request button info - if not media_info or media_info.get('status') < 5: + # Add request button info or status + if not media_info: + embed.add_field( + name="Request this Show", + value=f"Use `{config.BOT_PREFIX}request tv {media_id}` to request all seasons or\n" + f"`{config.BOT_PREFIX}request tv {media_id} ` for specific seasons", + inline=False + ) + elif media_info.get('status') == 5: # Available + embed.add_field( + name="Status", + value="✅ This TV show is available in your library", + inline=False + ) + elif media_info.get('status') == 4: # Partially Available + embed.add_field( + name="Status", + value="⚠️ This TV show is partially available. You may want to request specific seasons.", + inline=False + ) + embed.add_field( + name="Request Specific Seasons", + value=f"Use `{config.BOT_PREFIX}request tv {media_id} ` to request specific seasons", + inline=False + ) + elif media_info.get('status') == 3: # Processing + embed.add_field( + name="Status", + value="⏳ This TV show is being processed", + inline=False + ) + elif media_info.get('status') == 2: # Pending + embed.add_field( + name="Status", + value="⏳ This TV show has been requested and is pending", + inline=False + ) + elif media_info.get('status') < 5: embed.add_field( name="Request this Show", value=f"Use `{config.BOT_PREFIX}request tv {media_id}` to request all seasons or\n" @@ -486,6 +546,22 @@ class RequestCommands(commands.Cog): await ctx.send(f"Could not retrieve details for {media_type} with ID {media_id}. Please check the ID and try again.") return + # Check if media is already available + if media_details.get('mediaInfo'): + status = media_details.get('mediaInfo', {}).get('status') + if status == 5: # 5 = Available + await ctx.send(f"**{title}** is already available in your library! No need to request it.") + return + elif status == 4: # 4 = Partially Available (for TV shows) + if media_type.lower() == 'tv': + await ctx.send(f"**{title}** is partially available in your library. You might want to request specific seasons instead.") + elif status == 3: # 3 = Processing + await ctx.send(f"**{title}** is currently being processed. Please wait for it to become available.") + return + elif status == 2: # 2 = Pending + await ctx.send(f"**{title}** has already been requested and is pending approval or processing.") + return + # Create the request request_data = { 'media_type': media_type.lower(), @@ -541,14 +617,18 @@ class RequestCommands(commands.Cog): error_message = str(e) if "500" in error_message: - await ctx.send(f"Error creating request: Server error (500). This could be because:\n" - f"1. You might not have permission to request this media\n" - f"2. The media ID doesn't exist or is invalid\n" - f"3. The media may already be requested or available\n\n" - f"Try searching for the media first with `{config.BOT_PREFIX}search` to get a valid ID") + if "Request already exists" in error_message: + await ctx.send(f"This media has already been requested and is either pending or being processed.") + else: + await ctx.send(f"Error creating request: Server error (500). This could be because:\n" + f"1. You might not have permission to request this media\n" + f"2. The media ID doesn't exist or is invalid\n" + f"3. The media may already be requested or available\n\n" + f"Try using `{config.BOT_PREFIX}info {media_id}` to check the current status") elif "401" in error_message or "403" in error_message: await ctx.send(f"Error creating request: Authentication error. The bot account may not have permission to make requests.") else: + await ctx.send(f"Error creating request: {str(e)}") # Provide more specific error messages for common issues if "already exists" in str(e).lower(): await ctx.send(f"This media has already been requested or is already available in your library.")