2022-03-23 20:39:52 +00:00
|
|
|
package moe.oko.Kiafumi;
|
2022-03-23 20:31:23 +00:00
|
|
|
|
2022-03-24 04:10:50 +00:00
|
|
|
import moe.oko.Kiafumi.model.KiafumiDB;
|
2022-03-23 20:31:23 +00:00
|
|
|
import org.simpleyaml.configuration.ConfigurationSection;
|
|
|
|
import org.simpleyaml.configuration.file.YamlConfiguration;
|
|
|
|
|
2022-03-23 20:39:52 +00:00
|
|
|
import static moe.oko.Kiafumi.Kiafumi.error;
|
|
|
|
import static moe.oko.Kiafumi.Kiafumi.info;
|
2022-03-23 20:31:23 +00:00
|
|
|
|
2022-03-23 20:39:52 +00:00
|
|
|
public class KiafumiConfig {
|
2022-03-23 20:31:23 +00:00
|
|
|
|
|
|
|
public YamlConfiguration configuration;
|
|
|
|
|
|
|
|
/*
|
|
|
|
Discord Variable Section
|
|
|
|
*/
|
|
|
|
private String token;
|
|
|
|
private String logChannel;
|
|
|
|
private String ownerId;
|
|
|
|
private String mainGuild;
|
|
|
|
private String clientId;
|
|
|
|
private String prefix;
|
|
|
|
private int defaultInvitePermissionLevel;
|
|
|
|
|
|
|
|
/*
|
2022-03-23 20:39:52 +00:00
|
|
|
Kia Variable Section
|
2022-03-23 20:31:23 +00:00
|
|
|
*/
|
|
|
|
private boolean sharded;
|
2022-03-23 20:39:52 +00:00
|
|
|
private String activityType;
|
|
|
|
private String activityMsg;
|
|
|
|
private String statusType;
|
2022-03-23 20:31:23 +00:00
|
|
|
|
2022-03-24 04:10:50 +00:00
|
|
|
/*
|
|
|
|
SQL Variable Section
|
|
|
|
*/
|
|
|
|
private String host;
|
|
|
|
private int port;
|
|
|
|
private String username;
|
|
|
|
private String password;
|
|
|
|
private String database;
|
|
|
|
|
2022-03-23 20:39:52 +00:00
|
|
|
public KiafumiConfig(YamlConfiguration configuration) {
|
2022-03-23 20:31:23 +00:00
|
|
|
//Load config on class creation...
|
|
|
|
this.configuration = configuration;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean load() {
|
|
|
|
try {
|
|
|
|
//Discord loaders
|
|
|
|
info("Starting Discord Configuration load");
|
|
|
|
ConfigurationSection discord = configuration.getConfigurationSection("discord");
|
|
|
|
token = discord.getString("token");
|
|
|
|
info("!!! DO NOT SHARE !!! Token - " + token);
|
|
|
|
logChannel = discord.getString("logChannel");
|
|
|
|
info("Logging Channel - " + logChannel);
|
|
|
|
ownerId = discord.getString("ownerId");
|
|
|
|
info("Owner ID - " + ownerId);
|
|
|
|
mainGuild = discord.getString("mainGuild");
|
|
|
|
info("Main Guild - " + mainGuild);
|
|
|
|
clientId = discord.getString("clientId");
|
|
|
|
defaultInvitePermissionLevel = discord.getInt("invitePermissionLevel");
|
|
|
|
info("Invite link - " + assembleDefaultInvite());
|
|
|
|
prefix = discord.getString("prefix");
|
|
|
|
info("Prefix - " + prefix);
|
|
|
|
//Shiki loaders
|
|
|
|
ConfigurationSection main = configuration.getConfigurationSection("main");
|
|
|
|
sharded = main.getBoolean("sharded");
|
2022-03-23 20:39:52 +00:00
|
|
|
activityType = main.getString("activityType");
|
|
|
|
activityMsg = main.getString("activityMsg");
|
|
|
|
statusType = main.getString("statusType");
|
2022-03-24 04:10:50 +00:00
|
|
|
//SQL loaders
|
|
|
|
ConfigurationSection sql = configuration.getConfigurationSection("sql");
|
|
|
|
host = sql.getString("host");
|
|
|
|
port = sql.getInt("port");
|
|
|
|
username = sql.getString("username");
|
|
|
|
password = sql.getString("password");
|
|
|
|
database = sql.getString("database");
|
2022-03-23 20:31:23 +00:00
|
|
|
} catch(Exception ex) {
|
|
|
|
ex.printStackTrace();
|
|
|
|
error("Failed to load configuration!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
info("Configuration Loaded");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String assembleDefaultInvite() {
|
|
|
|
return "https://discord.com/oauth2/authorize?client_id=" + clientId + "&scope=bot&permissions=" + defaultInvitePermissionLevel;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getPrefix() {
|
|
|
|
return prefix;
|
|
|
|
}
|
2022-03-23 20:39:52 +00:00
|
|
|
|
|
|
|
public String getToken() { return token; }
|
|
|
|
|
|
|
|
public String getActivityType() { return activityType; }
|
|
|
|
|
|
|
|
public String getActivityMsg() { return activityMsg; }
|
|
|
|
|
|
|
|
public String getStatusType() { return statusType; }
|
2022-03-24 04:10:50 +00:00
|
|
|
|
|
|
|
public String getLogChannel() { return logChannel; }
|
|
|
|
|
|
|
|
public KiafumiDB createDb() { return new KiafumiDB(username, password, host, port, database); }
|
2022-03-23 20:31:23 +00:00
|
|
|
}
|