Added a DEFAULT_LANGUAGE System env variable

Signed-off-by: Louis Vallat <louis@louis-vallat.xyz>
This commit is contained in:
Louis Vallat 2021-05-16 00:46:35 +02:00
parent 66e93e5c57
commit eff29e9c93
3 changed files with 6 additions and 12 deletions

View File

@ -1,32 +1,26 @@
package xyz.vallat.louis.commands;
import com.github.wtekiela.opensub4j.response.SubtitleInfo;
import discord4j.common.util.Snowflake;
import discord4j.core.event.domain.message.MessageCreateEvent;
import discord4j.core.object.reaction.ReactionEmoji;
import discord4j.core.spec.EmbedCreateSpec;
import discord4j.rest.util.Color;
import org.apache.commons.cli.Options;
import org.apache.commons.lang3.RandomStringUtils;
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 xyz.vallat.louis.env.EnvironmentVariables;
import java.io.IOException;
import java.time.Instant;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public abstract class Command {
protected static final ReactionEmoji WAITING = ReactionEmoji.unicode("");
protected static final String DEFAULT_LANG = System.getenv(EnvironmentVariables.DEFAULT_LANGUAGE.getValue());
private static final Logger logger = LoggerFactory.getLogger(Command.class.getCanonicalName());
protected final String name;
protected final String description;

View File

@ -40,7 +40,7 @@ public class Download extends Command {
.addOption(Option.builder("i").longOpt("imdb").hasArg().desc("imdb identifier for the film").build())
.addOption(Option.builder("t").longOpt("title").hasArgs().numberOfArgs(Option.UNLIMITED_VALUES).desc("movie title for the film").build());
iOrT.setRequired(true);
options.addOption(Option.builder("l").longOpt("lang").hasArg().desc("specify a language (by default, english)").build());
options.addOption(Option.builder("l").longOpt("lang").hasArg().desc("specify a language (by default, " + DEFAULT_LANG + ")").build());
options.addOptionGroup(iOrT);
}
@ -54,7 +54,7 @@ public class Download extends Command {
Lang l;
if (!cmd.hasOption("l")) {
l = UserConfigManager.getDefaultLanguage(user, guild);
if (l == null) l = LanguageManager.getLangFromAny("english");
if (l == null) l = LanguageManager.getLangFromAny(DEFAULT_LANG);
} else l = LanguageManager.getLangFromAny(cmd.getOptionValue("l"));
if (l == null) return unknownLanguage(event, cmd.getOptionValue("l"));
Lang language = l;

View File

@ -44,9 +44,9 @@ public class Quote extends Command {
Snowflake user = getUser(event);
Snowflake guild = getGuild(event);
if (cmd.hasOption("l")) language = LanguageManager.getLangFromAny(cmd.getOptionValue("l"));
else language = user == null ? LanguageManager.getLangFromAny("english") :
else language = user == null ? LanguageManager.getLangFromAny(DEFAULT_LANG) :
UserConfigManager.getDefaultLanguage(user, guild);
if (language == null) language = LanguageManager.getLangFromAny("english");
if (language == null) language = LanguageManager.getLangFromAny(DEFAULT_LANG);
String imdb = cmd.hasOption("i") ? cmd.getOptionValue("i") : null;
String title = cmd.hasOption("t") ? String.join(" ", cmd.getOptionValues("t")) : null;
String search = cmd.hasOption("s") ? String.join(" ", cmd.getOptionValues("s")) : null;