mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-09 01:30:17 +08:00
Fix compilation error
This commit is contained in:
parent
70dd71cb61
commit
936ed3fff9
@ -386,12 +386,15 @@ internal suspend inline fun <reified T : MessagePacket<*, *>, R> T.selectMessage
|
|||||||
val defaultListeners: MutableList<MessageListener<T, Any?>> = mutableListOf()
|
val defaultListeners: MutableList<MessageListener<T, Any?>> = mutableListOf()
|
||||||
|
|
||||||
if (isUnit) {
|
if (isUnit) {
|
||||||
|
// https://youtrack.jetbrains.com/issue/KT-37716
|
||||||
|
val outside = { filter: T.(String) -> Boolean, listener: MessageListener<T, Any?> ->
|
||||||
|
listeners += filter to listener
|
||||||
|
}
|
||||||
object : MessageSelectBuilderUnit<T, R>(
|
object : MessageSelectBuilderUnit<T, R>(
|
||||||
this@selectMessagesImpl,
|
this@selectMessagesImpl,
|
||||||
SELECT_MESSAGE_STUB,
|
SELECT_MESSAGE_STUB,
|
||||||
{ filter: T.(String) -> Boolean, listener: MessageListener<T, Any?> ->
|
outside
|
||||||
listeners += filter to listener
|
) {
|
||||||
}) {
|
|
||||||
override fun obtainCurrentCoroutineScope(): CoroutineScope = this@withTimeoutOrCoroutineScope
|
override fun obtainCurrentCoroutineScope(): CoroutineScope = this@withTimeoutOrCoroutineScope
|
||||||
override fun obtainCurrentDeferred(): CompletableDeferred<R>? = deferred
|
override fun obtainCurrentDeferred(): CompletableDeferred<R>? = deferred
|
||||||
override fun default(onEvent: MessageListener<T, R>) {
|
override fun default(onEvent: MessageListener<T, R>) {
|
||||||
@ -399,12 +402,15 @@ internal suspend inline fun <reified T : MessagePacket<*, *>, R> T.selectMessage
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// https://youtrack.jetbrains.com/issue/KT-37716
|
||||||
|
val outside = { filter: T.(String) -> Boolean, listener: MessageListener<T, Any?> ->
|
||||||
|
listeners += filter to listener
|
||||||
|
}
|
||||||
object : MessageSelectBuilder<T, R>(
|
object : MessageSelectBuilder<T, R>(
|
||||||
this@selectMessagesImpl,
|
this@selectMessagesImpl,
|
||||||
SELECT_MESSAGE_STUB,
|
SELECT_MESSAGE_STUB,
|
||||||
{ filter: T.(String) -> Boolean, listener: MessageListener<T, Any?> ->
|
outside
|
||||||
listeners += filter to listener
|
) {
|
||||||
}) {
|
|
||||||
override fun obtainCurrentCoroutineScope(): CoroutineScope = this@withTimeoutOrCoroutineScope
|
override fun obtainCurrentCoroutineScope(): CoroutineScope = this@withTimeoutOrCoroutineScope
|
||||||
override fun obtainCurrentDeferred(): CompletableDeferred<R>? = deferred
|
override fun obtainCurrentDeferred(): CompletableDeferred<R>? = deferred
|
||||||
override fun default(onEvent: MessageListener<T, R>) {
|
override fun default(onEvent: MessageListener<T, R>) {
|
||||||
@ -414,7 +420,7 @@ internal suspend inline fun <reified T : MessagePacket<*, *>, R> T.selectMessage
|
|||||||
}.apply(selectBuilder)
|
}.apply(selectBuilder)
|
||||||
|
|
||||||
// we don't have any way to reduce duplication yet,
|
// we don't have any way to reduce duplication yet,
|
||||||
// until local functions is supported in inline functions
|
// until local functions are supported in inline functions
|
||||||
@Suppress("DuplicatedCode")
|
@Suppress("DuplicatedCode")
|
||||||
subscribeAlways<T> { event ->
|
subscribeAlways<T> { event ->
|
||||||
if (!this.isContextIdenticalWith(this@selectMessagesImpl))
|
if (!this.isContextIdenticalWith(this@selectMessagesImpl))
|
||||||
@ -470,12 +476,15 @@ internal suspend inline fun <reified T : MessagePacket<*, *>> T.whileSelectMessa
|
|||||||
val listeners: MutableList<Pair<T.(String) -> Boolean, MessageListener<T, Any?>>> = mutableListOf()
|
val listeners: MutableList<Pair<T.(String) -> Boolean, MessageListener<T, Any?>>> = mutableListOf()
|
||||||
val defaltListeners: MutableList<MessageListener<T, Any?>> = mutableListOf()
|
val defaltListeners: MutableList<MessageListener<T, Any?>> = mutableListOf()
|
||||||
|
|
||||||
|
// https://youtrack.jetbrains.com/issue/KT-37716
|
||||||
|
val outside = { filter: T.(String) -> Boolean, listener: MessageListener<T, Any?> ->
|
||||||
|
listeners += filter to listener
|
||||||
|
}
|
||||||
object : MessageSelectBuilder<T, Boolean>(
|
object : MessageSelectBuilder<T, Boolean>(
|
||||||
this@whileSelectMessagesImpl,
|
this@whileSelectMessagesImpl,
|
||||||
SELECT_MESSAGE_STUB,
|
SELECT_MESSAGE_STUB,
|
||||||
{ filter: T.(String) -> Boolean, listener: MessageListener<T, Any?> ->
|
outside
|
||||||
listeners += filter to listener
|
) {
|
||||||
}) {
|
|
||||||
override fun obtainCurrentCoroutineScope(): CoroutineScope = this@withTimeoutOrCoroutineScope
|
override fun obtainCurrentCoroutineScope(): CoroutineScope = this@withTimeoutOrCoroutineScope
|
||||||
override fun obtainCurrentDeferred(): CompletableDeferred<Boolean>? = deferred
|
override fun obtainCurrentDeferred(): CompletableDeferred<Boolean>? = deferred
|
||||||
override fun default(onEvent: MessageListener<T, Boolean>) {
|
override fun default(onEvent: MessageListener<T, Boolean>) {
|
||||||
|
@ -33,7 +33,6 @@ import kotlin.coroutines.CoroutineContext
|
|||||||
import kotlin.coroutines.EmptyCoroutineContext
|
import kotlin.coroutines.EmptyCoroutineContext
|
||||||
import kotlin.js.JsName
|
import kotlin.js.JsName
|
||||||
import kotlin.jvm.JvmName
|
import kotlin.jvm.JvmName
|
||||||
import kotlin.jvm.JvmSynthetic
|
|
||||||
|
|
||||||
typealias MessagePacketSubscribersBuilder = MessageSubscribersBuilder<MessagePacket<*, *>, Listener<MessagePacket<*, *>>, Unit, Unit>
|
typealias MessagePacketSubscribersBuilder = MessageSubscribersBuilder<MessagePacket<*, *>, Listener<MessagePacket<*, *>>, Unit, Unit>
|
||||||
|
|
||||||
@ -260,7 +259,6 @@ typealias MessageListener<T, R> = @MessageDsl suspend T.(String) -> R
|
|||||||
* @param Ret 每个 DSL 函数创建监听器之后的返回值
|
* @param Ret 每个 DSL 函数创建监听器之后的返回值
|
||||||
*
|
*
|
||||||
* @see subscribeFriendMessages
|
* @see subscribeFriendMessages
|
||||||
* @sample demo.subscribe.messageDSL
|
|
||||||
*/
|
*/
|
||||||
@Suppress("unused", "DSL_SCOPE_VIOLATION_WARNING")
|
@Suppress("unused", "DSL_SCOPE_VIOLATION_WARNING")
|
||||||
@MessageDsl
|
@MessageDsl
|
||||||
@ -277,7 +275,7 @@ open class MessageSubscribersBuilder<M : MessagePacket<*, *>, out Ret, R : RR, R
|
|||||||
/**
|
/**
|
||||||
* 监听的条件
|
* 监听的条件
|
||||||
*/
|
*/
|
||||||
open inner class ListeningFilter @Deprecated(
|
open inner class ListeningFilter @Deprecated( // keep it for development warning
|
||||||
"use newListeningFilter instead",
|
"use newListeningFilter instead",
|
||||||
ReplaceWith("newListeningFilter(filter)"),
|
ReplaceWith("newListeningFilter(filter)"),
|
||||||
level = DeprecationLevel.ERROR
|
level = DeprecationLevel.ERROR
|
||||||
@ -314,93 +312,42 @@ open class MessageSubscribersBuilder<M : MessagePacket<*, *>, out Ret, R : RR, R
|
|||||||
fun not(): ListeningFilter =
|
fun not(): ListeningFilter =
|
||||||
newListeningFilter { !filter.invoke(this, it) }
|
newListeningFilter { !filter.invoke(this, it) }
|
||||||
|
|
||||||
|
|
||||||
@Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN)
|
|
||||||
internal open infix fun reply(toReply: String): Ret {
|
|
||||||
return content(filter) { reply(toReply);this@MessageSubscribersBuilder.stub }
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN)
|
|
||||||
internal open infix fun reply(message: Message): Ret {
|
|
||||||
return content(filter) { reply(message);this@MessageSubscribersBuilder.stub }
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN)
|
|
||||||
internal open infix fun reply(replier: (@MessageDsl suspend M.(String) -> Any?)): Ret {
|
|
||||||
return content(filter) {
|
|
||||||
this@MessageSubscribersBuilder.executeAndReply(this, replier)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN)
|
|
||||||
internal open infix fun quoteReply(toReply: String): Ret {
|
|
||||||
return content(filter) { quoteReply(toReply);this@MessageSubscribersBuilder.stub }
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN)
|
|
||||||
internal open infix fun quoteReply(message: Message): Ret {
|
|
||||||
return content(filter) { quoteReply(message);this@MessageSubscribersBuilder.stub }
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN)
|
|
||||||
internal open infix fun quoteReply(replier: (@MessageDsl suspend M.(String) -> Any?)): Ret {
|
|
||||||
return content(filter) {
|
|
||||||
@Suppress("DSL_SCOPE_VIOLATION_WARNING")
|
|
||||||
this@MessageSubscribersBuilder.executeAndQuoteReply(this, replier)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@JvmSynthetic
|
|
||||||
@Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN)
|
|
||||||
@JvmName("invoke")
|
|
||||||
internal fun invoke0(onEvent: MessageListener<M, R>): Listener<*> {
|
|
||||||
return content(filter, onEvent) as Listener<*>
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 启动事件监听.
|
* 启动事件监听.
|
||||||
*/
|
*/
|
||||||
@JvmName("invoke1")
|
|
||||||
// do not inline due to kotlin (1.3.61) bug: java.lang.IllegalAccessError
|
// do not inline due to kotlin (1.3.61) bug: java.lang.IllegalAccessError
|
||||||
operator fun invoke(onEvent: MessageListener<M, R>): Ret {
|
operator fun invoke(onEvent: MessageListener<M, R>): Ret {
|
||||||
return content(filter, onEvent)
|
return content(filter, onEvent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("EXTENSION_SHADOWED_BY_MEMBER") // binary compatibility
|
|
||||||
@SinceMirai("0.29.0")
|
@SinceMirai("0.29.0")
|
||||||
open infix fun ListeningFilter.reply(toReply: String): Ret {
|
open infix fun ListeningFilter.reply(toReply: String): Ret {
|
||||||
return content(filter) { reply(toReply);this@MessageSubscribersBuilder.stub }
|
return content(filter) { reply(toReply);this@MessageSubscribersBuilder.stub }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("EXTENSION_SHADOWED_BY_MEMBER") // binary compatibility
|
|
||||||
@SinceMirai("0.29.0")
|
@SinceMirai("0.29.0")
|
||||||
open infix fun ListeningFilter.reply(message: Message): Ret {
|
open infix fun ListeningFilter.reply(message: Message): Ret {
|
||||||
return content(filter) { reply(message);this@MessageSubscribersBuilder.stub }
|
return content(filter) { reply(message);this@MessageSubscribersBuilder.stub }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("EXTENSION_SHADOWED_BY_MEMBER") // binary compatibility
|
|
||||||
@SinceMirai("0.29.0")
|
@SinceMirai("0.29.0")
|
||||||
open infix fun ListeningFilter.reply(replier: (@MessageDsl suspend M.(String) -> Any?)): Ret {
|
open infix fun ListeningFilter.reply(replier: (@MessageDsl suspend M.(String) -> Any?)): Ret {
|
||||||
return content(filter) {
|
return content(filter) {
|
||||||
@Suppress("DSL_SCOPE_VIOLATION_WARNING")
|
|
||||||
this@MessageSubscribersBuilder.executeAndReply(this, replier)
|
this@MessageSubscribersBuilder.executeAndReply(this, replier)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("EXTENSION_SHADOWED_BY_MEMBER") // binary compatibility
|
|
||||||
@SinceMirai("0.29.0")
|
@SinceMirai("0.29.0")
|
||||||
open infix fun ListeningFilter.quoteReply(toReply: String): Ret {
|
open infix fun ListeningFilter.quoteReply(toReply: String): Ret {
|
||||||
return content(filter) { quoteReply(toReply);this@MessageSubscribersBuilder.stub }
|
return content(filter) { quoteReply(toReply);this@MessageSubscribersBuilder.stub }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("EXTENSION_SHADOWED_BY_MEMBER") // binary compatibility
|
|
||||||
@SinceMirai("0.29.0")
|
@SinceMirai("0.29.0")
|
||||||
open infix fun ListeningFilter.quoteReply(message: Message): Ret {
|
open infix fun ListeningFilter.quoteReply(message: Message): Ret {
|
||||||
return content(filter) { quoteReply(message);this@MessageSubscribersBuilder.stub }
|
return content(filter) { quoteReply(message);this@MessageSubscribersBuilder.stub }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("EXTENSION_SHADOWED_BY_MEMBER") // binary compatibility
|
|
||||||
@SinceMirai("0.29.0")
|
@SinceMirai("0.29.0")
|
||||||
open infix fun ListeningFilter.quoteReply(replier: (@MessageDsl suspend M.(String) -> Any?)): Ret {
|
open infix fun ListeningFilter.quoteReply(replier: (@MessageDsl suspend M.(String) -> Any?)): Ret {
|
||||||
return content(filter) {
|
return content(filter) {
|
||||||
@ -440,7 +387,7 @@ open class MessageSubscribersBuilder<M : MessagePacket<*, *>, out Ret, R : RR, R
|
|||||||
@JvmName("case1")
|
@JvmName("case1")
|
||||||
@JsName("case1")
|
@JsName("case1")
|
||||||
@SinceMirai("0.29.0")
|
@SinceMirai("0.29.0")
|
||||||
@Suppress("INVALID_CHARACTERS", "NAME_CONTAINS_ILLEGAL_CHARS")
|
@Suppress("INVALID_CHARACTERS", "NAME_CONTAINS_ILLEGAL_CHARS", "FunctionName")
|
||||||
infix fun String.`->`(block: MessageListener<M, R>): Ret {
|
infix fun String.`->`(block: MessageListener<M, R>): Ret {
|
||||||
return case(this, onEvent = block)
|
return case(this, onEvent = block)
|
||||||
}
|
}
|
||||||
@ -739,7 +686,7 @@ open class MessageSubscribersBuilder<M : MessagePacket<*, *>, out Ret, R : RR, R
|
|||||||
@MessageDsl
|
@MessageDsl
|
||||||
@SinceMirai("0.30.0")
|
@SinceMirai("0.30.0")
|
||||||
inline fun <reified N : Message> has(noinline onEvent: @MessageDsl suspend M.(N) -> R): Ret =
|
inline fun <reified N : Message> has(noinline onEvent: @MessageDsl suspend M.(N) -> R): Ret =
|
||||||
content({ message.any { it is N } }, { onEvent.invoke(this, message.first<N>()) })
|
content({ message.any { it is N } }, { onEvent.invoke(this, message.first()) })
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 如果 [mapper] 返回值非空, 就执行 [onEvent]
|
* 如果 [mapper] 返回值非空, 就执行 [onEvent]
|
||||||
@ -973,41 +920,4 @@ open class MessageSubscribersBuilder<M : MessagePacket<*, *>, out Ret, R : RR, R
|
|||||||
@Retention(AnnotationRetention.SOURCE)
|
@Retention(AnnotationRetention.SOURCE)
|
||||||
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.CLASS, AnnotationTarget.TYPE)
|
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.CLASS, AnnotationTarget.TYPE)
|
||||||
@DslMarker
|
@DslMarker
|
||||||
annotation class MessageDsl
|
annotation class MessageDsl
|
||||||
|
|
||||||
|
|
||||||
@Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN)
|
|
||||||
fun <R> CoroutineScope.subscribeMessages(
|
|
||||||
coroutineContext: CoroutineContext = EmptyCoroutineContext,
|
|
||||||
listeners: MessagePacketSubscribersBuilder.() -> R
|
|
||||||
): R = subscribeMessages(coroutineContext, listeners = listeners)
|
|
||||||
|
|
||||||
@Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN)
|
|
||||||
fun <R> CoroutineScope.subscribeGroupMessages(
|
|
||||||
coroutineContext: CoroutineContext = EmptyCoroutineContext,
|
|
||||||
listeners: GroupMessageSubscribersBuilder.() -> R
|
|
||||||
): R = subscribeGroupMessages(coroutineContext, listeners = listeners)
|
|
||||||
|
|
||||||
@Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN)
|
|
||||||
fun <R> CoroutineScope.subscribeFriendMessages(
|
|
||||||
coroutineContext: CoroutineContext = EmptyCoroutineContext,
|
|
||||||
listeners: FriendMessageSubscribersBuilder.() -> R
|
|
||||||
): R = subscribeFriendMessages(coroutineContext, listeners = listeners)
|
|
||||||
|
|
||||||
@Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN)
|
|
||||||
fun <R> Bot.subscribeMessages(
|
|
||||||
coroutineContext: CoroutineContext = EmptyCoroutineContext,
|
|
||||||
listeners: MessagePacketSubscribersBuilder.() -> R
|
|
||||||
): R = subscribeMessages(coroutineContext, listeners = listeners)
|
|
||||||
|
|
||||||
@Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN)
|
|
||||||
fun <R> Bot.subscribeGroupMessages(
|
|
||||||
coroutineContext: CoroutineContext = EmptyCoroutineContext,
|
|
||||||
listeners: GroupMessageSubscribersBuilder.() -> R
|
|
||||||
): R = subscribeGroupMessages(coroutineContext, listeners = listeners)
|
|
||||||
|
|
||||||
@Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN)
|
|
||||||
fun <R> Bot.subscribeFriendMessages(
|
|
||||||
coroutineContext: CoroutineContext = EmptyCoroutineContext,
|
|
||||||
listeners: FriendMessageSubscribersBuilder.() -> R
|
|
||||||
): R = subscribeFriendMessages(coroutineContext, listeners = listeners)
|
|
Loading…
Reference in New Issue
Block a user