[F] Fix long casting

pull/29/head
Azalea 2024-03-28 01:56:23 -04:00
parent 50ae04bb4e
commit 1cdbed51cd
2 changed files with 9 additions and 3 deletions

View File

@ -115,6 +115,12 @@ catch (e: Exception) { null } }
fun Long.toHex(len: Int = 16): Str = "0x${this.toString(len).padStart(len, '0').uppercase()}" fun Long.toHex(len: Int = 16): Str = "0x${this.toString(len).padStart(len, '0').uppercase()}"
fun Map<String, Any>.toUrl() = entries.joinToString("&") { (k, v) -> "$k=$v" } fun Map<String, Any>.toUrl() = entries.joinToString("&") { (k, v) -> "$k=$v" }
fun Any.long() = when (this) {
is Number -> toLong()
is String -> toLong()
else -> 400 - "Invalid number: $this"
}
// Collections // Collections
operator fun <K, V> Map<K, V>.plus(map: Map<K, V>) = operator fun <K, V> Map<K, V>.plus(map: Map<K, V>) =
(if (this is MutableMap) this else toMutableMap()).apply { putAll(map) } (if (this is MutableMap) this else toMutableMap()).apply { putAll(map) }

View File

@ -24,7 +24,7 @@ class WaccaServer(val rp: WaccaRepos) {
init { api() } init { api() }
// DSL Functions // DSL Functions
fun options(u: WaccaUser) = rp.option.findByUser(u).associate { it.optId to it.value } fun options(u: WaccaUser?) = u?.let { rp.option.findByUser(u).associate { it.optId to it.value } } ?: emptyMap()
operator fun Map<Int, Int>.get(type: WaccaOptionType) = getOrDefault(type.id, type.default) operator fun Map<Int, Int>.get(type: WaccaOptionType) = getOrDefault(type.id, type.default)
fun ls(vararg args: Any) = args.toList() fun ls(vararg args: Any) = args.toList()
@ -75,9 +75,9 @@ fun WaccaServer.api() {
"stateUpScore#" - 0, "otherScore#" - 0, "waccaPoints#" - 0) } "stateUpScore#" - 0, "otherScore#" - 0, "waccaPoints#" - 0) }
"user/status/get" { req, (uid) -> "user/status/get" { req, (uid) ->
val ru = rp.user.findById(uid as Long)() val ru = rp.user.findById(uid.long())()
val u = ru ?: WaccaUser() val u = ru ?: WaccaUser()
val o = options(u) val o = options(ru)
u.run { ls( u.run { ls(
ls(uid, username, "userType" - 1, xp, danLevel, danType, wp, "titlePartIds" - ls(0, 0, 0), ls(uid, username, "userType" - 1, xp, danLevel, danType, wp, "titlePartIds" - ls(0, 0, 0),
loginCount, loginCountDays, loginCountConsec, loginCountDaysConsec, vipExpireTime, loginCountToday, rating), loginCount, loginCountDays, loginCountConsec, loginCountDaysConsec, vipExpireTime, loginCountToday, rating),