Skip to content

Commit

Permalink
Merge pull request #4 from Goksi/config-defaults
Browse files Browse the repository at this point in the history
Using default config values
  • Loading branch information
Goksi authored Nov 13, 2022
2 parents 14bdd4f + 5c1f99a commit 8c3a44f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
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

0 comments on commit 8c3a44f

Please sign in to comment.