Commit c62fbc06 authored by Him188's avatar Him188

Add `ListenerFilter.quoteReply`

parent ec0d7f44
...@@ -264,6 +264,21 @@ class MessageSubscribersBuilder<T : MessagePacket<*, *>>( ...@@ -264,6 +264,21 @@ class MessageSubscribersBuilder<T : MessagePacket<*, *>>(
executeAndReply(replier) 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<*, *>>( ...@@ -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 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) } fun replyContains(value: String, replier: MessageReplier<T>) = content({ value in it }) { replier(this) }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment