diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/subscribeMessages.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/subscribeMessages.kt index dac261adb..26945a705 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/subscribeMessages.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/subscribeMessages.kt @@ -264,6 +264,21 @@ class MessageSubscribersBuilder>( executeAndReply(replier) } } + + infix fun quoteReply(toReply: String): Listener { + return content(filter) { quoteReply(toReply) } + } + + infix fun quoteReply(message: Message): Listener { + return content(filter) { quoteReply(message) } + } + + infix fun quoteReply(replier: (@MessageDsl suspend T.(String) -> Any?)): Listener { + return content(filter) { + @Suppress("DSL_SCOPE_VIOLATION_WARNING") + executeAndQuoteReply(replier) + } + } } /** @@ -713,6 +728,17 @@ class MessageSubscribersBuilder>( } } + @PublishedApi + @Suppress("REDUNDANT_INLINE_SUSPEND_FUNCTION_TYPE") // false positive + internal suspend inline fun T.executeAndQuoteReply(replier: suspend T.(String) -> Any?) { + when (val message = replier(this, this.message.toString())) { + is Message -> this.quoteReply(message) + is Unit -> { + + } + else -> this.quoteReply(message.toString()) + } + } /* 易产生迷惑感 fun replyCase(equals: String, trim: Boolean = true, replier: MessageReplier) = case(equals, trim) { reply(replier(this)) } fun replyContains(value: String, replier: MessageReplier) = content({ value in it }) { replier(this) }