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:
Louis Vallat 2020-10-26 22:06:25 +01:00
parent 672567e118
commit f692df6ce0
4 changed files with 23 additions and 16 deletions

View File

@ -34,7 +34,6 @@ public class MovieQuoteBot {
static { static {
commands.put("ping", new Ping(PREFIX + "ping")); commands.put("ping", new Ping(PREFIX + "ping"));
commands.put("version", new Version(PREFIX + "version")); commands.put("version", new Version(PREFIX + "version"));
commands.put("searchTitle", new SearchTitle(PREFIX + "searchTitle"));
commands.put("listLang", new ListLang(PREFIX + "listLang")); commands.put("listLang", new ListLang(PREFIX + "listLang"));
} }
@ -69,6 +68,7 @@ public class MovieQuoteBot {
Runtime.getRuntime().addShutdownHook(new Thread(() -> { Runtime.getRuntime().addShutdownHook(new Thread(() -> {
logger.info("Received shut down signal. Bye!"); logger.info("Received shut down signal. Bye!");
OpenSubtitles.logout();
discordClient.logout().block(); discordClient.logout().block();
})); }));

View File

@ -1,7 +1,6 @@
package xyz.vallat.louis.commands; package xyz.vallat.louis.commands;
import com.github.wtekiela.opensub4j.response.ListResponse; 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.ResponseStatus;
import com.github.wtekiela.opensub4j.response.SubtitleInfo; import com.github.wtekiela.opensub4j.response.SubtitleInfo;
import discord4j.core.event.domain.message.MessageCreateEvent; import discord4j.core.event.domain.message.MessageCreateEvent;
@ -23,15 +22,15 @@ public class ListLang extends Command {
@Override @Override
public Mono<Void> execute(MessageCreateEvent event) { public Mono<Void> execute(MessageCreateEvent event) {
String[] args = event.getMessage().getContent().split(" "); String arg = event.getMessage().getContent().substring(name.length() + 1);
if (args.length < minArgs) if (arg.replace(" ", "").length() == 0)
return notEnoughArguments(event); return notEnoughArguments(event);
return event.getMessage().getChannel() return event.getMessage().getChannel()
.flatMap(channel -> { .flatMap(channel -> {
if (OpenSubtitles.isLoggedIn()) { if (OpenSubtitles.isLoggedIn()) {
return event.getMessage().addReaction(WAITING) return event.getMessage().addReaction(WAITING)
.then(event.getMessage().getChannel().flatMap(messageChannel -> .then(event.getMessage().getChannel().flatMap(messageChannel ->
searchAndShowFilms(args[1], channel, messageChannel))) searchAndShowFilms(arg, channel, messageChannel)))
.then(event.getMessage().removeSelfReaction(WAITING)) .then(event.getMessage().removeSelfReaction(WAITING))
.then(); .then();
} else return channel.createMessage("I cannot search for subtitle languages right now. Sorry."); } else return channel.createMessage("I cannot search for subtitle languages right now. Sorry.");
@ -45,28 +44,27 @@ public class ListLang extends Command {
.then(); .then();
} }
// TODO: ADD MOVIE TITLE
private Mono<? extends Message> searchAndShowFilms(String arg, MessageChannel channel, MessageChannel messageChannel) { private Mono<? extends Message> searchAndShowFilms(String arg, MessageChannel channel, MessageChannel messageChannel) {
try { try {
ListResponse<SubtitleInfo> subtitles = OpenSubtitles.searchSubtitles("", arg); ListResponse<SubtitleInfo> subtitles = OpenSubtitles.searchSubtitles("", arg);
ListResponse<MovieInfo> movies = OpenSubtitles.searchImdb(arg);
if (subtitles.getStatus().getCode() == ResponseStatus.OK.getCode()) { if (subtitles.getStatus().getCode() == ResponseStatus.OK.getCode()) {
return messageChannel.createEmbed( return messageChannel.createEmbed(
embed -> { embed -> {
embed.setTitle("Results") embed.setTitle("Results")
.setDescription("Found " + subtitles.getData().size() + " results.") .setDescription("Found " + subtitles.getData().size() + " results.")
.setColor(Color.BISMARK); .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(); StringBuilder s = new StringBuilder();
for (SubtitleInfo info : subtitles.getData().subList(0, Math.min(10, subtitles.getData().size()))) for (SubtitleInfo info : subtitles.getData().subList(0, Math.min(10, subtitles.getData().size())))
s.append(info.getId()).append(" - ").append(info.getLanguage()).append("\n"); s.append(info.getId()).append(" - ").append(info.getLanguage()).append("\n");
embed.addField("Languages found", s.toString(), false); embed.addField("Languages found", s.toString(), false);
}); });
} else if (subtitles.getStatus().getCode() == ResponseStatus.INVALID_IMDB_ID.getCode() || } else if (subtitles.getStatus().getCode() == ResponseStatus.INVALID_PARAMETERS.getCode()) {
subtitles.getStatus().getCode() == ResponseStatus.INVALID_PARAMETERS.getCode()) return messageChannel.createMessage("It looks like it is an invalid IMDB identifier.");
return messageChannel.createMessage("It looks like this IMDB id is invalid. Try again with a valid one."); } else {
else return messageChannel.createMessage("An error happened while fetching the results. " +
return messageChannel.createMessage("An error happened while fetching the results. Try again later, or contact my administrator." + subtitles.getStatus()); "Try again later, or contact my administrator." + subtitles.getStatus());
}
} catch (XmlRpcException e) { } catch (XmlRpcException e) {
return channel.createMessage("It seems like OpenSubtitles had a stroke."); return channel.createMessage("It seems like OpenSubtitles had a stroke.");
} }

View File

@ -23,15 +23,15 @@ public class SearchTitle extends Command {
@Override @Override
public Mono<Void> execute(MessageCreateEvent event) { public Mono<Void> execute(MessageCreateEvent event) {
String[] args = event.getMessage().getContent().split(" "); String arg = event.getMessage().getContent().substring(name.length() + 1);
if (args.length < minArgs) if (arg.replace(" ", "").length() == 0)
return notEnoughArguments(event); return notEnoughArguments(event);
return event.getMessage().getChannel() return event.getMessage().getChannel()
.flatMap(channel -> { .flatMap(channel -> {
if (OpenSubtitles.isLoggedIn()) { if (OpenSubtitles.isLoggedIn()) {
return event.getMessage().addReaction(WAITING) return event.getMessage().addReaction(WAITING)
.then(event.getMessage().getChannel().flatMap(messageChannel -> .then(event.getMessage().getChannel().flatMap(messageChannel ->
searchAndShowFilms(args[1], channel, messageChannel))) searchAndShowFilms(arg, channel, messageChannel)))
.then(event.getMessage().removeSelfReaction(WAITING)) .then(event.getMessage().removeSelfReaction(WAITING))
.then(); .then();
} else return channel.createMessage("I cannot search for subtitles right now. Sorry."); } else return channel.createMessage("I cannot search for subtitles right now. Sorry.");

View File

@ -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 { public static ListResponse<MovieInfo> searchImdb(String name) throws XmlRpcException {
return client.searchMoviesOnImdb(name); return client.searchMoviesOnImdb(name);
} }