Skip to content

Commit

Permalink
Finish up the Installer and added the parts that should contain in it.
Browse files Browse the repository at this point in the history
  • Loading branch information
DxsSucuk committed Jun 8, 2023
1 parent 7a59ea7 commit f5ccd19
Show file tree
Hide file tree
Showing 2 changed files with 144 additions and 38 deletions.
96 changes: 82 additions & 14 deletions Ree6-Installer/src/main/java/de/presti/ree6/Config.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.presti.ree6;

import org.simpleyaml.configuration.MemorySection;
import org.simpleyaml.configuration.file.YamlFile;

import java.io.File;
Expand Down Expand Up @@ -62,10 +63,59 @@ public void init() {
.parent().path("host").addDefault("localhost")
.parent().path("port").addDefault(3306)
.parent().parent().path("misc").comment("Misc Configuration").blankLine()
.path("storage").addDefault("sqlite")
.path("storage").addDefault("sqlite").commentSide("Possible entries: sqlite, mariadb, postgresql, h2, h2-server")
.parent().path("storageFile").addDefault("storage/Ree6.db")
.parent().path("createEmbeddedServer").addDefault(false).commentSide("Should an instance of an embedded Server be created? Only used for H2-Server.")
.parent().path("poolSize").addDefault(10);

yamlFile.path("bot")
.comment("Discord Application and overall Bot Configuration, used for OAuth, Bot Authentication and customization.").blankLine()
.path("tokens").path("release").addDefault("ReleaseTokenhere").commentSide("Token used when set to release build.")
.parent().path("beta").addDefault("BetaTokenhere").commentSide("Token used when set to beta build.")
.parent().path("dev").addDefault("DevTokenhere").commentSide("Token used when set to dev build.")
.parent().parent().path("misc").comment("Configuration for the Bot itself.").blankLine()
.path("status").addDefault("ree6.de | %guilds% Servers. (%shard%)").commentSide("The Status of the Bot.")
.parent().path("feedbackChannelId").addDefault(0L).commentSide("The Channel used for Feedback.")
.parent().path("ownerId").addDefault(321580743488831490L).commentSide("The ID of the Bot Owner. Change this to yours!")
.parent().path("predefineInformation").addDefault("""
You are Ree6 a Discord bot.
""").commentSide("Predefined Information for the AI.")
.parent().path("invite").addDefault("https://invite.ree6.de").commentSide("The Invite Link of the Bot.")
.parent().path("support").addDefault("https://support.ree6.de").commentSide("The Support Server Link of the Bot.")
.parent().path("github").addDefault("https://github.ree6.de").commentSide("The GitHub Link of the Bot.")
.parent().path("website").addDefault("https://ree6.de").commentSide("The Website Link of the Bot.")
.parent().path("webinterface").addDefault("https://cp.ree6.de").commentSide("The Webinterface Link of the Bot.")
.parent().path("recording").addDefault("https://cp.ree6.de/external/recording").commentSide("The Recording Link of the Bot.")
.parent().path("twitchAuth").addDefault("https://cp.ree6.de/external/twitch").commentSide("The Twitch Authentication Link of the Bot.")
.parent().path("advertisement").addDefault("powered by Tube-hosting").commentSide("The Advertisement in Embed Footers and the rest.")
.parent().path("name").addDefault("Ree6").commentSide("The Name of the Bot.")
.parent().path("shards").addDefault(1).commentSide("The shard amount of the Bot. Check out https://anidiots.guide/understanding/sharding/#sharding for more information.")
.parent().path("modules").comment("Customize the active modules in Ree6.").blankLine()
.path("moderation").addDefault(true).commentSide("Enable the moderation module.")
.parent().path("music").addDefault(true).commentSide("Enable the music module.")
.parent().path("fun").addDefault(true).commentSide("Enable the fun commands.")
.parent().path("community").addDefault(true).commentSide("Enable the community commands.")
.parent().path("economy").addDefault(true).commentSide("Enable the economy commands.")
.parent().path("level").addDefault(true).commentSide("Enable the level module.")
.parent().path("nsfw").addDefault(true).commentSide("Enable the nsfw module.")
.parent().path("info").addDefault(true).commentSide("Enable the info commands.")
.parent().path("hidden").addDefault(true).commentSide("Enable the hidden commands.")
.parent().path("logging").addDefault(true).commentSide("Enable the logging module.")
.parent().path("notifier").addDefault(true).commentSide("Enable the notifier module.")
.parent().path("streamtools").addDefault(true).commentSide("Enable the Stream-tools module.")
.parent().path("temporalvoice").addDefault(true).commentSide("Enable the Temporal-voice module.")
.parent().path("tickets").addDefault(true).commentSide("Enable the Tickets module.")
.parent().path("suggestions").addDefault(true).commentSide("Enable the suggestions module.")
.parent().path("customcommands").addDefault(true).commentSide("Enable the custom Commands module.")
.parent().path("customevents").addDefault(true).commentSide("Enable the custom Events module.")
.parent().path("ai").addDefault(true).commentSide("Enable the AI module.")
.parent().path("addons").addDefault(false).commentSide("Enable the Addons module.")
.parent().path("news").addDefault(true).commentSide("Enable the news command/module.")
.parent().path("games").addDefault(true).commentSide("Enable the Games module.")
.parent().path("reactionroles").addDefault(true).commentSide("Enable the reaction-roles module.")
.parent().path("slashcommands").addDefault(true).commentSide("Enable the slash-commands support.")
.parent().path("messagecommands").addDefault(true).commentSide("Enable the message-commands support.");

yamlFile.path("heartbeat")
.comment("Heartbeat Configuration, for status reporting").blankLine()
.path("url").addDefault("none").commentSide("The URL to the Heartbeat-Server")
Expand All @@ -79,8 +129,12 @@ public void init() {
yamlFile.path("amari").path("apitoken").commentSide("Your Amari API-Token, for Amari Level imports!")
.addDefault("Amari API-Token");

yamlFile.path("openai").path("apitoken").commentSide("Your OpenAI API-Token, for ChatGPT!")
.addDefault("OpenAI API-Token");
yamlFile.setBlankLine("amari");

yamlFile.path("openai").path("apiToken").commentSide("Your OpenAI API-Token, for ChatGPT!")
.addDefault("OpenAI API-Token")
.parent().path("apiUrl").addDefault("https://api.openai.com/v1/chat/completions").commentSide("The URL to the OpenAI API.")
.parent().path("model").addDefault("gpt-3.5-turbo-0301").commentSide("The Model used for the OpenAI API.");

yamlFile.setBlankLine("openai");

Expand All @@ -101,10 +155,7 @@ public void init() {

yamlFile.path("twitter")
.comment("Twitter Application Configuration, used for the Twitter Notifications.").blankLine()
.path("consumer").path("key").addDefault("yourTwitterConsumerKey")
.parent().path("secret").addDefault("yourTwitterConsumerSecret")
.parent().parent().path("access").path("key").addDefault("yourTwitterAccessKey")
.parent().path("secret").addDefault("yourTwitterAccessSecret");
.path("bearer").addDefault("yourTwitterBearerToken");

yamlFile.path("reddit")
.comment("Reddit Application Configuration, used for the Reddit Notification.").blankLine()
Expand All @@ -116,12 +167,6 @@ public void init() {
.path("username").addDefault("yourInstagramUsername")
.parent().path("password").addDefault("yourInstagramPassword");

yamlFile.path("bot")
.comment("Discord Application Configuration, used for OAuth and Bot Authentication.").blankLine()
.path("tokens").path("release").addDefault("ReleaseTokenhere").commentSide("Token used when set to release build.")
.parent().path("beta").addDefault("BetaTokenhere").commentSide("Token used when set to beta build.")
.parent().path("dev").addDefault("DevTokenhere").commentSide("Token used when set to dev build.");

try {
yamlFile.save(getFile());
} catch (Exception exception) {
Expand Down Expand Up @@ -149,15 +194,27 @@ public void migrateOldConfig() {
Map<String, Object> resources = yamlFile.getValues(true);

// Migrate configs
try {
Files.copy(getFile().toPath(), new File("config-old.yml").toPath());
} catch (Exception ignore) {
System.out.println("Could not move the old configuration file to config-old.yml!");
System.out.println("This means the config file is not backed up by us!");
}

if (getFile().delete()) {
init();

for (Map.Entry<String, Object> entry : resources.entrySet()) {
String key = entry.getKey();

boolean modified = false;

if (key.startsWith("config"))
continue;

if (entry.getValue() instanceof MemorySection)
continue;

// Migrate to 1.10.0
if (compareVersion("1.10.0", configVersion)) {

Expand All @@ -168,6 +225,7 @@ public void migrateOldConfig() {
key = key.replace(".rel", ".release");

yamlFile.set(key, entry.getValue());
modified = true;
}

// Migrate to 2.2.0
Expand All @@ -177,6 +235,17 @@ public void migrateOldConfig() {
continue;

yamlFile.set(key, entry.getValue());
modified = true;
}


// Migrate to 2.4.11
if (compareVersion("2.4.11", configVersion)) {
if (key.startsWith("twitter") && !key.endsWith("bearer")) continue;
}

if (!modified) {
yamlFile.set(key, entry.getValue());
}
}

Expand All @@ -190,7 +259,6 @@ public void migrateOldConfig() {
exception.printStackTrace();
}
}

}

/**
Expand Down
86 changes: 62 additions & 24 deletions Ree6-Installer/src/main/java/de/presti/ree6/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Paths;
Expand All @@ -19,7 +17,10 @@ public class Main {

public static void main(String[] args) throws InterruptedException {
if (getJavaVersion() < 17) {
print("Looks like you are using a version below Java 17!\nRee6 has been developed base on Java 17 you wont be able to run it with " + getJavaVersion() + "!\nYou can still continue with installing everything!");
print(String.format("""
Looks like you are using a version below Java 17!
Ree6 has been developed base on Java 17 you wont be able to run it with %s!
You can still continue with installing everything!""", getJavaVersion()));
}

if (Arrays.stream(args).anyMatch(c -> c.equalsIgnoreCase("update"))) {
Expand All @@ -31,7 +32,7 @@ public static void main(String[] args) throws InterruptedException {
if (Files.exists(Paths.get("config.yml"))) {
print("We found a config.yml!\nDo you want to update Ree6 or fully configure it? (update/configure)");

String input = System.console().readLine();
String input = getValue();
switch (input) {
case "update" -> {
print("Updating Ree6...");
Expand All @@ -53,6 +54,7 @@ public static void main(String[] args) throws InterruptedException {

/**
* Returns the Java version as an int value.
*
* @return the Java version as an int value (8, 9, etc.)
*/
public static int getJavaVersion() {
Expand Down Expand Up @@ -93,22 +95,28 @@ public static void clear() {
try {
if (System.getProperty("os.name").contains("Windows")) {
new ProcessBuilder("cmd", "/c", "cls").inheritIO().start().waitFor();
}
else {
} else {
System.out.print("\033\143");
}
} catch (IOException | InterruptedException ignore) {}
} catch (IOException | InterruptedException ignore) {
}
}

public static void setupStepOne() throws InterruptedException, IOException {
clear();
print("Welcome to the setup System of Ree6!\nLets start by configuration the Config!\nPlease select one of these Database Types: MariaDB, SQLite");
print("Welcome to the setup System of Ree6!\nLets start by configuration the Config!\nPlease select one of these Database Types: MariaDB, SQLite, Postgres, H2, H2-Server");

switch (getValueOrDefault("sqlite").toLowerCase()) {
case "mariadb" -> setupMariaDB();
case "mariadb" -> setupGenericDatabase("mariadb", "MariaDB");

case "sqlite" -> setupSQLite();

case "h2" -> setupH2(false);

case "h2-server" -> setupH2(true);

case "postgres" -> setupGenericDatabase("postgresql", "Postgres");

default -> {
print("Unknown Database Typ!");
Thread.sleep(500);
Expand All @@ -130,12 +138,24 @@ public static void setupStepTwo() throws IOException {

if (getValueOrDefault("no").toLowerCase().startsWith("y")) {

print("Enter the Heartbeat-Url (NONE)");
config.getConfiguration().set("heartbeat.url", getValueOrDefault(""));

print("Enter the Heartbeat-Interval (NONE)");
config.getConfiguration().set("heartbeat.url", getValueOrDefault(""));

print("Enter your Dagpi.xyz-Key (NONE)");
config.getConfiguration().set("dagpi.apitoken", getValueOrDefault(""));

print("Enter your AmariBot-Key (NONE)");
config.getConfiguration().set("amari.apitoken", getValueOrDefault(""));

print("Enter your OpenAI API-Token (NONE)");
config.getConfiguration().set("openai.apiToken", getValueOrDefault(""));

print("Enter your OpenAI API-Url (NONE)");
config.getConfiguration().set("openai.apiUrl", getValueOrDefault(""));

print("Enter your Sentry DSN (NONE)");
config.getConfiguration().set("sentry.dsn", getValueOrDefault(""));

Expand All @@ -151,17 +171,8 @@ public static void setupStepTwo() throws IOException {
print("Enter your Twitch Client Secret (NONE)");
config.getConfiguration().set("twitch.client.secret", getValueOrDefaultHidden(""));

print("Enter your Twitter Consumer Id (NONE)");
config.getConfiguration().set("twitter.consumer.key", getValueOrDefault(""));

print("Enter your Twitter Consumer Secret (NONE)");
config.getConfiguration().set("twitter.consumer.secret", getValueOrDefaultHidden(""));

print("Enter your Twitter Access Id (NONE)");
config.getConfiguration().set("twitter.access.key", getValueOrDefault(""));

print("Enter your Twitter Access Secret (NONE)");
config.getConfiguration().set("twitter.access.secret", getValueOrDefaultHidden(""));
print("Enter your Twitter Bearer Key (NONE)");
config.getConfiguration().set("twitter.bearer", getValueOrDefault(""));

print("Enter your Reddit Client Id (NONE)");
config.getConfiguration().set("reddit.client.id", getValueOrDefault(""));
Expand Down Expand Up @@ -216,11 +227,11 @@ public static void update() {
}
}

public static void setupMariaDB() throws IOException {
public static void setupGenericDatabase(String typ, String displayName) throws IOException {
clear();
config.getConfiguration().set("hikari.misc.storage", "mariadb");
config.getConfiguration().set("hikari.misc.storage", typ);

print("You selected MariaDB!\nLets start by setting up the connection between Ree6 and MariaDB!\nWhat is the MariaDB-User that you want to use? (root)");
print("You selected " + displayName + "!\nLets start by setting up the connection between Ree6 and " + displayName + "!\nWhat is the Username that you want to use? (root)");
String name = getValueOrDefault("root");
config.getConfiguration().set("hikari.sql.name", name);

Expand All @@ -236,7 +247,8 @@ public static void setupMariaDB() throws IOException {
String databaseName = getValueOrDefault("root");
config.getConfiguration().set("hikari.sql.db", databaseName);

print("What is the MariaDB-Password? (NONE)");

print("What is the User password? (NONE)");
String password = getValueOrDefaultHidden("");
config.getConfiguration().set("hikari.sql.pw", password);

Expand All @@ -252,6 +264,32 @@ public static void setupSQLite() throws IOException {
config.getConfiguration().save();
}

public static void setupH2(boolean server) throws IOException {
clear();
config.getConfiguration().set("hikari.misc.storage", server ? "h2-server" : "h2");

if (server) {
print("Do you want to run the H2 server?\nEnter yes if you want or no If you dont.");
String input = getValue();
if (input.equalsIgnoreCase("yes")) {
config.getConfiguration().set("hikari.misc.createEmbeddedServer", true);

print("Done!\nRee6 will now start a H2 embedded Server when you start it!\nThe port to connect is: 9092!");
} else {
config.getConfiguration().set("hikari.misc.createEmbeddedServer", false);

setupGenericDatabase("h2-server", "H2-Server");

print("Done!\nRee6 will now connect to the H2 server when you start it!");
}
} else {
config.getConfiguration().set("hikari.misc.createEmbeddedServer", false);
print("You selected H2!\nYou dont need to set up anything for this one!");
}

config.getConfiguration().save();
}

public static String getValue() {
return System.console().readLine();
}
Expand Down

0 comments on commit f5ccd19

Please sign in to comment.