package moe.kageru.spektacles import arrow.core.Option import arrow.core.toOption import java.time.LocalDateTime class ParsedLine(val time: LocalDateTime, val user: Option, val userMode: Option, val message: String, val isSystemMessage: Boolean, private val originalMessage: String ) { override fun toString() = originalMessage companion object { // 18 04 26 19:40:47 Hi private val lineRegex = Regex("""(?\d\d)\s(?\d\d)\s(?\d\d)\s(?\d\d):(?\d\d):(?\d\d)\s(<(?[~&@%+])?(?\w+)>\t)?(?.*)""") fun parse(line: String): ParsedLine? = lineRegex .matchEntire(line) ?.let { ParsedLine( LocalDateTime.of( it.groups["year"]!!.value.toInt(), it.groups["month"]!!.value.toInt(), it.groups["day"]!!.value.toInt(), it.groups["hour"]!!.value.toInt(), it.groups["minute"]!!.value.toInt(), it.groups["second"]!!.value.toInt() ), it.groups["author"]?.value.toOption(), it.groups["mode"]?.value?.let { UserMode.values().first { mode -> mode.icon == it } }.toOption(), it.groups["message"]!!.value, it.groups["author"] == null, it.value ) } } } enum class UserMode(val icon: String) { ADMIN("~"), BOT("&"), OP("@"), HOP("%"), VOICE("+"); }