Finish implementing configuration file
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Configuration file is now fully functional. Startup arguments for bot token and heartbeat key have now been removed.
This commit is contained in:
@@ -29,27 +29,29 @@ import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class HidekoBot
|
||||
{
|
||||
private static String botToken;
|
||||
|
||||
private static JDA jda;
|
||||
|
||||
|
||||
// create a logger instance for ease of use
|
||||
private static final Logger logger = new Logger(HidekoBot.class);
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
|
||||
// check if bot token was specified as a startup argument
|
||||
if(args.length < 1)
|
||||
// load configuration
|
||||
logger.log("Loading configuration...");
|
||||
String configFilePath = Cache.getExecPath() + File.separator + "config.yml";
|
||||
ConfigurationManager configurationManager = new ConfigurationManager(configFilePath);
|
||||
configurationManager.initConfig();
|
||||
Cache.setConfigManager(configurationManager);
|
||||
logger.log("Configuration loaded!");
|
||||
|
||||
String botToken = Cache.getBotToken();
|
||||
if(botToken == null || botToken.isEmpty())
|
||||
{
|
||||
logger.log("Please specify your bot token!");
|
||||
logger.log("Invalid bot token!");
|
||||
shutdown();
|
||||
return;
|
||||
}
|
||||
|
||||
// load token from args
|
||||
botToken = args[0];
|
||||
|
||||
try
|
||||
{
|
||||
// try to create the bot object and authenticate it with discord.
|
||||
@@ -79,19 +81,18 @@ public class HidekoBot
|
||||
// if there is more than 1 arg, then iterate through them because we have additional things to do.
|
||||
// we are doing this at the end because we might need the API to be already initialized for some things.
|
||||
if(args.length > 1) {
|
||||
List<String> argsList = new ArrayList<>(Arrays.asList(args).subList(1, args.length));
|
||||
List<String> argsList = new ArrayList<>(Arrays.asList(args));
|
||||
|
||||
|
||||
// NOTE: do not replace with enhanced for, since we might need
|
||||
// to know what position we're at or do further elaboration of the string.
|
||||
// we were using this for api key parsing in the past.
|
||||
for(int i = 0; i < argsList.size(); i++)
|
||||
{
|
||||
String arg = argsList.get(i);
|
||||
|
||||
if(arg.equals("verbose")) Cache.setVerbose(true);
|
||||
if(arg.equals("refresh")) forceUpdateCommands = true;
|
||||
if(arg.startsWith("heartbeat="))
|
||||
{
|
||||
String apiKey = arg.replaceAll(".*=", ""); //remove the "heartbeat=" part
|
||||
Cache.setHeartBeatApiKey(apiKey);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -111,13 +112,6 @@ public class HidekoBot
|
||||
jda.getPresence().setStatus(OnlineStatus.ONLINE);
|
||||
jda.getPresence().setActivity(Activity.playing("Hatsune Miku: Project DIVA"));
|
||||
|
||||
|
||||
// load configuration
|
||||
String configFilePath = Cache.getExecPath() + File.separator + "config.yml";
|
||||
ConfigurationManager configurationManager = new ConfigurationManager(configFilePath);
|
||||
configurationManager.initConfig();
|
||||
Cache.setConfigManager(configurationManager);
|
||||
|
||||
// connect to database
|
||||
logger.log("Connecting to database...");
|
||||
String dbFilePath = Cache.getExecPath() + File.separator + "db.sqlite"; // in current directory
|
||||
|
Reference in New Issue
Block a user