Skip to content

Commit e4f153f

Browse files
committed
Use hjson for configuration
1 parent a4f56d3 commit e4f153f

5 files changed

+18
-12
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
.idea/
33
build/
44
out/
5-
kotbot.config.json
5+
kotbot.config.hjson
66
kotbotdb

build.gradle.kts

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ dependencies {
1818
implementation("org.graalvm.sdk:graal-sdk:1.0.0-rc16")
1919
implementation("com.beust:klaxon:5.0.1")
2020
implementation("org.xerial:sqlite-jdbc:3.27.2.1")
21+
implementation("org.hjson:hjson:3.0.0")
2122
implementation(kotlin("stdlib-jdk8"))
2223
}
2324

kotbot.config.hjson.example

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
username: kotbot,
3+
hostname: "localhost",
4+
channel: "#example",
5+
port: 6667,
6+
identify_password: "",
7+
identify_owner: "",
8+
command_prefix: ".",
9+
openweathermap: ""
10+
}

kotbot.config.json.example

-10
This file was deleted.

src/main/kotlin/Configuration.kt

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package us.kesslern.kotbot
22

33
import com.beust.klaxon.JsonObject
44
import com.beust.klaxon.Parser
5+
import org.hjson.JsonValue
6+
import java.io.File
57
import java.io.FileNotFoundException
68

79
/**
@@ -13,7 +15,10 @@ object ConfigurationFile {
1315
init {
1416
val parser: Parser = Parser.default()
1517
try {
16-
json = parser.parse("./kotbot.config.json") as JsonObject
18+
val hjson = File("./kotbot.config.hjson").readText(Charsets.UTF_8)
19+
val stream = StringBuilder()
20+
stream.append(JsonValue.readHjson(hjson))
21+
json = parser.parse(stream) as JsonObject
1722
} catch (e: FileNotFoundException) {
1823
throw RuntimeException("Cannot find configuration file kotbot.config.json")
1924
}

0 commit comments

Comments
 (0)