Add arrow-kt
This commit is contained in:
parent
231b27176a
commit
5cc34c9e29
|
@ -1,5 +1,10 @@
|
||||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||||
|
|
||||||
|
val arrowVersion = "0.10.2"
|
||||||
|
|
||||||
|
apply {
|
||||||
|
plugin("kotlin-kapt")
|
||||||
|
}
|
||||||
plugins {
|
plugins {
|
||||||
kotlin("jvm") version "1.3.50"
|
kotlin("jvm") version "1.3.50"
|
||||||
id("com.github.johnrengelman.shadow") version "5.1.0" apply true
|
id("com.github.johnrengelman.shadow") version "5.1.0" apply true
|
||||||
|
@ -27,6 +32,9 @@ version = "0.1"
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
jcenter()
|
jcenter()
|
||||||
|
maven {
|
||||||
|
url = uri("https://dl.bintray.com/arrow-kt/arrow-kt/")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val test by tasks.getting(Test::class) {
|
val test by tasks.getting(Test::class) {
|
||||||
|
@ -43,6 +51,12 @@ dependencies {
|
||||||
implementation("org.jetbrains.kotlin:kotlin-reflect:1.3.50")
|
implementation("org.jetbrains.kotlin:kotlin-reflect:1.3.50")
|
||||||
implementation("com.fasterxml.jackson.core:jackson-annotations:2.10.0.pr3")
|
implementation("com.fasterxml.jackson.core:jackson-annotations:2.10.0.pr3")
|
||||||
|
|
||||||
|
implementation("io.arrow-kt:arrow-core:$arrowVersion")
|
||||||
|
implementation("io.arrow-kt:arrow-syntax:$arrowVersion")
|
||||||
|
implementation("io.arrow-kt:arrow-optics:$arrowVersion")
|
||||||
|
implementation("io.arrow-kt:arrow-meta:$arrowVersion")
|
||||||
|
implementation("io.arrow-kt:arrow-fx:$arrowVersion")
|
||||||
|
|
||||||
testImplementation("io.kotlintest:kotlintest-runner-junit5:3.4.2")
|
testImplementation("io.kotlintest:kotlintest-runner-junit5:3.4.2")
|
||||||
testImplementation("io.mockk:mockk:1.9.3")
|
testImplementation("io.mockk:mockk:1.9.3")
|
||||||
// these two are needed to access javacord internals (such as reading from sent embeds during tests)
|
// these two are needed to access javacord internals (such as reading from sent embeds during tests)
|
||||||
|
|
|
@ -37,15 +37,12 @@ object Kagebot {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private val secret by lazy { File("secret").readText().trim() }
|
|
||||||
|
|
||||||
fun init() {
|
fun init() {
|
||||||
|
val secret = File("secret").readText().trim()
|
||||||
val api = DiscordApiBuilder().setToken(secret).login().join()
|
val api = DiscordApiBuilder().setToken(secret).login().join()
|
||||||
Globals.api = api
|
Globals.api = api
|
||||||
try {
|
ConfigParser.initialLoad(ConfigParser.DEFAULT_CONFIG_PATH).mapLeft { e ->
|
||||||
ConfigParser.initialLoad(ConfigParser.DEFAULT_CONFIG_PATH)
|
println("Config parsing error:\n$e,\n${e.message},\n${e.stackTrace.joinToString("\n")}")
|
||||||
} catch (e: IllegalArgumentException) {
|
|
||||||
println("Config error:\n$e,\n${e.message},\n${e.stackTrace.joinToString("\n")}")
|
|
||||||
exitProcess(1)
|
exitProcess(1)
|
||||||
}
|
}
|
||||||
Runtime.getRuntime().addShutdownHook(Thread {
|
Runtime.getRuntime().addShutdownHook(Thread {
|
||||||
|
|
|
@ -9,12 +9,13 @@ import java.util.logging.Logger
|
||||||
|
|
||||||
object Log {
|
object Log {
|
||||||
private val log: Logger by lazy {
|
private val log: Logger by lazy {
|
||||||
val log = Logger.getGlobal()
|
Logger.getGlobal().apply {
|
||||||
val fh = FileHandler("kagebot.log", true)
|
addHandler(
|
||||||
val formatter = LogFormatter()
|
FileHandler("kagebot.log", true).apply {
|
||||||
fh.formatter = formatter
|
formatter = LogFormatter()
|
||||||
log.addHandler(fh)
|
}
|
||||||
return@lazy log
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun info(message: String) {
|
fun info(message: String) {
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package moe.kageru.kagebot
|
package moe.kageru.kagebot
|
||||||
|
|
||||||
import moe.kageru.kagebot.Util.failed
|
import moe.kageru.kagebot.Util.failed
|
||||||
import moe.kageru.kagebot.config.Config
|
|
||||||
import moe.kageru.kagebot.Util.toPairs
|
import moe.kageru.kagebot.Util.toPairs
|
||||||
|
import moe.kageru.kagebot.config.Config
|
||||||
import moe.kageru.kagebot.config.SystemSpec
|
import moe.kageru.kagebot.config.SystemSpec
|
||||||
import org.javacord.api.entity.message.Message
|
import org.javacord.api.entity.message.Message
|
||||||
import org.javacord.api.entity.message.MessageAuthor
|
import org.javacord.api.entity.message.MessageAuthor
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package moe.kageru.kagebot.config
|
package moe.kageru.kagebot.config
|
||||||
|
|
||||||
|
import arrow.core.Either
|
||||||
|
import kotlinx.coroutines.runBlocking
|
||||||
import moe.kageru.kagebot.Globals
|
import moe.kageru.kagebot.Globals
|
||||||
import moe.kageru.kagebot.config.SystemSpec.serverId
|
import moe.kageru.kagebot.config.SystemSpec.serverId
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
@ -8,15 +10,17 @@ object ConfigParser {
|
||||||
internal const val DEFAULT_CONFIG_PATH = "config.toml"
|
internal const val DEFAULT_CONFIG_PATH = "config.toml"
|
||||||
val configFile: File = File(DEFAULT_CONFIG_PATH)
|
val configFile: File = File(DEFAULT_CONFIG_PATH)
|
||||||
|
|
||||||
fun initialLoad(file: String) {
|
fun initialLoad(file: String) = runBlocking {
|
||||||
val configFile = getFile(file)
|
Either.catch {
|
||||||
val config = Config.systemSpec.file(configFile)
|
val configFile = getFile(file)
|
||||||
Config.system = config
|
val config = Config.systemSpec.file(configFile)
|
||||||
Config.server = Globals.api.getServerById(config[serverId])
|
Config.system = config
|
||||||
.orElseThrow { IllegalArgumentException("Invalid server configured.") }
|
Config.server = Globals.api.getServerById(config[serverId])
|
||||||
Config.localization = Config.localeSpec.file(configFile)
|
.orElseThrow { IllegalArgumentException("Invalid server configured.") }
|
||||||
Config.featureConfig = Config.featureSpec.file(configFile)
|
Config.localization = Config.localeSpec.file(configFile)
|
||||||
Config.commandConfig = Config.commandSpec.file(configFile)
|
Config.featureConfig = Config.featureSpec.file(configFile)
|
||||||
|
Config.commandConfig = Config.commandSpec.file(configFile)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getFile(path: String): File {
|
private fun getFile(path: String): File {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user