Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using default config values #4

Merged
merged 3 commits into from
Nov 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/main/kotlin/tech/goksi/pterobot/PteroBot.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import tech.goksi.pterobot.events.NodeStatusDelete
import tech.goksi.pterobot.manager.ConfigManager
import tech.goksi.pterobot.manager.EmbedManager
import tech.goksi.pterobot.util.Checks
import kotlin.system.exitProcess

private const val DEFAULT_NO_TOKEN_MSG = "YOUR TOKEN HERE"
private const val DEFAULT_NO_ID_MSG = "YOUR DISCORD SERVER ID HERE"
Expand Down Expand Up @@ -117,8 +118,8 @@ class PteroBot {
logger.info("PteroBot has successfully started, you can stop it by typing \"stop\"")
while (true) {
if ((readLine()?.lowercase()) == "stop") {
jda.shutdown()
break
jda.shutdownNow()
exitProcess(0)
} else logger.warn("Wrong command ! You mean \"stop\" ?")
}
}
Expand Down
7 changes: 6 additions & 1 deletion src/main/kotlin/tech/goksi/pterobot/manager/ConfigManager.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package tech.goksi.pterobot.manager

import dev.minn.jda.ktx.util.SLF4J
import org.simpleyaml.configuration.file.YamlConfiguration
import org.simpleyaml.configuration.file.YamlFile
import org.simpleyaml.utils.SupplierIO
import java.io.File
import java.io.IOException
import kotlin.system.exitProcess
Expand All @@ -12,13 +14,16 @@ object ConfigManager {
val config: YamlFile

init {
val inputStreamURL = ConfigManager::class.java.classLoader.getResource("config.yml")!!
if (!configFile.exists()) {
val content = ConfigManager::class.java.classLoader.getResource("config.yml")!!.readText()
val content = inputStreamURL.readText()
configFile.writeText(content)
}
config = YamlFile(configFile)
try {
config.loadWithComments()
config.defaults =
YamlConfiguration.loadConfiguration(SupplierIO.InputStream { inputStreamURL.openStream() })
} catch (exception: IOException) {
logger.error("Error while loading configuration file, exiting program...", exception)
exitProcess(1)
Expand Down