Use env vars instead of json
This commit is contained in:
parent
57ae8a5e94
commit
89585cae0e
8 changed files with 28 additions and 38 deletions
|
|
@ -1,18 +1,20 @@
|
|||
package net.hypr.doki;
|
||||
|
||||
import com.freya02.botcommands.api.Logging;
|
||||
import com.google.gson.Gson;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
//You can add more fields in this class, if your input json matches the structure
|
||||
//You will need a valid config.json in the resources folder for this to work
|
||||
public class Config {
|
||||
@SuppressWarnings("unused") private String token;
|
||||
@SuppressWarnings("unused") private long warningChannel;
|
||||
@SuppressWarnings("unused") private final String token;
|
||||
@SuppressWarnings("unused") private final long warningChannel;
|
||||
|
||||
private Config(String token, long warningChannel) {
|
||||
this.token = token;
|
||||
this.warningChannel = warningChannel;
|
||||
}
|
||||
/**
|
||||
* Returns the configuration object for this bot
|
||||
*
|
||||
|
|
@ -21,14 +23,10 @@ public class Config {
|
|||
*/
|
||||
public static Config readConfig() throws IOException {
|
||||
Logger log = Logging.getLogger();
|
||||
try (InputStream in = new FileInputStream("./config.json")) {
|
||||
Reader reader = new InputStreamReader(in, StandardCharsets.UTF_8);
|
||||
log.info("Loaded config");
|
||||
return new Gson().fromJson(reader, Config.class);
|
||||
} catch (IOException | NullPointerException e) {
|
||||
log.error("Failed to load config.json, does the file exist?");
|
||||
throw new IOException(e);
|
||||
}
|
||||
return new Config(
|
||||
System.getenv("DOKI_TOKEN"),
|
||||
Long.parseLong(System.getenv("DOKI_WARNING_CHANNEL"))
|
||||
);
|
||||
}
|
||||
|
||||
public String getToken() {
|
||||
|
|
|
|||
|
|
@ -38,8 +38,12 @@ public class Doki {
|
|||
// Print some information about the bot
|
||||
log.info("Bot connected as {}", jda.getSelfUser().getAsTag());
|
||||
log.info("The bot is present in the following guilds:");
|
||||
for (Guild guild : jda.getGuildCache()) {
|
||||
log.info("\t- {} ({})", guild.getName(), guild.getId());
|
||||
try {
|
||||
for (Guild guild : jda.getGuildCache()) {
|
||||
log.info("\t- {} ({})", guild.getName(), guild.getId());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
new Doki(jda, config);
|
||||
|
|
|
|||
|
|
@ -1,12 +0,0 @@
|
|||
{
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"token": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"token"
|
||||
]
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue