Skip to content
This repository was archived by the owner on Jan 6, 2024. It is now read-only.

Commit 423f8b7

Browse files
committed
Prevent crashing when display tv show/movie details
1 parent 48601e8 commit 423f8b7

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

Requestrr.WebApi/RequestrrBot/ChatClients/Discord/DiscordMovieRequestingWorkFlow.cs

+7-3
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public async Task<MovieSelection> GetMovieSelectionAsync(IReadOnlyList<Movie> mo
8181
var movieRow = new StringBuilder();
8282
movieRow.Append($"{i + 1}) {arrayMovies[i].Title} ");
8383

84-
if (!string.IsNullOrWhiteSpace(arrayMovies[i].ReleaseDate))
84+
if (!string.IsNullOrWhiteSpace(arrayMovies[i].ReleaseDate) && arrayMovies[i].ReleaseDate.Length >= 4)
8585
movieRow.Append($"({arrayMovies[i].ReleaseDate.Substring(0, 4)}) ");
8686

8787
movieRow.Append($"[[TheMovieDb](https://www.themoviedb.org/movie/{arrayMovies[i].TheMovieDbId})]");
@@ -147,13 +147,17 @@ public async Task DisplayMovieDetails(Movie movie)
147147
public static async Task<Embed> GenerateMovieDetailsAsync(Movie movie, SocketUser user, IMovieSearcher movieSearcher = null)
148148
{
149149
var embedBuilder = new EmbedBuilder()
150-
.WithTitle($"{movie.Title} {(!string.IsNullOrWhiteSpace(movie.ReleaseDate) ? $"({movie.ReleaseDate.Split("T")[0].Substring(0, 4)})" : string.Empty)}")
151-
.WithDescription(movie.Overview.Substring(0, Math.Min(movie.Overview.Length, 255)) + "(...)")
150+
.WithTitle($"{movie.Title} {(!string.IsNullOrWhiteSpace(movie.ReleaseDate) && movie.ReleaseDate.Length >= 4 ? $"({movie.ReleaseDate.Split("T")[0].Substring(0, 4)})" : string.Empty)}")
152151
.WithFooter(user.Username, $"https://cdn.discordapp.com/avatars/{user.Id.ToString()}/{user.AvatarId}.png")
153152
.WithTimestamp(DateTime.Now)
154153
.WithUrl($"https://www.themoviedb.org/movie/{movie.TheMovieDbId}")
155154
.WithThumbnailUrl("https://i.imgur.com/44ueTES.png");
156155

156+
if(!string.IsNullOrWhiteSpace(movie.Overview))
157+
{
158+
embedBuilder.WithDescription(movie.Overview.Substring(0, Math.Min(movie.Overview.Length, 255)) + "(...)");
159+
}
160+
157161
if (!string.IsNullOrEmpty(movie.PosterPath) && movie.PosterPath.StartsWith("http", StringComparison.InvariantCultureIgnoreCase)) embedBuilder.WithImageUrl(movie.PosterPath);
158162
if (!string.IsNullOrWhiteSpace(movie.Quality)) embedBuilder.AddField("__Quality__", $"{movie.Quality}p", true);
159163
if (!string.IsNullOrWhiteSpace(movie.PlexUrl)) embedBuilder.AddField("__Plex__", $"[Watch now]({movie.PlexUrl})", true);

Requestrr.WebApi/RequestrrBot/ChatClients/Discord/DiscordTvShowsRequestingWorkFlow.cs

+10-3
Original file line numberDiff line numberDiff line change
@@ -147,19 +147,26 @@ public static Embed GenerateTvShowDetailsAsync(TvShow tvShow, SocketUser user)
147147
{
148148
var title = tvShow.Title;
149149

150-
if (!string.IsNullOrWhiteSpace(tvShow.FirstAired) && !title.Contains(tvShow.FirstAired.Split("T")[0].Substring(0, 4)))
150+
if (!string.IsNullOrWhiteSpace(tvShow.FirstAired))
151151
{
152-
title = $"{title} ({tvShow.FirstAired.Split("T")[0].Substring(0, 4)})";
152+
if(tvShow.FirstAired.Length >= 4 && !title.Contains(tvShow.FirstAired.Split("T")[0].Substring(0, 4)))
153+
{
154+
title = $"{title} ({tvShow.FirstAired.Split("T")[0].Substring(0, 4)})";
155+
}
153156
}
154157

155158
var embedBuilder = new EmbedBuilder()
156159
.WithTitle(title)
157-
.WithDescription(tvShow.Overview.Substring(0, Math.Min(tvShow.Overview.Length, 255)) + "(...)")
158160
.WithFooter(user.Username, $"https://cdn.discordapp.com/avatars/{user.Id}/{user.AvatarId}.png")
159161
.WithTimestamp(DateTime.Now)
160162
.WithUrl($"https://www.thetvdb.com/?id={tvShow.TheTvDbId}&tab=series")
161163
.WithThumbnailUrl("https://thetvdb.com/images/logo.png");
162164

165+
if(!string.IsNullOrWhiteSpace(tvShow.Overview))
166+
{
167+
embedBuilder.WithDescription(tvShow.Overview.Substring(0, Math.Min(tvShow.Overview.Length, 255)) + "(...)");
168+
}
169+
163170
if (!string.IsNullOrEmpty(tvShow.Banner) && tvShow.Banner.StartsWith("http", StringComparison.InvariantCultureIgnoreCase)) embedBuilder.WithImageUrl(tvShow.Banner);
164171
if (!string.IsNullOrWhiteSpace(tvShow.Network)) embedBuilder.AddField("__Network__", tvShow.Network, true);
165172
if (!string.IsNullOrWhiteSpace(tvShow.Status)) embedBuilder.AddField("__Status__", tvShow.Status, true);

0 commit comments

Comments
 (0)