Add ListenerFilter.quoteReply

This commit is contained in:
Him188 2020-02-25 09:02:02 +08:00
parent ec0d7f4434
commit c62fbc062a

View File

@ -264,6 +264,21 @@ class MessageSubscribersBuilder<T : MessagePacket<*, *>>(
executeAndReply(replier)
}
}
infix fun quoteReply(toReply: String): Listener<T> {
return content(filter) { quoteReply(toReply) }
}
infix fun quoteReply(message: Message): Listener<T> {
return content(filter) { quoteReply(message) }
}
infix fun quoteReply(replier: (@MessageDsl suspend T.(String) -> Any?)): Listener<T> {
return content(filter) {
@Suppress("DSL_SCOPE_VIOLATION_WARNING")
executeAndQuoteReply(replier)
}
}
}
/**
@ -713,6 +728,17 @@ class MessageSubscribersBuilder<T : MessagePacket<*, *>>(
}
}
@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<T>) = case(equals, trim) { reply(replier(this)) }
fun replyContains(value: String, replier: MessageReplier<T>) = content({ value in it }) { replier(this) }