Skip to content

Commit

Permalink
合并拉取请求 #452
Browse files Browse the repository at this point in the history
调整各监听函数相关实现,所有默认的 `EventResult` 调整为 `EventResult.invalid()`。
  • Loading branch information
ForteScarlet authored Sep 9, 2022
2 parents 8ceb729 + 0565c01 commit e7f415c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,13 @@ public interface EventResult {
*
* @see Truncated
*/
public sealed class Default : EventResult {
public object Truncated : Default() {
private sealed class Default : EventResult {
object Truncated : Default() {
override val content: Any? get() = null
override val isTruncated: Boolean get() = true
}

public object NormalEmpty : Default() {
object NormalEmpty : Default() {
override val content: Any? get() = null
override val isTruncated: Boolean get() = false
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Copyright (c) 2021-2022 ForteScarlet <ForteScarlet@163.com>
*
* 本文件是 simply-robot ( simple robot的v3版本,因此亦可称为 simple-robot v3 、simbot v3 等) 的一部分。
* 本文件是 simply-robot (或称 simple-robot 3.x 、simbot 3.x ) 的一部分。
*
* simply-robot 是自由软件:你可以再分发之和/或依照由自由软件基金会发布的 GNU 通用公共许可证修改之,无论是版本 3 许可证,还是(按你的决定)任何以后版都可以。
*
Expand All @@ -12,7 +12,6 @@
* https://www.gnu.org/licenses/gpl-3.0-standalone.html
* https://www.gnu.org/licenses/lgpl-3.0-standalone.html
*
*
*/

package love.forte.simboot.listener
Expand Down Expand Up @@ -72,10 +71,12 @@ public abstract class FunctionalBindableEventListener<R>(
*
* 默认情况下,如果结果是 [EventResult] 类型,则会直接返回, 否则通过 [EventResult.of] 转化为 [EventResult].
*
* 当 [result] == [Unit] 时,将其视为 `null`。
*
*/
protected open suspend fun resultProcess(result: R): EventResult {
return if (result is EventResult) result
else EventResult.of(result)
else EventResult.of(result.takeIf { it != Unit })
}

private val isOptional = caller.parameters.any { it.isOptional }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Copyright (c) 2022-2022 ForteScarlet <ForteScarlet@163.com>
*
* 本文件是 simply-robot ( simple robot的v3版本,因此亦可称为 simple-robot v3 、simbot v3 等) 的一部分。
* 本文件是 simply-robot (或称 simple-robot 3.x 、simbot 3.x ) 的一部分。
*
* simply-robot 是自由软件:你可以再分发之和/或依照由自由软件基金会发布的 GNU 通用公共许可证修改之,无论是版本 3 许可证,还是(按你的决定)任何以后版都可以。
*
Expand All @@ -12,7 +12,6 @@
* https://www.gnu.org/licenses/gpl-3.0-standalone.html
* https://www.gnu.org/licenses/lgpl-3.0-standalone.html
*
*
*/

package love.forte.simbot.core.event
Expand Down Expand Up @@ -186,7 +185,7 @@ public class SimpleListenerBuilder<E : Event>(public val target: Event.Key<E>) :

private fun setFunc(f: suspend EventListenerProcessingContext.(E) -> EventResult) {
if (this.func != null) {
throw SimbotIllegalStateException("Event handle can and can only be configured once")
throw SimbotIllegalStateException("Event handle must and must only be configured once")
}

func = f
Expand Down Expand Up @@ -242,7 +241,7 @@ public class SimpleListenerBuilder<E : Event>(public val target: Event.Key<E>) :
* handle { event: FooEvent -> // this: EventListenerProcessingContext
* process() // process function
*
* EventResult.defaults() // return default
* EventResult.invalid() // return default
* }
* }
* ```
Expand All @@ -261,7 +260,7 @@ public class SimpleListenerBuilder<E : Event>(public val target: Event.Key<E>) :
public inline fun process(crossinline func: suspend EventListenerProcessingContext.(E) -> Unit) {
handle {
func(it)
EventResult.defaults()
EventResult.invalid()
}
}

Expand Down

0 comments on commit e7f415c

Please sign in to comment.