diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/MessagePacket.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/MessagePacket.kt index b5ea0dac6..b8c3eb8fc 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/MessagePacket.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/MessagePacket.kt @@ -166,4 +166,21 @@ suspend inline fun > P.nextMessage( return subscribingGet(timeoutMillis) { takeIf { this.isContextIdenticalWith(this@nextMessage) }?.takeIf { filter(it, it) } } +} + +/** + * 挂起当前协程, 等待下一条 [MessagePacket.sender] 和 [MessagePacket.subject] 与 [P] 相同的 [MessagePacket] + * + * 若 [filter] 抛出了一个异常, 本函数会立即抛出这个异常. + * + * @param timeoutMillis 超时. 单位为毫秒. `-1` 为不限制 + * + * @see subscribingGetAsync 本函数的异步版本 + */ +suspend inline fun > P.nextMessage( + timeoutMillis: Long = -1 +): P { + return subscribingGet(timeoutMillis) { + takeIf { this.isContextIdenticalWith(this@nextMessage) } + } } \ No newline at end of file