Moved 'createEmbedListLang' to ListLang
Signed-off-by: Louis Vallat <louis@louis-vallat.xyz>
This commit is contained in:
parent
32ee3c4ee1
commit
66e93e5c57
@ -94,39 +94,6 @@ public abstract class Command {
|
|||||||
})).then();
|
})).then();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void createEmbedListLang(String arg, EmbedCreateSpec embed, boolean isId) {
|
|
||||||
try {
|
|
||||||
Movie movie = OMDBClient.getMovie(arg, isId);
|
|
||||||
if (movie != null) {
|
|
||||||
Stream<SubtitleInfo> 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) {
|
protected String[] getArgArray(MessageCreateEvent event) {
|
||||||
return event.getMessage().getContent().substring(name.length()).split(" ");
|
return event.getMessage().getContent().substring(name.length()).split(" ");
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,21 @@
|
|||||||
package xyz.vallat.louis.commands;
|
package xyz.vallat.louis.commands;
|
||||||
|
|
||||||
|
import com.github.wtekiela.opensub4j.response.SubtitleInfo;
|
||||||
import discord4j.core.event.domain.message.MessageCreateEvent;
|
import discord4j.core.event.domain.message.MessageCreateEvent;
|
||||||
|
import discord4j.core.spec.EmbedCreateSpec;
|
||||||
import discord4j.rest.util.Color;
|
import discord4j.rest.util.Color;
|
||||||
import org.apache.commons.cli.*;
|
import org.apache.commons.cli.*;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import reactor.core.publisher.Mono;
|
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 xyz.vallat.louis.subtitles.OpenSubtitles;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
public class ListLang extends Command {
|
public class ListLang extends Command {
|
||||||
|
|
||||||
@ -50,4 +57,37 @@ public class ListLang extends Command {
|
|||||||
return parsingError(event);
|
return parsingError(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void createEmbedListLang(String arg, EmbedCreateSpec embed, boolean isId) {
|
||||||
|
try {
|
||||||
|
Movie movie = OMDBClient.getMovie(arg, isId);
|
||||||
|
if (movie != null) {
|
||||||
|
Stream<SubtitleInfo> 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.");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user