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