From 66e93e5c57ecef0302f00701055bb3a26b275cea Mon Sep 17 00:00:00 2001 From: Louis Vallat Date: Sun, 16 May 2021 00:41:27 +0200 Subject: [PATCH] Moved 'createEmbedListLang' to ListLang Signed-off-by: Louis Vallat --- .../xyz/vallat/louis/commands/Command.java | 33 --------------- .../xyz/vallat/louis/commands/ListLang.java | 40 +++++++++++++++++++ 2 files changed, 40 insertions(+), 33 deletions(-) diff --git a/src/main/java/xyz/vallat/louis/commands/Command.java b/src/main/java/xyz/vallat/louis/commands/Command.java index a88d856..7efbe17 100644 --- a/src/main/java/xyz/vallat/louis/commands/Command.java +++ b/src/main/java/xyz/vallat/louis/commands/Command.java @@ -94,39 +94,6 @@ public abstract class Command { })).then(); } - protected void createEmbedListLang(String arg, EmbedCreateSpec embed, boolean isId) { - try { - Movie movie = OMDBClient.getMovie(arg, isId); - if (movie != null) { - Stream subtitles = OpenSubtitles.getSubtitleStreamFromMovie(movie); - if (subtitles != null) { - embed.setColor(Color.MEDIUM_SEA_GREEN); - String formattedSubtitles = subtitles.limit(20).map(SubtitleInfo::getLanguage) - .collect(Collectors.joining("\n")); - embed.setDescription("You requested a list of the languages available for a movie with the " + - (isId ? "IMDB Identifier" : "title") + " '" + arg + "'. "); - embed.addField("Movie", movie.toString(), true); - embed.addField("IMDB Link", "https://www.imdb.com/title/" + movie.getImdbID(), true); - if (movie.getPoster() != null) embed.setThumbnail(movie.getPoster()); - embed.addField("Top 20 distinct languages (based on downloads)", - formattedSubtitles.isBlank() ? "None." : formattedSubtitles, false); - } else { - embed.setDescription("We couldn't find any subtitle right now. Sorry. Try again later or contact my" + - " administrator, please!"); - } - } else { - embed.setDescription("I didn't find any correspondence, sorry! If you know this is an error, please " + - "contact my administrator!"); - } - } catch (IOException e) { - logger.error("A network error happened: {}", e.getMessage()); - logger.warn("It may be due to a website being down. If it's not" + - "the case, please fix this issue quickly."); - embed.setDescription("An error occurred. " + - "Try again later or contact my administrator."); - } - } - protected String[] getArgArray(MessageCreateEvent event) { return event.getMessage().getContent().substring(name.length()).split(" "); } diff --git a/src/main/java/xyz/vallat/louis/commands/ListLang.java b/src/main/java/xyz/vallat/louis/commands/ListLang.java index ed0406a..8de3327 100644 --- a/src/main/java/xyz/vallat/louis/commands/ListLang.java +++ b/src/main/java/xyz/vallat/louis/commands/ListLang.java @@ -1,14 +1,21 @@ package xyz.vallat.louis.commands; +import com.github.wtekiela.opensub4j.response.SubtitleInfo; import discord4j.core.event.domain.message.MessageCreateEvent; +import discord4j.core.spec.EmbedCreateSpec; import discord4j.rest.util.Color; import org.apache.commons.cli.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import reactor.core.publisher.Mono; +import xyz.vallat.louis.omdb.OMDBClient; +import xyz.vallat.louis.omdb.objects.Movie; import xyz.vallat.louis.subtitles.OpenSubtitles; +import java.io.IOException; import java.time.Instant; +import java.util.stream.Collectors; +import java.util.stream.Stream; public class ListLang extends Command { @@ -50,4 +57,37 @@ public class ListLang extends Command { return parsingError(event); } } + + private void createEmbedListLang(String arg, EmbedCreateSpec embed, boolean isId) { + try { + Movie movie = OMDBClient.getMovie(arg, isId); + if (movie != null) { + Stream subtitles = OpenSubtitles.getSubtitleStreamFromMovie(movie); + if (subtitles != null) { + embed.setColor(Color.MEDIUM_SEA_GREEN); + String formattedSubtitles = subtitles.limit(20).map(SubtitleInfo::getLanguage) + .collect(Collectors.joining("\n")); + embed.setDescription("You requested a list of the languages available for a movie with the " + + (isId ? "IMDB Identifier" : "title") + " '" + arg + "'. "); + embed.addField("Movie", movie.toString(), true); + embed.addField("IMDB Link", "https://www.imdb.com/title/" + movie.getImdbID(), true); + if (movie.getPoster() != null) embed.setThumbnail(movie.getPoster()); + embed.addField("Top 20 distinct languages (based on downloads)", + formattedSubtitles.isBlank() ? "None." : formattedSubtitles, false); + } else { + embed.setDescription("We couldn't find any subtitle right now. Sorry. Try again later or contact my" + + " administrator, please!"); + } + } else { + embed.setDescription("I didn't find any correspondence, sorry! If you know this is an error, please " + + "contact my administrator!"); + } + } catch (IOException e) { + logger.error("A network error happened: {}", e.getMessage()); + logger.warn("It may be due to a website being down. If it's not" + + "the case, please fix this issue quickly."); + embed.setDescription("An error occurred. " + + "Try again later or contact my administrator."); + } + } }