Turned all environment variable names in an Enum
Signed-off-by: Louis Vallat <louis@louis-vallat.xyz>
This commit is contained in:
parent
afe16f9eb1
commit
aad2f391fb
@ -12,6 +12,7 @@ import org.slf4j.LoggerFactory;
|
||||
import reactor.core.publisher.Mono;
|
||||
import xyz.vallat.louis.commands.*;
|
||||
import xyz.vallat.louis.database.DBManager;
|
||||
import xyz.vallat.louis.env.EnvironmentVariables;
|
||||
import xyz.vallat.louis.subtitles.OpenSubtitles;
|
||||
|
||||
import java.util.HashMap;
|
||||
@ -19,9 +20,6 @@ import java.util.Map;
|
||||
|
||||
public class MovieQuoteBot {
|
||||
|
||||
// TODO: MOVE TO ENUM
|
||||
public static final String DISCORD_TOKEN_ENVIRONMENT = "DISCORD_TOKEN";
|
||||
|
||||
public static final String PREFIX = "!";
|
||||
public static final String NAME = "Movies Quote Bot";
|
||||
public static final String DESCRIPTION = "I may know some quotes from some movies.";
|
||||
@ -42,7 +40,7 @@ public class MovieQuoteBot {
|
||||
DBManager.testConnection();
|
||||
DBManager.initDatabase();
|
||||
OpenSubtitles.login();
|
||||
discordLogin(System.getenv(DISCORD_TOKEN_ENVIRONMENT));
|
||||
discordLogin(System.getenv(EnvironmentVariables.DISCORD_TOKEN.getValue()));
|
||||
registerDiscordCommands();
|
||||
|
||||
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
||||
|
@ -3,6 +3,7 @@ package xyz.vallat.louis.database;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import xyz.vallat.louis.MovieQuoteBot;
|
||||
import xyz.vallat.louis.env.EnvironmentVariables;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
@ -15,19 +16,14 @@ import static xyz.vallat.louis.database.PropertyManager.initializeProperties;
|
||||
|
||||
public final class DBManager {
|
||||
|
||||
public static final String DB_USERNAME_ENVIRONMENT = "DB_USERNAME";
|
||||
public static final String DB_PASSWORD_ENVIRONMENT = "DB_PASSWORD";
|
||||
public static final String DB_PORT_ENVIRONMENT = "DB_PORT";
|
||||
public static final String DB_HOST_ENVIRONMENT = "DB_HOST";
|
||||
public static final String DB_NAME_ENVIRONMENT = "DB_NAME";
|
||||
private static final Logger logger = LoggerFactory.getLogger(MovieQuoteBot.class.getCanonicalName());
|
||||
private static final String CONNECTION_PREFIX = "postgresql";
|
||||
private static final String USERNAME = System.getenv(DB_USERNAME_ENVIRONMENT);
|
||||
private static final String PASSWORD = System.getenv(DB_PASSWORD_ENVIRONMENT);
|
||||
private static final String DATABASE = System.getenv(DB_NAME_ENVIRONMENT);
|
||||
private static final int PORT = System.getenv(DB_PORT_ENVIRONMENT) == null ? 5432 :
|
||||
Integer.parseInt(System.getenv(DB_PORT_ENVIRONMENT));
|
||||
private static final String HOST = System.getenv(DB_HOST_ENVIRONMENT);
|
||||
private static final String USERNAME = System.getenv(EnvironmentVariables.DB_USERNAME.getValue());
|
||||
private static final String PASSWORD = System.getenv(EnvironmentVariables.DB_PASSWORD.getValue());
|
||||
private static final String DATABASE = System.getenv(EnvironmentVariables.DB_NAME.getValue());
|
||||
private static final int PORT = System.getenv(EnvironmentVariables.DB_PORT.getValue()) == null ? 5432 :
|
||||
Integer.parseInt(System.getenv(EnvironmentVariables.DB_PORT.getValue()));
|
||||
private static final String HOST = System.getenv(EnvironmentVariables.DB_HOST.getValue());
|
||||
|
||||
private DBManager() {
|
||||
}
|
||||
|
28
src/main/java/xyz/vallat/louis/env/EnvironmentVariables.java
vendored
Normal file
28
src/main/java/xyz/vallat/louis/env/EnvironmentVariables.java
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
package xyz.vallat.louis.env;
|
||||
|
||||
public enum EnvironmentVariables {
|
||||
DISCORD_TOKEN("DISCORD_TOKEN"),
|
||||
DB_USERNAME("DB_USERNAME"),
|
||||
DB_PASSWORD("DB_PASSWORD"),
|
||||
DB_NAME("DB_NAME"),
|
||||
DB_HOST("DB_HOST"),
|
||||
DB_PORT("DB_PORT"),
|
||||
OS_USERNAME("OPEN_SUBTITLES_USERNAME"),
|
||||
OS_PASSWORD("OPEN_SUBTITLES_PASSWORD"),
|
||||
OS_USER_AGENT("OPEN_SUBTITLES_USER_AGENT");
|
||||
|
||||
private final String value;
|
||||
|
||||
EnvironmentVariables(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getValue();
|
||||
}
|
||||
}
|
@ -6,20 +6,18 @@ import com.github.wtekiela.opensub4j.response.*;
|
||||
import org.apache.xmlrpc.XmlRpcException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import xyz.vallat.louis.env.EnvironmentVariables;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
public final class OpenSubtitles {
|
||||
|
||||
public static final String OS_USERNAME_ENVIRONMENT = "OPEN_SUBTITLES_USERNAME";
|
||||
public static final String OS_PASSWORD_ENVIRONMENT = "OPEN_SUBTITLES_PASSWORD";
|
||||
public static final String OS_UA_ENVIRONMENT = "OPEN_SUBTITLES_USER_AGENT";
|
||||
private static final Logger logger = LoggerFactory.getLogger(OpenSubtitles.class.getCanonicalName());
|
||||
private static final String USERNAME = System.getenv(OS_USERNAME_ENVIRONMENT);
|
||||
private static final String PASSWORD = System.getenv(OS_PASSWORD_ENVIRONMENT);
|
||||
private static final String USERNAME = System.getenv(EnvironmentVariables.OS_USERNAME.getValue());
|
||||
private static final String PASSWORD = System.getenv(EnvironmentVariables.OS_PASSWORD.getValue());
|
||||
private static final String LANG = "en";
|
||||
private static final String USER_AGENT = System.getenv(OS_UA_ENVIRONMENT);
|
||||
private static final String USER_AGENT = System.getenv(EnvironmentVariables.OS_USER_AGENT.getValue());
|
||||
private static OpenSubtitlesClient client;
|
||||
|
||||
private OpenSubtitles() {
|
||||
|
Loading…
Reference in New Issue
Block a user