Removed the search title feature as it is broken right now
Signed-off-by: Louis Vallat <louis@louis-vallat.xyz>
This commit is contained in:
parent
672567e118
commit
f692df6ce0
@ -34,7 +34,6 @@ public class MovieQuoteBot {
|
||||
static {
|
||||
commands.put("ping", new Ping(PREFIX + "ping"));
|
||||
commands.put("version", new Version(PREFIX + "version"));
|
||||
commands.put("searchTitle", new SearchTitle(PREFIX + "searchTitle"));
|
||||
commands.put("listLang", new ListLang(PREFIX + "listLang"));
|
||||
}
|
||||
|
||||
@ -69,6 +68,7 @@ public class MovieQuoteBot {
|
||||
|
||||
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
||||
logger.info("Received shut down signal. Bye!");
|
||||
OpenSubtitles.logout();
|
||||
discordClient.logout().block();
|
||||
}));
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
package xyz.vallat.louis.commands;
|
||||
|
||||
import com.github.wtekiela.opensub4j.response.ListResponse;
|
||||
import com.github.wtekiela.opensub4j.response.MovieInfo;
|
||||
import com.github.wtekiela.opensub4j.response.ResponseStatus;
|
||||
import com.github.wtekiela.opensub4j.response.SubtitleInfo;
|
||||
import discord4j.core.event.domain.message.MessageCreateEvent;
|
||||
@ -23,15 +22,15 @@ public class ListLang extends Command {
|
||||
|
||||
@Override
|
||||
public Mono<Void> execute(MessageCreateEvent event) {
|
||||
String[] args = event.getMessage().getContent().split(" ");
|
||||
if (args.length < minArgs)
|
||||
String arg = event.getMessage().getContent().substring(name.length() + 1);
|
||||
if (arg.replace(" ", "").length() == 0)
|
||||
return notEnoughArguments(event);
|
||||
return event.getMessage().getChannel()
|
||||
.flatMap(channel -> {
|
||||
if (OpenSubtitles.isLoggedIn()) {
|
||||
return event.getMessage().addReaction(WAITING)
|
||||
.then(event.getMessage().getChannel().flatMap(messageChannel ->
|
||||
searchAndShowFilms(args[1], channel, messageChannel)))
|
||||
searchAndShowFilms(arg, channel, messageChannel)))
|
||||
.then(event.getMessage().removeSelfReaction(WAITING))
|
||||
.then();
|
||||
} else return channel.createMessage("I cannot search for subtitle languages right now. Sorry.");
|
||||
@ -45,28 +44,27 @@ public class ListLang extends Command {
|
||||
.then();
|
||||
}
|
||||
|
||||
// TODO: ADD MOVIE TITLE
|
||||
private Mono<? extends Message> searchAndShowFilms(String arg, MessageChannel channel, MessageChannel messageChannel) {
|
||||
try {
|
||||
ListResponse<SubtitleInfo> subtitles = OpenSubtitles.searchSubtitles("", arg);
|
||||
ListResponse<MovieInfo> movies = OpenSubtitles.searchImdb(arg);
|
||||
if (subtitles.getStatus().getCode() == ResponseStatus.OK.getCode()) {
|
||||
return messageChannel.createEmbed(
|
||||
embed -> {
|
||||
embed.setTitle("Results")
|
||||
.setDescription("Found " + subtitles.getData().size() + " results.")
|
||||
.setColor(Color.BISMARK);
|
||||
if (movies.getStatus().getCode() == ResponseStatus.OK.getCode() && !movies.getData().isEmpty())
|
||||
embed.addField("Title", movies.getData().get(0).getTitle(), false);
|
||||
StringBuilder s = new StringBuilder();
|
||||
for (SubtitleInfo info : subtitles.getData().subList(0, Math.min(10, subtitles.getData().size())))
|
||||
s.append(info.getId()).append(" - ").append(info.getLanguage()).append("\n");
|
||||
embed.addField("Languages found", s.toString(), false);
|
||||
});
|
||||
} else if (subtitles.getStatus().getCode() == ResponseStatus.INVALID_IMDB_ID.getCode() ||
|
||||
subtitles.getStatus().getCode() == ResponseStatus.INVALID_PARAMETERS.getCode())
|
||||
return messageChannel.createMessage("It looks like this IMDB id is invalid. Try again with a valid one.");
|
||||
else
|
||||
return messageChannel.createMessage("An error happened while fetching the results. Try again later, or contact my administrator." + subtitles.getStatus());
|
||||
} else if (subtitles.getStatus().getCode() == ResponseStatus.INVALID_PARAMETERS.getCode()) {
|
||||
return messageChannel.createMessage("It looks like it is an invalid IMDB identifier.");
|
||||
} else {
|
||||
return messageChannel.createMessage("An error happened while fetching the results. " +
|
||||
"Try again later, or contact my administrator." + subtitles.getStatus());
|
||||
}
|
||||
} catch (XmlRpcException e) {
|
||||
return channel.createMessage("It seems like OpenSubtitles had a stroke.");
|
||||
}
|
||||
|
@ -23,15 +23,15 @@ public class SearchTitle extends Command {
|
||||
|
||||
@Override
|
||||
public Mono<Void> execute(MessageCreateEvent event) {
|
||||
String[] args = event.getMessage().getContent().split(" ");
|
||||
if (args.length < minArgs)
|
||||
String arg = event.getMessage().getContent().substring(name.length() + 1);
|
||||
if (arg.replace(" ", "").length() == 0)
|
||||
return notEnoughArguments(event);
|
||||
return event.getMessage().getChannel()
|
||||
.flatMap(channel -> {
|
||||
if (OpenSubtitles.isLoggedIn()) {
|
||||
return event.getMessage().addReaction(WAITING)
|
||||
.then(event.getMessage().getChannel().flatMap(messageChannel ->
|
||||
searchAndShowFilms(args[1], channel, messageChannel)))
|
||||
searchAndShowFilms(arg, channel, messageChannel)))
|
||||
.then(event.getMessage().removeSelfReaction(WAITING))
|
||||
.then();
|
||||
} else return channel.createMessage("I cannot search for subtitles right now. Sorry.");
|
||||
|
@ -49,6 +49,15 @@ public final class OpenSubtitles {
|
||||
}
|
||||
}
|
||||
|
||||
public static void logout() {
|
||||
try {
|
||||
client.logout();
|
||||
} catch (XmlRpcException e) {
|
||||
logger.error("Could not log out. Skipping.");
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: NUKE THAT FUNCTION AND REPLACE IT WITH OMDB IMPLEMENTATION
|
||||
public static ListResponse<MovieInfo> searchImdb(String name) throws XmlRpcException {
|
||||
return client.searchMoviesOnImdb(name);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user