Use env vars instead of json
This commit is contained in:
parent
57ae8a5e94
commit
89585cae0e
8 changed files with 28 additions and 38 deletions
2
.env
Normal file
2
.env
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
DOKI_TOKEN=OTM4NTIyNzgxMDM1OTIxNDQ4.G49Qim.wrCrGvb3YwTQEMMoJ0P3LpSCWcaeL2AAuOOsEI
|
||||||
|
DOKI_WARNING_CHANNEL=1320191969137393736
|
||||||
3
.idea/runConfigurations/Doki.xml
generated
3
.idea/runConfigurations/Doki.xml
generated
|
|
@ -1,5 +1,8 @@
|
||||||
<component name="ProjectRunConfigurationManager">
|
<component name="ProjectRunConfigurationManager">
|
||||||
<configuration default="false" name="Doki" type="Application" factoryName="Application">
|
<configuration default="false" name="Doki" type="Application" factoryName="Application">
|
||||||
|
<option name="envFilePaths">
|
||||||
|
<option value="$PROJECT_DIR$/.env" />
|
||||||
|
</option>
|
||||||
<option name="MAIN_CLASS_NAME" value="net.hypr.doki.Doki" />
|
<option name="MAIN_CLASS_NAME" value="net.hypr.doki.Doki" />
|
||||||
<module name="doki" />
|
<module name="doki" />
|
||||||
<method v="2">
|
<method v="2">
|
||||||
|
|
|
||||||
13
README.md
13
README.md
|
|
@ -18,13 +18,12 @@ A multipurpose Discord bot written in Java.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Config file schema
|
## Enviromnent Variables
|
||||||
```json
|
|
||||||
{
|
| Variable | Description |
|
||||||
"token": "your_token",
|
|------------------------|----------------------------|
|
||||||
"warningChannel": 0
|
| `DOKI_TOKEN` | Discord token for the bot |
|
||||||
}
|
| `DOKI_WARNING_CHANNEL` | Channel to log warnings to |
|
||||||
```
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +0,0 @@
|
||||||
{
|
|
||||||
"token": "CHANGEME",
|
|
||||||
"warningChannel": 0
|
|
||||||
}
|
|
||||||
2
pom.xml
2
pom.xml
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
<groupId>net.hypr</groupId>
|
<groupId>net.hypr</groupId>
|
||||||
<artifactId>doki</artifactId>
|
<artifactId>doki</artifactId>
|
||||||
<version>1.0.9</version>
|
<version>1.1.0</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>17</maven.compiler.source>
|
<maven.compiler.source>17</maven.compiler.source>
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,20 @@
|
||||||
package net.hypr.doki;
|
package net.hypr.doki;
|
||||||
|
|
||||||
import com.freya02.botcommands.api.Logging;
|
import com.freya02.botcommands.api.Logging;
|
||||||
import com.google.gson.Gson;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
|
|
||||||
//You can add more fields in this class, if your input json matches the structure
|
//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
|
//You will need a valid config.json in the resources folder for this to work
|
||||||
public class Config {
|
public class Config {
|
||||||
@SuppressWarnings("unused") private String token;
|
@SuppressWarnings("unused") private final String token;
|
||||||
@SuppressWarnings("unused") private long warningChannel;
|
@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
|
* Returns the configuration object for this bot
|
||||||
*
|
*
|
||||||
|
|
@ -21,14 +23,10 @@ public class Config {
|
||||||
*/
|
*/
|
||||||
public static Config readConfig() throws IOException {
|
public static Config readConfig() throws IOException {
|
||||||
Logger log = Logging.getLogger();
|
Logger log = Logging.getLogger();
|
||||||
try (InputStream in = new FileInputStream("./config.json")) {
|
return new Config(
|
||||||
Reader reader = new InputStreamReader(in, StandardCharsets.UTF_8);
|
System.getenv("DOKI_TOKEN"),
|
||||||
log.info("Loaded config");
|
Long.parseLong(System.getenv("DOKI_WARNING_CHANNEL"))
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getToken() {
|
public String getToken() {
|
||||||
|
|
|
||||||
|
|
@ -38,9 +38,13 @@ public class Doki {
|
||||||
// Print some information about the bot
|
// Print some information about the bot
|
||||||
log.info("Bot connected as {}", jda.getSelfUser().getAsTag());
|
log.info("Bot connected as {}", jda.getSelfUser().getAsTag());
|
||||||
log.info("The bot is present in the following guilds:");
|
log.info("The bot is present in the following guilds:");
|
||||||
|
try {
|
||||||
for (Guild guild : jda.getGuildCache()) {
|
for (Guild guild : jda.getGuildCache()) {
|
||||||
log.info("\t- {} ({})", guild.getName(), guild.getId());
|
log.info("\t- {} ({})", guild.getName(), guild.getId());
|
||||||
}
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
new Doki(jda, config);
|
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