Hinzufügen einer Config Datei
This commit is contained in:
11
src/main/java/core/Main.java
Normal file → Executable file
11
src/main/java/core/Main.java
Normal file → Executable file
@ -15,16 +15,21 @@ public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
Config conf = new Config();
|
||||
conf.readConfig();
|
||||
// Insert your bot's token here
|
||||
String token = "NDA1MDQ2NDg1OTk0OTYyOTQ2.DUessg.YFKvsTLIyPwprLlEOnZc0PXWJH0";
|
||||
//String token = "NTQ3MDc5NzgzNDE1MjgzNzEy.D0xjRw.ydeX_ou_pAqN_DCSwyGHzQUGBBk";
|
||||
String token = conf.token;
|
||||
|
||||
JDABuilder builder = new JDABuilder(AccountType.BOT);
|
||||
|
||||
|
||||
|
||||
builder.setToken(token);
|
||||
builder.setAutoReconnect(true);
|
||||
builder.setStatus(OnlineStatus.ONLINE);
|
||||
builder.setGame(Game.watching("Den NinjaSäuen zu"));
|
||||
builder.addEventListener(new groupchange());
|
||||
builder.setGame(Game.watching(conf.GameWatching));
|
||||
builder.addEventListener(new groupchange(conf));
|
||||
|
||||
try {
|
||||
JDA jda = builder.build();
|
||||
|
||||
83
src/main/java/core/config.java
Executable file
83
src/main/java/core/config.java
Executable file
@ -0,0 +1,83 @@
|
||||
package core;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.Properties;
|
||||
|
||||
public class Config {
|
||||
public String token;
|
||||
public String GameWatching = "Den NinjaSäuen zu";
|
||||
|
||||
public String targetRole = "Ninjasau";
|
||||
public String authorizedRole = "Chief Ninjasau";
|
||||
|
||||
public String userNotFound = "Benutzer nicht gefunden";
|
||||
public String noPrivilegs = "Du bist nicht berechtigt den Befehl auszuführen";
|
||||
|
||||
public String hasGroup = "%Member% hat bereits die Gruppe %Group%";
|
||||
public String becameGroup = "%Member% wurde der Gruppe %Group% zugeteilt";
|
||||
|
||||
public String notInGroup = "%Member% ist nicht in der Gruppe %Group%";
|
||||
public String removeGroup = "%Member% wurde aus der Gruppe %Group% entfernt";
|
||||
|
||||
|
||||
public void readConfig() {
|
||||
FileInputStream input = null;
|
||||
OutputStream output = null;
|
||||
Properties config = new Properties();
|
||||
try {
|
||||
File f = new File("config.cfg");
|
||||
if (f.isFile() && f.canRead()) {
|
||||
|
||||
input = new FileInputStream("config.cfg");
|
||||
config.load(input);
|
||||
if(config.containsKey("token"))
|
||||
this.token = config.getProperty("token");
|
||||
if(config.containsKey("GameWatching"))
|
||||
this.GameWatching = config.getProperty("GameWatching");
|
||||
|
||||
if(config.containsKey("targetRole"))
|
||||
this.targetRole = config.getProperty("targetRole");
|
||||
if(config.containsKey("authorizedRole"))
|
||||
this.authorizedRole = config.getProperty("authorizedRole");
|
||||
if(config.containsKey("userNotFound"))
|
||||
this.userNotFound = config.getProperty("userNotFound");
|
||||
if(config.containsKey("noPrivilegs"))
|
||||
this.noPrivilegs = config.getProperty("noPrivilegs");
|
||||
if(config.containsKey("hasGroup"))
|
||||
this.hasGroup = config.getProperty("hasGroup");
|
||||
if(config.containsKey("becameGroup"))
|
||||
this.becameGroup = config.getProperty("becameGroup");
|
||||
if(config.containsKey("notInGroup"))
|
||||
this.notInGroup = config.getProperty("notInGroup");
|
||||
if(config.containsKey("removeGroup"))
|
||||
this.removeGroup = config.getProperty("removeGroup");
|
||||
|
||||
}
|
||||
else {
|
||||
output = new FileOutputStream("config.cfg");
|
||||
config.setProperty("targetRole", this.targetRole);
|
||||
config.setProperty("authorizedRole", this.authorizedRole);
|
||||
config.setProperty("userNotFound", this.userNotFound);
|
||||
config.setProperty("noPrivilegs", this.noPrivilegs);
|
||||
config.setProperty("hasGroup", this.hasGroup);
|
||||
config.setProperty("becameGroup", this.becameGroup);
|
||||
config.setProperty("notInGroup", this.notInGroup);
|
||||
config.setProperty("removeGroup", this.removeGroup);
|
||||
config.store(output, null);
|
||||
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
finally {
|
||||
if (input != null) {
|
||||
try {
|
||||
input.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user