Move more stuff, start config site development

This commit is contained in:
Julius de Jeu 2018-09-15 00:47:18 +02:00
parent 71b657f108
commit aa55c21f04
5 changed files with 41 additions and 16 deletions

View file

@ -24,7 +24,7 @@ dependencies {
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.11.1'
compile group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version: '2.11.1'
compile 'com.github.salomonbrys.kotson:kotson:2.5.0'
compile "com.sparkjava:spark-kotlin:1.0.0-alpha"
compile 'io.javalin:javalin:2.1.1'
}

View file

@ -1,4 +1,5 @@
{
"httpPort": 7222,
"guildWords": {
"174602395630829568": {
"list": [

View file

@ -1,6 +1,6 @@
package nl.voidcorp.yeetbot
data class Config(val guildWords: MutableMap<Long, GuildInfo> = mutableMapOf())
data class Config(var httpPort: Int = 7222, val guildWords: MutableMap<Long, GuildInfo> = mutableMapOf())
data class GuildInfo(val list: MutableList<Match> = mutableListOf())
@ -11,4 +11,4 @@ enum class MatchType {
RAW
}
fun MutableList<Match>.contains(match: String):Boolean = this.any { it.match == match }
fun MutableList<Match>.contains(match: String): Boolean = this.any { it.match == match }

View file

@ -1,8 +1,20 @@
package nl.voidcorp.yeetbot
import com.google.gson.GsonBuilder
import java.util.regex.Pattern
import java.util.regex.PatternSyntaxException
val gson = GsonBuilder().setPrettyPrinting().create()
fun Any.toJson():String = gson.toJson(this)
fun checkRegex(pattern: String): Boolean {
var exc: PatternSyntaxException? = null
try {
Pattern.compile(pattern)
} catch (e: PatternSyntaxException) {
exc = e
}
return exc == null
}

View file

@ -1,15 +1,19 @@
package nl.voidcorp.yeetbot
import com.github.salomonbrys.kotson.fromJson
import net.dv8tion.jda.core.*
import io.javalin.Javalin
import io.javalin.json.FromJsonMapper
import io.javalin.json.JavalinJson
import io.javalin.json.ToJsonMapper
import net.dv8tion.jda.core.AccountType
import net.dv8tion.jda.core.JDABuilder
import net.dv8tion.jda.core.OnlineStatus
import net.dv8tion.jda.core.entities.Game
import org.apache.logging.log4j.LogManager
import java.io.File
import java.io.FileReader
import java.io.FileWriter
import java.util.*
import java.util.regex.Pattern
import java.util.regex.PatternSyntaxException
import kotlin.concurrent.fixedRateTimer
import kotlin.concurrent.schedule
@ -82,16 +86,24 @@ fun main(args: Array<String>) {
}
}
JavalinJson.toJsonMapper = object : ToJsonMapper {
override fun map(obj: Any): String = obj.toJson()
}
JavalinJson.fromJsonMapper = object : FromJsonMapper {
override fun <T> map(json: String, targetClass: Class<T>): T = gson.fromJson(json, targetClass)
}
val app = Javalin.create().start(config.httpPort)
app.get("/") {
it.result("memes!")
}
app.get("/test") {
it.json(config)
}
}
fun checkRegex(pattern: String): Boolean {
var exc: PatternSyntaxException? = null
try {
Pattern.compile(pattern)
} catch (e: PatternSyntaxException) {
exc = e
}
return exc == null
}