From eff29e9c93d25819393f1d9839c6256a3911d7c4 Mon Sep 17 00:00:00 2001 From: Louis Vallat Date: Sun, 16 May 2021 00:46:35 +0200 Subject: [PATCH] Added a DEFAULT_LANGUAGE System env variable Signed-off-by: Louis Vallat --- src/main/java/xyz/vallat/louis/commands/Command.java | 10 ++-------- src/main/java/xyz/vallat/louis/commands/Download.java | 4 ++-- src/main/java/xyz/vallat/louis/commands/Quote.java | 4 ++-- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/main/java/xyz/vallat/louis/commands/Command.java b/src/main/java/xyz/vallat/louis/commands/Command.java index 7efbe17..92e7b4c 100644 --- a/src/main/java/xyz/vallat/louis/commands/Command.java +++ b/src/main/java/xyz/vallat/louis/commands/Command.java @@ -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; diff --git a/src/main/java/xyz/vallat/louis/commands/Download.java b/src/main/java/xyz/vallat/louis/commands/Download.java index 52d5062..6907948 100644 --- a/src/main/java/xyz/vallat/louis/commands/Download.java +++ b/src/main/java/xyz/vallat/louis/commands/Download.java @@ -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; diff --git a/src/main/java/xyz/vallat/louis/commands/Quote.java b/src/main/java/xyz/vallat/louis/commands/Quote.java index 8b9227c..0653dd6 100644 --- a/src/main/java/xyz/vallat/louis/commands/Quote.java +++ b/src/main/java/xyz/vallat/louis/commands/Quote.java @@ -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;