Discontinue config.yml file in favor of class mapping
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
The configuration entries are now mapped in an enum that transfers very well to SnakeYaml's YAML parsing. This is better because we no longer run the risk of entries getting mistyped in classes, or renamed without replacing them everywhere...
This commit is contained in:
parent
ae6647a51e
commit
6480795368
@ -0,0 +1,24 @@
|
|||||||
|
package wtf.beatrice.hidekobot.datasource;
|
||||||
|
|
||||||
|
public enum ConfigurationEntry
|
||||||
|
{
|
||||||
|
|
||||||
|
BOT_TOKEN("bot-token", "MTAxMjUzNzI5MTMwODI4NjAyMw.GWeNuh.00000000000000000000000000000000000000"),
|
||||||
|
BOT_OWNER_ID("bot-owner-id", 100000000000000000L),
|
||||||
|
BOT_COLOR("bot-color", "PINK"),
|
||||||
|
HEARTBEAT_LINK("heartbeat-link", "https://your-heartbeat-api.com/api/push/apikey?status=up&msg=OK&ping="),
|
||||||
|
|
||||||
|
;
|
||||||
|
|
||||||
|
|
||||||
|
private String path;
|
||||||
|
private Object defaultValue;
|
||||||
|
ConfigurationEntry(String path, Object defaultValue)
|
||||||
|
{
|
||||||
|
this.path = path;
|
||||||
|
this.defaultValue = defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPath() { return path; }
|
||||||
|
public Object getDefaultValue() { return defaultValue; }
|
||||||
|
}
|
@ -25,19 +25,18 @@ public class ConfigurationSource
|
|||||||
public void initConfig()
|
public void initConfig()
|
||||||
{
|
{
|
||||||
// load the YAML file from the archive's resources folder
|
// load the YAML file from the archive's resources folder
|
||||||
Yaml internalConfigYaml = new Yaml();
|
/*
|
||||||
LinkedHashMap<String, Object> internalConfigContents = null; // map holding all file entries
|
* note: this is no longer technically a YAML file, but we are using a very similar structure
|
||||||
try (InputStream internalConfigStream = getClass()
|
* to what SnakeYaml does, so that it can map all entries directly to a YAML file itself.
|
||||||
.getClassLoader()
|
* we used to have a config.yml file in the "resources" folder, but that is no longer necessary.
|
||||||
.getResourceAsStream("config.yml"))
|
*/
|
||||||
{ internalConfigContents = internalConfigYaml.load(internalConfigStream); }
|
LinkedHashMap<String, Object> internalConfigContents = new LinkedHashMap<>(); // map holding all file entries
|
||||||
catch (IOException e) {
|
for(ConfigurationEntry entry : ConfigurationEntry.values())
|
||||||
logger.log(e.getMessage());
|
{
|
||||||
HidekoBot.shutdown();
|
internalConfigContents.put(entry.getPath(), entry.getDefaultValue());
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(internalConfigContents == null)
|
if(internalConfigContents.isEmpty())
|
||||||
{
|
{
|
||||||
logger.log("Error reading internal configuration!");
|
logger.log("Error reading internal configuration!");
|
||||||
HidekoBot.shutdown();
|
HidekoBot.shutdown();
|
||||||
|
@ -1,4 +0,0 @@
|
|||||||
bot-token: 'MTAxMjUzNzI5MTMwODI4NjAyMw.GWeNuh.00000000000000000000000000000000000000'
|
|
||||||
bot-owner-id: 000000000000000000
|
|
||||||
bot-color: 'PINK'
|
|
||||||
heartbeat-link: 'https://your-heartbeat-api.com/api/push/apikey?status=up&msg=OK&ping='
|
|
Loading…
Reference in New Issue
Block a user