mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-11 02:50:15 +08:00
Move CommandResolveResult.fold to extension, add CommandResolveResult.getOrElse
This commit is contained in:
parent
453d072cc7
commit
77f00d2d84
@ -32,7 +32,12 @@ public class CommandResolveResult private constructor(
|
|||||||
public val failure: CommandExecuteResult.Failure?
|
public val failure: CommandExecuteResult.Failure?
|
||||||
get() = value.safeCast()
|
get() = value.safeCast()
|
||||||
|
|
||||||
public inline fun <R> fold(
|
public constructor(call: ResolvedCommandCall?) : this(call as Any?)
|
||||||
|
public constructor(failure: CommandExecuteResult.Failure) : this(failure as Any)
|
||||||
|
}
|
||||||
|
|
||||||
|
@OptIn(ExperimentalCommandDescriptors::class)
|
||||||
|
public inline fun <R> CommandResolveResult.fold(
|
||||||
onSuccess: (ResolvedCommandCall?) -> R,
|
onSuccess: (ResolvedCommandCall?) -> R,
|
||||||
onFailure: (CommandExecuteResult.Failure) -> R,
|
onFailure: (CommandExecuteResult.Failure) -> R,
|
||||||
): R {
|
): R {
|
||||||
@ -44,8 +49,16 @@ public class CommandResolveResult private constructor(
|
|||||||
return call.let(onSuccess)
|
return call.let(onSuccess)
|
||||||
}
|
}
|
||||||
|
|
||||||
public constructor(call: ResolvedCommandCall?) : this(call as Any?)
|
|
||||||
public constructor(failure: CommandExecuteResult.Failure) : this(failure as Any)
|
@OptIn(ExperimentalCommandDescriptors::class)
|
||||||
|
public inline fun CommandResolveResult.getOrElse(
|
||||||
|
onFailure: (CommandExecuteResult.Failure) -> ResolvedCommandCall,
|
||||||
|
): ResolvedCommandCall {
|
||||||
|
contract {
|
||||||
|
callsInPlace(onFailure, InvocationKind.AT_MOST_ONCE)
|
||||||
|
}
|
||||||
|
failure?.let(onFailure)?.let { return it }
|
||||||
|
return call!!
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -193,11 +193,8 @@ internal suspend fun executeCommandImpl(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val resolved = call
|
val resolved = call
|
||||||
.resolve().fold(
|
.resolve()
|
||||||
onSuccess = { it },
|
.getOrElse { return it }
|
||||||
onFailure = { return it }
|
|
||||||
)
|
|
||||||
.ifNull { return CommandExecuteResult.UnresolvedCommand(call) }
|
|
||||||
.let { raw ->
|
.let { raw ->
|
||||||
raw.intercepted()
|
raw.intercepted()
|
||||||
.getOrElse { return CommandExecuteResult.Intercepted(call, raw, null, it) }
|
.getOrElse { return CommandExecuteResult.Intercepted(call, raw, null, it) }
|
||||||
|
Loading…
Reference in New Issue
Block a user