mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-09 01:30:17 +08:00
Add ListenerFilter.quoteReply
This commit is contained in:
parent
ec0d7f4434
commit
c62fbc062a
@ -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) }
|
||||
|
Loading…
Reference in New Issue
Block a user