fix tmdb command errors

This commit is contained in:
Lee 2024-07-04 01:47:01 +01:00
parent dc7e44239f
commit a9e4626dfd
3 changed files with 63 additions and 31 deletions

@ -44,10 +44,8 @@ public class TMDBFeature extends Feature {
*/ */
public static EmbedBuilder pageMovie(@NonNull TMDBService tmdbService, @NonNull String query, String language, String primaryReleaseYear, String region, String year, int movie, boolean adult) { public static EmbedBuilder pageMovie(@NonNull TMDBService tmdbService, @NonNull String query, String language, String primaryReleaseYear, String region, String year, int movie, boolean adult) {
List<Movie> movieList = tmdbService.lookupMovies(query, adult, language, primaryReleaseYear, region, year); List<Movie> movieList = tmdbService.lookupMovies(query, adult, language, primaryReleaseYear, region, year);
if (movieList == null || movieList.isEmpty()) { if (movieList == null || movieList.isEmpty()) {
return EmbedUtils.errorEmbed() return null;
.setDescription("No movieList found with the provided query + options!");
} }
// Adjust movie index to stay within bounds // Adjust movie index to stay within bounds
@ -79,10 +77,8 @@ public class TMDBFeature extends Feature {
*/ */
public static EmbedBuilder pageSeries(@NonNull TMDBService tmdbService, @NonNull String query, String language, int firstAirDateYear, int year, int series, boolean adult) { public static EmbedBuilder pageSeries(@NonNull TMDBService tmdbService, @NonNull String query, String language, int firstAirDateYear, int year, int series, boolean adult) {
List<TvSeries> seriesList = tmdbService.lookupSeries(query, adult, language, firstAirDateYear, year); List<TvSeries> seriesList = tmdbService.lookupSeries(query, adult, language, firstAirDateYear, year);
if (seriesList == null || seriesList.isEmpty()) { if (seriesList == null || seriesList.isEmpty()) {
return EmbedUtils.errorEmbed() return null;
.setDescription("No series found with the provided query + options!");
} }
// Adjust series index to stay within bounds // Adjust series index to stay within bounds

@ -9,6 +9,7 @@ import cc.fascinated.bat.model.BatGuild;
import cc.fascinated.bat.model.BatUser; import cc.fascinated.bat.model.BatUser;
import cc.fascinated.bat.service.TMDBService; import cc.fascinated.bat.service.TMDBService;
import lombok.NonNull; import lombok.NonNull;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
@ -76,17 +77,26 @@ public class MovieSubCommand extends BatSubCommand implements EventListener {
userCommands.put(user.getId(), params); userCommands.put(user.getId(), params);
event.replyEmbeds(TMDBFeature.pageMovie( EmbedBuilder embedBuilder = TMDBFeature.pageMovie(
tmdbService, tmdbService,
titleOption.getAsString(), titleOption.getAsString(),
(languageOption != null ? languageOption.getAsString() : null), (languageOption != null ? languageOption.getAsString() : null),
(primaryReleaseYearOption != null ? primaryReleaseYearOption.getAsString() : null), (primaryReleaseYearOption != null ? primaryReleaseYearOption.getAsString() : null),
(regionOption != null ? regionOption.getAsString() : null), (regionOption != null ? regionOption.getAsString() : null),
(yearOption != null ? yearOption.getAsString() : null), (yearOption != null ? yearOption.getAsString() : null),
0, // Initial page number 0, // Initial page number
adult adult
).build() );
).addActionRow(
if (embedBuilder == null) {
event.replyEmbeds(EmbedUtils.errorEmbed()
.setDescription("No movies found with the given parameters!")
.build())
.queue();
return;
}
event.replyEmbeds(embedBuilder.build()).addActionRow(
Button.primary("backMovie", "Back").withEmoji(Emoji.fromFormatted("⬅️")), Button.primary("backMovie", "Back").withEmoji(Emoji.fromFormatted("⬅️")),
Button.primary("nextMovie", "Next").withEmoji(Emoji.fromFormatted("➡️")) Button.primary("nextMovie", "Next").withEmoji(Emoji.fromFormatted("➡️"))
).queue(); ).queue();
@ -120,7 +130,7 @@ public class MovieSubCommand extends BatSubCommand implements EventListener {
params.put("page", String.valueOf(currentPage)); params.put("page", String.valueOf(currentPage));
event.editMessageEmbeds(TMDBFeature.pageMovie( EmbedBuilder embedBuilder = TMDBFeature.pageMovie(
tmdbService, tmdbService,
title, title,
language, language,
@ -129,6 +139,14 @@ public class MovieSubCommand extends BatSubCommand implements EventListener {
year, year,
currentPage, currentPage,
adult adult
).build()).queue(); );
if (embedBuilder == null) {
event.replyEmbeds(EmbedUtils.errorEmbed()
.setDescription("No movies found with the given parameters!")
.build())
.queue();
return;
}
event.editMessageEmbeds(embedBuilder.build()).queue();
} }
} }

@ -9,6 +9,7 @@ import cc.fascinated.bat.model.BatGuild;
import cc.fascinated.bat.model.BatUser; import cc.fascinated.bat.model.BatUser;
import cc.fascinated.bat.service.TMDBService; import cc.fascinated.bat.service.TMDBService;
import lombok.NonNull; import lombok.NonNull;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
@ -71,17 +72,26 @@ public class SeriesSubCommand extends BatSubCommand implements EventListener {
if (yearOption != null) params.put("year", String.valueOf(yearOption.getAsInt())); if (yearOption != null) params.put("year", String.valueOf(yearOption.getAsInt()));
params.put("adult", String.valueOf(adult)); params.put("adult", String.valueOf(adult));
userCommands.put(user.getId(), params); EmbedBuilder embedBuilder = TMDBFeature.pageSeries(
tmdbService,
titleOption.getAsString(),
(languageOption != null ? languageOption.getAsString() : null),
(firstAirYearOption != null ? firstAirYearOption.getAsInt() : -1),
(yearOption != null ? yearOption.getAsInt() : -1),
0, // Initial page number
adult
);
event.replyEmbeds(TMDBFeature.pageSeries( if (embedBuilder == null) {
tmdbService, event.replyEmbeds(EmbedUtils.errorEmbed()
titleOption.getAsString(), .setDescription("No series found with the given parameters!")
(languageOption != null ? languageOption.getAsString() : null), .build())
(firstAirYearOption != null ? firstAirYearOption.getAsInt() : -1), .queue();
(yearOption != null ? yearOption.getAsInt() : -1), return;
0, // Initial page number }
adult
).build() userCommands.put(user.getId(), params);
event.replyEmbeds(embedBuilder.build()
).addActionRow( ).addActionRow(
Button.primary("backSeries", "Back").withEmoji(Emoji.fromFormatted("⬅️")), Button.primary("backSeries", "Back").withEmoji(Emoji.fromFormatted("⬅️")),
Button.primary("nextSeries", "Next").withEmoji(Emoji.fromFormatted("➡️")) Button.primary("nextSeries", "Next").withEmoji(Emoji.fromFormatted("➡️"))
@ -115,7 +125,7 @@ public class SeriesSubCommand extends BatSubCommand implements EventListener {
params.put("page", String.valueOf(currentPage)); params.put("page", String.valueOf(currentPage));
event.editMessageEmbeds(TMDBFeature.pageSeries( EmbedBuilder embedBuilder = TMDBFeature.pageSeries(
tmdbService, tmdbService,
title, title,
language, language,
@ -123,6 +133,14 @@ public class SeriesSubCommand extends BatSubCommand implements EventListener {
year, year,
currentPage, currentPage,
adult adult
).build()).queue(); );
if (embedBuilder == null) {
event.editMessageEmbeds(EmbedUtils.errorEmbed()
.setDescription("No series found with the given parameters!")
.build())
.queue();
return;
}
event.editMessageEmbeds(embedBuilder.build()).queue();
} }
} }