Removed support for command line arguments are there are too many arguments to manage. Fixed small typo in DBManager
Signed-off-by: Louis Vallat <louis@louis-vallat.xyz>
This commit is contained in:
parent
66de95c0df
commit
ee08b6b29c
@ -11,6 +11,7 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
import xyz.vallat.louis.commands.*;
|
import xyz.vallat.louis.commands.*;
|
||||||
|
import xyz.vallat.louis.database.DBManager;
|
||||||
import xyz.vallat.louis.subtitles.OpenSubtitles;
|
import xyz.vallat.louis.subtitles.OpenSubtitles;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -18,10 +19,12 @@ import java.util.Map;
|
|||||||
|
|
||||||
public class MovieQuoteBot {
|
public class MovieQuoteBot {
|
||||||
|
|
||||||
|
// TODO: MOVE TO ENUM
|
||||||
public static final String DISCORD_TOKEN_ENVIRONMENT = "DISCORD_TOKEN";
|
public static final String DISCORD_TOKEN_ENVIRONMENT = "DISCORD_TOKEN";
|
||||||
public static final String OS_USERNAME_ENVIRONMENT = "OPEN_SUBTITLES_USERNAME";
|
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_PASSWORD_ENVIRONMENT = "OPEN_SUBTITLES_PASSWORD";
|
||||||
public static final String OS_UA_ENVIRONMENT = "OPEN_SUBTITLES_USER_AGENT";
|
public static final String OS_UA_ENVIRONMENT = "OPEN_SUBTITLES_USER_AGENT";
|
||||||
|
|
||||||
public static final String PREFIX = "!";
|
public static final String PREFIX = "!";
|
||||||
public static final String NAME = "Movies Quote Bot";
|
public static final String NAME = "Movies Quote Bot";
|
||||||
public static final String DESCRIPTION = "I may know some quotes from some movies.";
|
public static final String DESCRIPTION = "I may know some quotes from some movies.";
|
||||||
@ -39,33 +42,15 @@ public class MovieQuoteBot {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
if ((System.getenv(DISCORD_TOKEN_ENVIRONMENT) == null ||
|
DBManager.testConnection();
|
||||||
System.getenv(OS_USERNAME_ENVIRONMENT) == null ||
|
|
||||||
System.getenv(OS_PASSWORD_ENVIRONMENT) == null ||
|
|
||||||
System.getenv(OS_UA_ENVIRONMENT) == null
|
|
||||||
) && args.length < 4) {
|
|
||||||
logger.error("Missing tokens. Exiting.");
|
|
||||||
System.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
String discordToken = System.getenv(DISCORD_TOKEN_ENVIRONMENT) == null ?
|
|
||||||
args[0] :
|
|
||||||
System.getenv(DISCORD_TOKEN_ENVIRONMENT);
|
|
||||||
|
|
||||||
// TODO: FIX CRASH ON LOGIN IF OS IS IN MAINTENANCE OR BROKEN
|
// TODO: FIX CRASH ON LOGIN IF OS IS IN MAINTENANCE OR BROKEN
|
||||||
OpenSubtitles.login(
|
OpenSubtitles.login(
|
||||||
System.getenv(OS_USERNAME_ENVIRONMENT) == null ?
|
System.getenv(OS_USERNAME_ENVIRONMENT),
|
||||||
args[1] :
|
System.getenv(OS_PASSWORD_ENVIRONMENT),
|
||||||
System.getenv(OS_USERNAME_ENVIRONMENT),
|
|
||||||
System.getenv(OS_PASSWORD_ENVIRONMENT) == null ?
|
|
||||||
args[2] :
|
|
||||||
System.getenv(OS_PASSWORD_ENVIRONMENT),
|
|
||||||
"en",
|
"en",
|
||||||
System.getenv(OS_UA_ENVIRONMENT) == null ?
|
System.getenv(OS_UA_ENVIRONMENT)
|
||||||
args[3] :
|
|
||||||
System.getenv(OS_UA_ENVIRONMENT)
|
|
||||||
);
|
);
|
||||||
discordLogin(discordToken);
|
discordLogin(System.getenv(DISCORD_TOKEN_ENVIRONMENT));
|
||||||
registerDiscordCommands();
|
registerDiscordCommands();
|
||||||
|
|
||||||
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
||||||
|
@ -11,37 +11,30 @@ import java.sql.Statement;
|
|||||||
|
|
||||||
public final class DBManager {
|
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 Logger logger = LoggerFactory.getLogger(MovieQuoteBot.class.getCanonicalName());
|
||||||
private static final String DRIVER_CLASS = "org.posgresql.Driver";
|
private static final String DRIVER_CLASS = "org.postgresql.Driver";
|
||||||
private static final String CONNECTION_PREFIX = "postgresql";
|
private static final String CONNECTION_PREFIX = "postgresql";
|
||||||
|
private static final String USERNAME = System.getenv(DB_USERNAME_ENVIRONMENT);
|
||||||
private static String username;
|
private static final String PASSWORD = System.getenv(DB_PASSWORD_ENVIRONMENT);
|
||||||
private static String password;
|
private static final String DATABASE = System.getenv(DB_NAME_ENVIRONMENT);
|
||||||
private static String database;
|
private static final int PORT = System.getenv(DB_PORT_ENVIRONMENT) == null ? 5432 :
|
||||||
private static int port = 5432;
|
Integer.parseInt(System.getenv(DB_PORT_ENVIRONMENT));
|
||||||
private static String host;
|
private static final String HOST = System.getenv(DB_HOST_ENVIRONMENT);
|
||||||
|
|
||||||
private DBManager() {
|
private DBManager() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setLoginInformation(String host, String database, String username, String password) {
|
|
||||||
DBManager.host = host;
|
|
||||||
DBManager.database = database;
|
|
||||||
DBManager.username = username;
|
|
||||||
DBManager.password = password;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setLoginInformation(String host, int port, String database, String username, String password) {
|
|
||||||
DBManager.port = port;
|
|
||||||
setLoginInformation(host, database, username, password);
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: EXIT CODES AS ENUM
|
// TODO: EXIT CODES AS ENUM
|
||||||
private static Connection getConnection() {
|
private static Connection getConnection() {
|
||||||
try {
|
try {
|
||||||
Class.forName(DRIVER_CLASS);
|
Class.forName(DRIVER_CLASS);
|
||||||
return DriverManager.getConnection("jdbc:" + CONNECTION_PREFIX + "://" + host + ":" + port + "/"
|
return DriverManager.getConnection("jdbc:" + CONNECTION_PREFIX + "://" + HOST + ":" + PORT + "/"
|
||||||
+ database, username, password);
|
+ DATABASE, USERNAME, PASSWORD);
|
||||||
} catch (ClassNotFoundException | SQLException e) {
|
} catch (ClassNotFoundException | SQLException e) {
|
||||||
logger.error("Could not connect to database. Reason: {}.", e.getMessage());
|
logger.error("Could not connect to database. Reason: {}.", e.getMessage());
|
||||||
System.exit(4);
|
System.exit(4);
|
||||||
|
Loading…
Reference in New Issue
Block a user