mirror of
https://github.com/JonasunderscoreJones/ZtereoMUSIC.git
synced 2025-10-25 05:29:18 +02:00
Use dedicated method for loading Config, clean exception types and handling
This commit is contained in:
parent
0fa9ceef8e
commit
d11b9a97a4
2 changed files with 21 additions and 8 deletions
|
|
@ -13,9 +13,13 @@ import com.sedmelluq.discord.lavaplayer.source.AudioSourceManagers;
|
|||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.SneakyThrows;
|
||||
import net.dv8tion.jda.api.JDA;
|
||||
import net.dv8tion.jda.api.JDABuilder;
|
||||
import net.shadew.json.JsonSyntaxException;
|
||||
|
||||
import javax.security.auth.login.LoginException;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
|
@ -43,10 +47,12 @@ public class Bot {
|
|||
return Bot.INSTANCE;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
@SneakyThrows({ JsonSyntaxException.class, FileNotFoundException.class, LoginException.class,
|
||||
InterruptedException.class })
|
||||
public static void main(String[] args) {
|
||||
Bot bot = Bot.getInstance();
|
||||
|
||||
bot.setConfig(new Config("./config.json5"));
|
||||
bot.setConfig(Config.loadFrom("./config.json5"));
|
||||
bot.setJda(JDABuilder.createDefault(bot.getConfig().getPropreties().get("token"), GUILD_MESSAGES,
|
||||
GUILD_VOICE_STATES).build().awaitReady());
|
||||
|
||||
|
|
|
|||
|
|
@ -3,22 +3,29 @@ package codes.ztereohype.ztereomusic.database;
|
|||
import lombok.Getter;
|
||||
import net.shadew.json.Json;
|
||||
import net.shadew.json.JsonNode;
|
||||
import net.shadew.json.JsonSyntaxException;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class Config {
|
||||
private @Getter final Map<String, String> propreties = new HashMap<>();
|
||||
private final String path;
|
||||
private @Getter Map<String, String> propreties = new HashMap<>();
|
||||
private String path;
|
||||
|
||||
public static Config loadFrom(String path) throws JsonSyntaxException, FileNotFoundException {
|
||||
Config config = new Config();
|
||||
|
||||
public Config(String pathname) throws Exception {
|
||||
Json json5 = Json.json5();
|
||||
JsonNode tree = json5.parse(new File(pathname));
|
||||
this.path = pathname;
|
||||
JsonNode tree = json5.parse(new File(path));
|
||||
|
||||
config.path = path;
|
||||
|
||||
for (String key : tree.keys()) {
|
||||
propreties.put(key, tree.get(key).asString());
|
||||
config.getPropreties().put(key, tree.get(key).asString());
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue