mirror of
https://github.com/mamoe/mirai.git
synced 2025-03-25 06:50:09 +08:00
Simplify
This commit is contained in:
parent
eef4ed12f6
commit
f3cbb6e485
@ -107,14 +107,14 @@ private inline fun <reified R> PipelineContext<Unit, ApplicationCall>.param(name
|
||||
@Suppress("IMPLICIT_CAST_TO_ANY")
|
||||
@UseExperimental(ExperimentalUnsignedTypes::class)
|
||||
private inline fun <reified R> PipelineContext<Unit, ApplicationCall>.paramOrNull(name: String): R? =
|
||||
when {
|
||||
R::class == Byte::class -> call.parameters[name]?.toByte()
|
||||
R::class == Int::class -> call.parameters[name]?.toInt()
|
||||
R::class == Short::class -> call.parameters[name]?.toShort()
|
||||
R::class == Float::class -> call.parameters[name]?.toFloat()
|
||||
R::class == Long::class -> call.parameters[name]?.toLong()
|
||||
R::class == Double::class -> call.parameters[name]?.toDouble()
|
||||
R::class == Boolean::class -> when (call.parameters[name]) {
|
||||
when (R::class) {
|
||||
Byte::class -> call.parameters[name]?.toByte()
|
||||
Int::class -> call.parameters[name]?.toInt()
|
||||
Short::class -> call.parameters[name]?.toShort()
|
||||
Float::class -> call.parameters[name]?.toFloat()
|
||||
Long::class -> call.parameters[name]?.toLong()
|
||||
Double::class -> call.parameters[name]?.toDouble()
|
||||
Boolean::class -> when (call.parameters[name]) {
|
||||
"true" -> true
|
||||
"false" -> false
|
||||
"0" -> false
|
||||
@ -123,13 +123,13 @@ private inline fun <reified R> PipelineContext<Unit, ApplicationCall>.paramOrNul
|
||||
else -> illegalParam("boolean", name)
|
||||
}
|
||||
|
||||
R::class == String::class -> call.parameters[name]
|
||||
String::class -> call.parameters[name]
|
||||
|
||||
R::class == UByte::class -> call.parameters[name]?.toUByte()
|
||||
R::class == UInt::class -> call.parameters[name]?.toUInt()
|
||||
R::class == UShort::class -> call.parameters[name]?.toUShort()
|
||||
UByte::class -> call.parameters[name]?.toUByte()
|
||||
UInt::class -> call.parameters[name]?.toUInt()
|
||||
UShort::class -> call.parameters[name]?.toUShort()
|
||||
|
||||
R::class == UByteArray::class -> call.parameters[name]?.hexToUBytes()
|
||||
R::class == ByteArray::class -> call.parameters[name]?.hexToBytes()
|
||||
UByteArray::class -> call.parameters[name]?.hexToUBytes()
|
||||
ByteArray::class -> call.parameters[name]?.hexToBytes()
|
||||
else -> error(name::class.simpleName + " is not supported")
|
||||
} as R?
|
||||
|
Loading…
Reference in New Issue
Block a user