Commit d8e262c5 authored by Him188's avatar Him188

Binary compatibility, fix #155

parent 1f60474c
......@@ -35,6 +35,14 @@ fun <L : Listener<E>, E : Event> KClass<out E>.subscribeInternal(listener: L): L
return listener
}
@PublishedApi
@Suppress("FunctionName", "unused")
@Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN)
internal fun <E : Event> CoroutineScope.Handler(
coroutineContext: CoroutineContext,
handler: suspend (E) -> ListeningStatus
): Handler<E> = Handler(coroutineContext, concurrencyKind = Listener.ConcurrencyKind.LOCKED, handler = handler)
@PublishedApi
@Suppress("FunctionName")
internal fun <E : Event> CoroutineScope.Handler(
......@@ -60,12 +68,22 @@ internal class Handler<in E : Event>
) :
Listener<E>, CompletableJob by Job(parentJob) {
@Suppress("unused")
@Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN)
@PublishedApi
internal constructor(
parentJob: Job?,
subscriberContext: CoroutineContext,
handler: suspend (E) -> ListeningStatus
) : this(parentJob, subscriberContext, handler, Listener.ConcurrencyKind.LOCKED)
@MiraiInternalAPI
val lock: Mutex? = when (concurrencyKind) {
Listener.ConcurrencyKind.CONCURRENT -> null
Listener.ConcurrencyKind.LOCKED -> Mutex()
}
@Suppress("unused")
@OptIn(MiraiDebugAPI::class)
override suspend fun onEvent(event: E): ListeningStatus {
if (isCompleted || isCancelled) return ListeningStatus.STOPPED
......@@ -80,8 +98,7 @@ internal class Handler<in E : Event>
@Suppress("DEPRECATION")
MiraiLogger.warning(
"""Event processing: An exception occurred but no CoroutineExceptionHandler found,
either in coroutineContext from Handler job, or in subscriberContext""".trimIndent()
, e
either in coroutineContext from Handler job, or in subscriberContext""".trimIndent(), e
)
}
// this.complete() // do not `completeExceptionally`, otherwise parentJob will fai`l.
......
......@@ -270,7 +270,7 @@ open class MessageSubscribersBuilder<M : MessagePacket<*, *>, out Ret, R : RR, R
*/
val subscriber: (M.(String) -> Boolean, MessageListener<M, RR>) -> Ret
) {
@Suppress("DEPRECATION")
@Suppress("DEPRECATION_ERROR")
open fun newListeningFilter(filter: M.(String) -> Boolean): ListeningFilter = ListeningFilter(filter)
/**
......@@ -278,7 +278,8 @@ open class MessageSubscribersBuilder<M : MessagePacket<*, *>, out Ret, R : RR, R
*/
open inner class ListeningFilter @Deprecated(
"use newListeningFilter instead",
ReplaceWith("newListeningFilter(filter)")
ReplaceWith("newListeningFilter(filter)"),
level = DeprecationLevel.ERROR
) constructor(
val filter: M.(String) -> Boolean
) {
......@@ -312,6 +313,43 @@ open class MessageSubscribersBuilder<M : MessagePacket<*, *>, out Ret, R : RR, R
fun not(): ListeningFilter =
newListeningFilter { !filter.invoke(this, it) }
@Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN)
open infix fun reply(toReply: String): Ret {
return content(filter) { reply(toReply);stub }
}
@Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN)
open infix fun reply(message: Message): Ret {
return content(filter) { reply(message);stub }
}
@Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN)
open infix fun reply(replier: (@MessageDsl suspend M.(String) -> Any?)): Ret {
return content(filter) {
@Suppress("DSL_SCOPE_VIOLATION_WARNING")
executeAndReply(replier)
}
}
@Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN)
open infix fun quoteReply(toReply: String): Ret {
return content(filter) { quoteReply(toReply);stub }
}
@Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN)
open infix fun quoteReply(message: Message): Ret {
return content(filter) { quoteReply(message);stub }
}
@Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN)
open infix fun quoteReply(replier: (@MessageDsl suspend M.(String) -> Any?)): Ret {
return content(filter) {
@Suppress("DSL_SCOPE_VIOLATION_WARNING")
executeAndQuoteReply(replier)
}
}
/**
* 启动事件监听.
*/
......@@ -321,16 +359,19 @@ open class MessageSubscribersBuilder<M : MessagePacket<*, *>, out Ret, R : RR, R
}
}
@Suppress("EXTENSION_SHADOWED_BY_MEMBER") // binary compatibility
@SinceMirai("0.29.0")
open infix fun ListeningFilter.reply(toReply: String): Ret {
return content(filter) { reply(toReply);stub }
}
@Suppress("EXTENSION_SHADOWED_BY_MEMBER") // binary compatibility
@SinceMirai("0.29.0")
open infix fun ListeningFilter.reply(message: Message): Ret {
return content(filter) { reply(message);stub }
}
@Suppress("EXTENSION_SHADOWED_BY_MEMBER") // binary compatibility
@SinceMirai("0.29.0")
open infix fun ListeningFilter.reply(replier: (@MessageDsl suspend M.(String) -> Any?)): Ret {
return content(filter) {
......@@ -339,16 +380,19 @@ open class MessageSubscribersBuilder<M : MessagePacket<*, *>, out Ret, R : RR, R
}
}
@Suppress("EXTENSION_SHADOWED_BY_MEMBER") // binary compatibility
@SinceMirai("0.29.0")
open infix fun ListeningFilter.quoteReply(toReply: String): Ret {
return content(filter) { quoteReply(toReply);stub }
}
@Suppress("EXTENSION_SHADOWED_BY_MEMBER") // binary compatibility
@SinceMirai("0.29.0")
open infix fun ListeningFilter.quoteReply(message: Message): Ret {
return content(filter) { quoteReply(message);stub }
}
@Suppress("EXTENSION_SHADOWED_BY_MEMBER") // binary compatibility
@SinceMirai("0.29.0")
open infix fun ListeningFilter.quoteReply(replier: (@MessageDsl suspend M.(String) -> Any?)): Ret {
return content(filter) {
......@@ -914,4 +958,41 @@ open class MessageSubscribersBuilder<M : MessagePacket<*, *>, out Ret, R : RR, R
@Retention(AnnotationRetention.SOURCE)
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.CLASS, AnnotationTarget.TYPE)
@DslMarker
annotation class MessageDsl
\ No newline at end of file
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)
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