mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-03 06:26:59 +08:00
Kotlin 1.5 and dependencies updates (#1246)
* Kotlin 1.5 and dependencies updates * Update mirai-console ref * Use Kotlin 1.5.10 * 2.7-M1-dev-3 * Update console ref
This commit is contained in:
parent
5e25c0e25b
commit
bcdff1336b
@ -510,8 +510,8 @@ public final class net/mamoe/mirai/contact/NormalMemberKt {
|
||||
public static final fun getNameCardOrNick (Lnet/mamoe/mirai/contact/User;)Ljava/lang/String;
|
||||
public static final fun getNameCardOrNick (Lnet/mamoe/mirai/contact/UserOrBot;)Ljava/lang/String;
|
||||
public static final fun isMuted (Lnet/mamoe/mirai/contact/NormalMember;)Z
|
||||
public static final fun mute-8Mi8wO0 (Lnet/mamoe/mirai/contact/NormalMember;DLkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
public static final synthetic fun mute-fcu0wV4 (Lnet/mamoe/mirai/contact/NormalMember;DLkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
public static final fun mute-8Mi8wO0 (Lnet/mamoe/mirai/contact/NormalMember;JLkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
public static final synthetic fun mute-fcu0wV4 (Lnet/mamoe/mirai/contact/NormalMember;JLkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
}
|
||||
|
||||
public abstract interface class net/mamoe/mirai/contact/OtherClient : net/mamoe/mirai/contact/Contact {
|
||||
@ -5519,6 +5519,7 @@ public final class net/mamoe/mirai/network/ForceOfflineException : java/util/con
|
||||
}
|
||||
|
||||
public abstract class net/mamoe/mirai/network/LoginFailedException : java/lang/RuntimeException {
|
||||
public synthetic fun <init> (ZLjava/lang/String;Ljava/lang/Throwable;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
|
||||
public synthetic fun <init> (ZLjava/lang/String;Ljava/lang/Throwable;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
|
||||
public final fun getKillBot ()Z
|
||||
}
|
||||
@ -5641,11 +5642,11 @@ public final class net/mamoe/mirai/utils/BotConfiguration$ContactListCache {
|
||||
public fun <init> ()V
|
||||
public final fun getFriendListCacheEnabled ()Z
|
||||
public final fun getGroupMemberListCacheEnabled ()Z
|
||||
public final synthetic fun getSaveInterval-UwyO8pc ()D
|
||||
public final synthetic fun getSaveInterval-UwyO8pc ()J
|
||||
public final fun getSaveIntervalMillis ()J
|
||||
public final fun setFriendListCacheEnabled (Z)V
|
||||
public final fun setGroupMemberListCacheEnabled (Z)V
|
||||
public final synthetic fun setSaveInterval-LRDsOJo (D)V
|
||||
public final synthetic fun setSaveInterval-LRDsOJo (J)V
|
||||
public final fun setSaveIntervalMillis (J)V
|
||||
}
|
||||
|
||||
|
@ -510,8 +510,8 @@ public final class net/mamoe/mirai/contact/NormalMemberKt {
|
||||
public static final fun getNameCardOrNick (Lnet/mamoe/mirai/contact/User;)Ljava/lang/String;
|
||||
public static final fun getNameCardOrNick (Lnet/mamoe/mirai/contact/UserOrBot;)Ljava/lang/String;
|
||||
public static final fun isMuted (Lnet/mamoe/mirai/contact/NormalMember;)Z
|
||||
public static final fun mute-8Mi8wO0 (Lnet/mamoe/mirai/contact/NormalMember;DLkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
public static final synthetic fun mute-fcu0wV4 (Lnet/mamoe/mirai/contact/NormalMember;DLkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
public static final fun mute-8Mi8wO0 (Lnet/mamoe/mirai/contact/NormalMember;JLkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
public static final synthetic fun mute-fcu0wV4 (Lnet/mamoe/mirai/contact/NormalMember;JLkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
}
|
||||
|
||||
public abstract interface class net/mamoe/mirai/contact/OtherClient : net/mamoe/mirai/contact/Contact {
|
||||
@ -5519,6 +5519,7 @@ public final class net/mamoe/mirai/network/ForceOfflineException : java/util/con
|
||||
}
|
||||
|
||||
public abstract class net/mamoe/mirai/network/LoginFailedException : java/lang/RuntimeException {
|
||||
public synthetic fun <init> (ZLjava/lang/String;Ljava/lang/Throwable;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
|
||||
public synthetic fun <init> (ZLjava/lang/String;Ljava/lang/Throwable;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
|
||||
public final fun getKillBot ()Z
|
||||
}
|
||||
@ -5641,11 +5642,11 @@ public final class net/mamoe/mirai/utils/BotConfiguration$ContactListCache {
|
||||
public fun <init> ()V
|
||||
public final fun getFriendListCacheEnabled ()Z
|
||||
public final fun getGroupMemberListCacheEnabled ()Z
|
||||
public final synthetic fun getSaveInterval-UwyO8pc ()D
|
||||
public final synthetic fun getSaveInterval-UwyO8pc ()J
|
||||
public final fun getSaveIntervalMillis ()J
|
||||
public final fun setFriendListCacheEnabled (Z)V
|
||||
public final fun setGroupMemberListCacheEnabled (Z)V
|
||||
public final synthetic fun setSaveInterval-LRDsOJo (D)V
|
||||
public final synthetic fun setSaveInterval-LRDsOJo (J)V
|
||||
public final fun setSaveIntervalMillis (J)V
|
||||
}
|
||||
|
||||
|
@ -31,9 +31,11 @@ fun Project.configureJvmTarget() {
|
||||
val defaultVer = JavaVersion.VERSION_1_8
|
||||
|
||||
tasks.withType(KotlinJvmCompile::class.java) {
|
||||
kotlinOptions.languageVersion = "1.4"
|
||||
kotlinOptions.languageVersion = "1.5"
|
||||
kotlinOptions.jvmTarget = defaultVer.toString()
|
||||
kotlinOptions.freeCompilerArgs += "-Xjvm-default=all"
|
||||
kotlinOptions.freeCompilerArgs += "-XXLanguage:-JvmIrEnabledByDefault"
|
||||
// TODO: 2021/5/6 We are still using legacy JVM backend since kotlinx.serialization is not yet supported in Kotlin 1.5.0
|
||||
}
|
||||
|
||||
extensions.findByType(JavaPluginExtension::class.java)?.run {
|
||||
|
@ -12,20 +12,20 @@
|
||||
import org.gradle.api.attributes.Attribute
|
||||
|
||||
object Versions {
|
||||
const val project = "2.6.4"
|
||||
const val project = "2.7-M1-dev-3"
|
||||
|
||||
const val core = project
|
||||
const val console = project
|
||||
const val consoleTerminal = project
|
||||
|
||||
const val kotlinCompiler = "1.4.30"
|
||||
const val kotlinStdlib = "1.4.30"
|
||||
const val dokka = "1.4.20"
|
||||
const val kotlinCompiler = "1.5.10"
|
||||
const val kotlinStdlib = "1.5.10"
|
||||
const val dokka = "1.4.32"
|
||||
|
||||
const val coroutines = "1.4.2"
|
||||
const val atomicFU = "0.15.1"
|
||||
const val coroutines = "1.5.0"
|
||||
const val atomicFU = "0.16.1"
|
||||
const val serialization = "1.1.0"
|
||||
const val ktor = "1.5.1"
|
||||
const val ktor = "1.5.4"
|
||||
|
||||
const val binaryValidator = "0.4.0"
|
||||
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 410cdd02efaa70ed5a64603d121c44fd4f952985
|
||||
Subproject commit 19abf48aac4ad0eed63fd721ae9723f0686097d5
|
@ -21,7 +21,7 @@ import net.mamoe.mirai.Bot
|
||||
* @see Contact
|
||||
* @see Bot
|
||||
*/
|
||||
public interface ContactOrBot : CoroutineScope { // TODO: 2021/1/10 Make sealed interface in Kotlin 1.5
|
||||
public interface ContactOrBot : CoroutineScope {
|
||||
/**
|
||||
* QQ 号或群号.
|
||||
*/
|
||||
|
@ -492,8 +492,9 @@ public abstract class MessageSelectBuilderUnit<M : MessageEvent, R> @PublishedAp
|
||||
protected abstract fun obtainCurrentDeferred(): CompletableDeferred<R>?
|
||||
}
|
||||
|
||||
@JvmInline
|
||||
@Suppress("NON_PUBLIC_PRIMARY_CONSTRUCTOR_OF_INLINE_CLASS")
|
||||
public inline class MessageSelectionTimeoutChecker internal constructor(public val timeoutMillis: Long)
|
||||
public value class MessageSelectionTimeoutChecker internal constructor(public val timeoutMillis: Long)
|
||||
|
||||
public class MessageSelectionTimeoutException : RuntimeException()
|
||||
|
||||
|
@ -37,8 +37,10 @@ public class AsyncRecallResult internal constructor(
|
||||
* 撤回是否成功. Kotlin [Deferred] API.
|
||||
*/
|
||||
public val isSuccess: Deferred<Boolean> by lazy {
|
||||
GlobalScope.async {
|
||||
kotlin.runCatching { exception.await() == null }.getOrElse { false }
|
||||
CompletableDeferred<Boolean>().apply {
|
||||
exception.invokeOnCompletion {
|
||||
complete(it == null)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -130,7 +130,7 @@ import kotlin.internal.LowPriorityInOverloadResolution
|
||||
*
|
||||
* @suppress **注意:** [Message] 类型大多有隐藏的协议实现, 不能被第三方应用继承.
|
||||
*/
|
||||
public interface Message { // TODO: 2021/1/10 Make sealed interface in Kotlin 1.5
|
||||
public interface Message {
|
||||
|
||||
/**
|
||||
* 得到包含 mirai 消息元素代码的, 易读的字符串. 如 `At(member) + "test"` 将转为 `"[mirai:at:qqId]test"`.
|
||||
|
@ -184,8 +184,8 @@ import kotlin.streams.asSequence
|
||||
*
|
||||
*/
|
||||
@Serializable(MessageChain.Serializer::class)
|
||||
public interface MessageChain :
|
||||
Message, List<SingleMessage>, RandomAccess, CodableMessage { // TODO: 2021/1/10 Make sealed interface in Kotlin 1.5
|
||||
public sealed interface MessageChain :
|
||||
Message, List<SingleMessage>, RandomAccess, CodableMessage {
|
||||
|
||||
/**
|
||||
* 获取第一个类型为 [key] 的 [Message] 实例. 若不存在此实例, 返回 `null`.
|
||||
@ -519,8 +519,9 @@ public inline operator fun <reified T : SingleMessage> MessageChain.getValue(thi
|
||||
* 可空的委托
|
||||
* @see orNull
|
||||
*/
|
||||
@JvmInline
|
||||
@Suppress("NON_PUBLIC_PRIMARY_CONSTRUCTOR_OF_INLINE_CLASS")
|
||||
public inline class OrNullDelegate<out R> @PublishedApi internal constructor(@JvmField @PublishedApi internal val value: Any?) {
|
||||
public value class OrNullDelegate<out R> @PublishedApi internal constructor(@JvmField @PublishedApi internal val value: Any?) {
|
||||
@Suppress("UNCHECKED_CAST") // don't inline, IC error
|
||||
public operator fun getValue(thisRef: Any?, property: KProperty<*>): R = value as R
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ import net.mamoe.mirai.utils.safeCast
|
||||
* 单个消息元素. 与之相对的是 [MessageChain], 是多个 [SingleMessage] 的集合.
|
||||
*/
|
||||
// @Serializable(SingleMessage.Serializer::class)
|
||||
public interface SingleMessage : Message { // TODO: 2021/1/10 Make sealed interface in Kotlin 1.5
|
||||
public interface SingleMessage : Message {
|
||||
|
||||
/**
|
||||
* @suppress deprecated since 2.4.0
|
||||
@ -59,7 +59,7 @@ public interface SingleMessage : Message { // TODO: 2021/1/10 Make sealed interf
|
||||
*
|
||||
* @see ConstrainSingle 约束一个 [MessageChain] 中只存在这一种类型的元素
|
||||
*/
|
||||
public interface MessageMetadata : SingleMessage { // TODO: 2021/1/10 Make sealed interface in Kotlin 1.5
|
||||
public interface MessageMetadata : SingleMessage {
|
||||
/**
|
||||
* 返回空字符串
|
||||
*/
|
||||
@ -82,7 +82,7 @@ public interface MessageMetadata : SingleMessage { // TODO: 2021/1/10 Make seale
|
||||
* @see MarketFace 商城表情
|
||||
* @see MusicShare 音乐分享
|
||||
*/
|
||||
public interface MessageContent : SingleMessage { // TODO: 2021/1/10 Make sealed interface in Kotlin 1.5
|
||||
public interface MessageContent : SingleMessage {
|
||||
public companion object Key : AbstractMessageKey<MessageContent>({ it.safeCast() })
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,6 @@ import kotlin.coroutines.EmptyCoroutineContext
|
||||
import kotlin.coroutines.coroutineContext
|
||||
import kotlin.time.Duration
|
||||
import kotlin.time.ExperimentalTime
|
||||
import kotlin.time.milliseconds
|
||||
|
||||
/**
|
||||
* [Bot] 配置. 用于 [BotFactory.newBot]
|
||||
@ -471,9 +470,9 @@ public open class BotConfiguration { // open for Java
|
||||
*/
|
||||
@ExperimentalTime
|
||||
public inline var saveInterval: Duration
|
||||
@JvmSynthetic inline get() = saveIntervalMillis.milliseconds
|
||||
@JvmSynthetic inline get() = Duration.milliseconds(saveIntervalMillis)
|
||||
@JvmSynthetic inline set(v) {
|
||||
saveIntervalMillis = v.toLongMilliseconds()
|
||||
saveIntervalMillis = v.inWholeMilliseconds
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -391,7 +391,7 @@ public interface RemoteFile {
|
||||
public fun SendChannel<Long>.asProgressionCallback(closeOnFinish: Boolean = true): ProgressionCallback {
|
||||
return object : ProgressionCallback {
|
||||
override fun onProgression(file: RemoteFile, resource: ExternalResource, downloadedSize: Long) {
|
||||
offer(downloadedSize)
|
||||
trySend(downloadedSize)
|
||||
}
|
||||
|
||||
override fun onSuccess(file: RemoteFile, resource: ExternalResource) {
|
||||
|
@ -38,11 +38,11 @@ internal class TimeTest {
|
||||
val time0 = (1.toDuration(DurationUnit.DAYS) +
|
||||
20.toDuration(DurationUnit.HOURS) +
|
||||
15.toDuration(DurationUnit.MINUTES) +
|
||||
2057.toDuration(DurationUnit.MILLISECONDS)).toLongMilliseconds()
|
||||
2057.toDuration(DurationUnit.MILLISECONDS)).inWholeMilliseconds
|
||||
|
||||
println(time0.millisToHumanReadableString())
|
||||
assertTrue { time0.millisToHumanReadableString() == "1d 20h 15min 2.057s" }
|
||||
val time1 = (1.toDuration(DurationUnit.DAYS) + 59.toDuration(DurationUnit.MINUTES)).toLongMilliseconds()
|
||||
val time1 = (1.toDuration(DurationUnit.DAYS) + 59.toDuration(DurationUnit.MINUTES)).inWholeMilliseconds
|
||||
println(time1.millisToHumanReadableString())
|
||||
assertTrue { time1.millisToHumanReadableString() == "1d 59min 0.0s" }
|
||||
}
|
||||
|
@ -10,9 +10,7 @@
|
||||
|
||||
package net.mamoe.mirai.utils
|
||||
|
||||
import kotlinx.coroutines.CoroutineName
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.io.ByteWriteChannel
|
||||
import kotlinx.coroutines.io.close
|
||||
import kotlinx.coroutines.io.jvm.nio.copyTo
|
||||
@ -20,7 +18,6 @@ import kotlinx.coroutines.io.reader
|
||||
import kotlinx.coroutines.io.writeFully
|
||||
import kotlinx.coroutines.sync.Mutex
|
||||
import kotlinx.coroutines.sync.withLock
|
||||
import kotlinx.coroutines.withContext
|
||||
import net.mamoe.mirai.Bot
|
||||
import net.mamoe.mirai.internal.utils.SeleniumLoginSolver
|
||||
import net.mamoe.mirai.internal.utils.isSliderCaptchaSupportKind
|
||||
@ -224,6 +221,7 @@ public class StandardCharImageLoginSolver @JvmOverloads constructor(
|
||||
}
|
||||
|
||||
// Copied from Ktor CIO
|
||||
@OptIn(DelicateCoroutinesApi::class)
|
||||
private fun File.writeChannel(
|
||||
coroutineContext: CoroutineContext = Dispatchers.IO
|
||||
): ByteWriteChannel = GlobalScope.reader(CoroutineName("file-writer") + coroutineContext, autoFlush = true) {
|
||||
|
@ -10,7 +10,6 @@
|
||||
package net.mamoe.mirai.event
|
||||
|
||||
import kotlinx.coroutines.*
|
||||
import net.mamoe.mirai.internal.event.GlobalEventListeners
|
||||
import net.mamoe.mirai.utils.StepUtil
|
||||
import org.junit.jupiter.api.AfterEach
|
||||
import java.util.concurrent.Executor
|
||||
@ -47,7 +46,7 @@ class EventTests {
|
||||
fun testSubscribeGlobalScope() {
|
||||
resetEventListeners()
|
||||
runBlocking {
|
||||
val listener = GlobalScope.globalEventChannel().subscribeAlways<TestEvent> {
|
||||
val listener = globalEventChannel().subscribeAlways<TestEvent> {
|
||||
triggered = true
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,6 @@ package net.mamoe.mirai.utils
|
||||
|
||||
import kotlinx.io.charsets.Charset
|
||||
import kotlinx.io.core.ByteReadPacket
|
||||
import java.util.*
|
||||
import kotlin.contracts.InvocationKind
|
||||
import kotlin.contracts.contract
|
||||
|
||||
@ -69,8 +68,8 @@ public operator fun ByteArray.get(rangeStart: Int, rangeEnd: Int): String = buil
|
||||
|
||||
private fun Byte.fixToString(): String {
|
||||
return when (val b = this.toInt() and 0xff) {
|
||||
in 0..15 -> "0${this.toString(16).toUpperCase()}"
|
||||
else -> b.toString(16).toUpperCase()
|
||||
in 0..15 -> "0${this.toString(16).uppercase()}"
|
||||
else -> b.toString(16).uppercase()
|
||||
}
|
||||
}
|
||||
|
||||
@ -90,7 +89,7 @@ public fun ByteArray.toUHexString(
|
||||
return buildString(length * 2) {
|
||||
this@toUHexString.forEachIndexed { index, it ->
|
||||
if (index in offset until lastIndex) {
|
||||
var ret = it.toUByte().toString(16).toUpperCase()
|
||||
var ret = it.toUByte().toString(16).uppercase()
|
||||
if (ret.length == 1) ret = "0$ret"
|
||||
append(ret)
|
||||
if (index < lastIndex - 1) append(separator)
|
||||
@ -120,7 +119,7 @@ public fun List<Byte>.toUHexString(separator: String = " ", offset: Int = 0, len
|
||||
return buildString(length * 2) {
|
||||
this@toUHexString.forEachIndexed { index, it ->
|
||||
if (index in offset until lastIndex) {
|
||||
var ret = it.toUByte().toString(16).toUpperCase()
|
||||
var ret = it.toUByte().toString(16).uppercase()
|
||||
if (ret.length == 1) ret = "0$ret"
|
||||
append(ret)
|
||||
if (index < lastIndex - 1) append(separator)
|
||||
@ -140,7 +139,7 @@ public fun UByteArray.toUHexString(separator: String = " ", offset: Int = 0, len
|
||||
return buildString(length * 2) {
|
||||
this@toUHexString.forEachIndexed { index, it ->
|
||||
if (index in offset until lastIndex) {
|
||||
var ret = it.toByte().toUByte().toString(16).toUpperCase()
|
||||
var ret = it.toByte().toUByte().toString(16).uppercase()
|
||||
if (ret.length == 1) ret = "0$ret"
|
||||
append(ret)
|
||||
if (index < lastIndex - 1) append(separator)
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Mamoe Technologies and contributors.
|
||||
* Copyright 2019-2021 Mamoe Technologies and contributors.
|
||||
*
|
||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||
@ -113,7 +113,7 @@ public fun Byte.fixToUHex(): String = this.toUByte().fixToUHex()
|
||||
* 转无符号十六进制表示, 并补充首位 `0`.
|
||||
*/
|
||||
public fun UByte.fixToUHex(): String =
|
||||
if (this.toInt() in 0..15) "0${this.toString(16).toUpperCase()}" else this.toString(16).toUpperCase()
|
||||
if (this.toInt() in 0..15) "0${this.toString(16).uppercase()}" else this.toString(16).uppercase()
|
||||
|
||||
public fun String.hexToBytes(): ByteArray =
|
||||
this.split(" ")
|
||||
|
@ -12,6 +12,7 @@
|
||||
|
||||
package net.mamoe.mirai.utils
|
||||
|
||||
import java.util.*
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
public inline fun <reified T> Any?.cast(): T = this as T
|
||||
@ -195,3 +196,7 @@ public fun Throwable.causes(maxDepth: Int = 20): Sequence<Throwable> = sequence
|
||||
if (depth++ >= maxDepth) break
|
||||
}
|
||||
}
|
||||
|
||||
public fun String.capitalize(): String {
|
||||
return replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.ROOT) else it.toString() }
|
||||
}
|
@ -37,7 +37,7 @@ internal class OnlineGroupImageImpl(
|
||||
|
||||
override val imageId: String = generateImageId(
|
||||
delegate.picMd5,
|
||||
delegate.filePath.substringAfterLast('.').toLowerCase().let { ext ->
|
||||
delegate.filePath.substringAfterLast('.').lowercase().let { ext ->
|
||||
if (ext == "null") {
|
||||
// official clients might send `null`
|
||||
getImageType(delegate.imageType)
|
||||
|
@ -12,7 +12,6 @@ package net.mamoe.mirai.internal.network.highway
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.channels.Channel
|
||||
import kotlinx.coroutines.channels.ReceiveChannel
|
||||
import kotlinx.coroutines.channels.receiveOrNull
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.collect
|
||||
import kotlinx.coroutines.flow.produceIn
|
||||
@ -325,7 +324,7 @@ internal suspend fun ChunkedFlowSession<ByteReadPacket>.sendConcurrently(
|
||||
launch(CoroutineName("Worker $it")) {
|
||||
val socket = createConnection()
|
||||
while (isActive) {
|
||||
val next = channel.tryReceive() ?: break // concurrent-safe receive
|
||||
val next = channel.receiveCatching().getOrNull() ?: return@launch // concurrent-safe receive
|
||||
val result = next.withUse {
|
||||
socket.sendReceiveHighway(next, resultChecker)
|
||||
}
|
||||
@ -335,15 +334,6 @@ internal suspend fun ChunkedFlowSession<ByteReadPacket>.sendConcurrently(
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun <E : Any> ReceiveChannel<E>.tryReceive(): E? {
|
||||
return kotlin.runCatching {
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
receiveOrNull() // this is experimental api
|
||||
}.recoverCatching {
|
||||
// in case binary changes
|
||||
receive()
|
||||
}.getOrNull()
|
||||
}
|
||||
|
||||
private suspend fun HighwayProtocolChannel.sendReceiveHighway(
|
||||
it: ByteReadPacket,
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Mamoe Technologies and contributors.
|
||||
* Copyright 2019-2021 Mamoe Technologies and contributors.
|
||||
*
|
||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||
@ -9,7 +9,8 @@
|
||||
|
||||
package net.mamoe.mirai.internal.network.protocol
|
||||
|
||||
internal inline class LoginType(
|
||||
@JvmInline
|
||||
internal value class LoginType(
|
||||
val value: Int
|
||||
) {
|
||||
companion object {
|
||||
|
@ -14,6 +14,7 @@ import kotlinx.serialization.protobuf.ProtoNumber
|
||||
import net.mamoe.mirai.internal.network.Packet
|
||||
import net.mamoe.mirai.internal.utils.io.ProtoBuf
|
||||
import net.mamoe.mirai.utils.EMPTY_BYTE_ARRAY
|
||||
import net.mamoe.mirai.utils.capitalize
|
||||
|
||||
internal class Oidb0x5d4 : ProtoBuf {
|
||||
@Serializable
|
||||
|
@ -45,7 +45,8 @@ internal fun TlvMap.smartToString(leadingLineBreak: Boolean = true, sorted: Bool
|
||||
/**
|
||||
* 显式表示一个 [ByteArray] 是一个 tlv 的 body
|
||||
*/
|
||||
internal inline class Tlv(val value: ByteArray)
|
||||
@JvmInline
|
||||
internal value class Tlv(val value: ByteArray)
|
||||
|
||||
internal fun BytePacketBuilder.t1(uin: Long, ip: ByteArray) {
|
||||
require(ip.size == 4) { "ip.size must == 4" }
|
||||
|
@ -19,10 +19,7 @@ import kotlinx.io.core.*
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.protobuf.ProtoNumber
|
||||
import net.mamoe.mirai.Mirai
|
||||
import net.mamoe.mirai.contact.Member
|
||||
import net.mamoe.mirai.contact.MemberPermission
|
||||
import net.mamoe.mirai.contact.NormalMember
|
||||
import net.mamoe.mirai.contact.User
|
||||
import net.mamoe.mirai.contact.*
|
||||
import net.mamoe.mirai.data.GroupHonorType
|
||||
import net.mamoe.mirai.event.events.*
|
||||
import net.mamoe.mirai.internal.QQAndroidBot
|
||||
@ -49,7 +46,7 @@ import net.mamoe.mirai.internal.network.protocol.packet.OutgoingPacket
|
||||
import net.mamoe.mirai.internal.network.protocol.packet.buildResponseUniPacket
|
||||
import net.mamoe.mirai.internal.network.protocol.packet.list.FriendList
|
||||
import net.mamoe.mirai.internal.network.protocol.packet.sendAndExpect
|
||||
import net.mamoe.mirai.internal.utils._miraiContentToString
|
||||
import net.mamoe.mirai.internal.utils.*
|
||||
import net.mamoe.mirai.internal.utils.io.ProtoBuf
|
||||
import net.mamoe.mirai.internal.utils.io.serialization.*
|
||||
import net.mamoe.mirai.internal.utils.parseToMessageDataList
|
||||
@ -445,7 +442,7 @@ private object Transformers732 : Map<Int, Lambda732> by mapOf(
|
||||
else -> {
|
||||
/*
|
||||
bot.network.logger.debug("unknown Transformer732 0xunknown type: ${dataBytes[0].toString(16)
|
||||
.toUpperCase()}")
|
||||
.uppercase()}")
|
||||
bot.network.logger.debug("unknown Transformer732 0xdata= ${readBytes().toUHexString()}")
|
||||
*/
|
||||
return@lambda732 emptySequence()
|
||||
@ -818,7 +815,7 @@ internal object Transformers528 : Map<Long, Lambda528> by mapOf(
|
||||
return@mapNotNull MemberCardChangeEvent(old, new, member)
|
||||
}
|
||||
2 -> {
|
||||
if (info.value.singleOrNull()?.toInt() != 0) {
|
||||
if (info.value.singleOrNull()?.code != 0) {
|
||||
bot.logger.debug {
|
||||
"Unknown Transformers528 0x27L ModGroupMemberProfile, field=${info.field}, value=${info.value}"
|
||||
}
|
||||
|
@ -18,7 +18,8 @@ package net.mamoe.mirai.internal.utils
|
||||
* 17: 以前没保存但现在生成成功;
|
||||
*/
|
||||
@Suppress("NON_PUBLIC_PRIMARY_CONSTRUCTOR_OF_INLINE_CLASS")
|
||||
internal inline class GuidSource private constructor(val id: Long) { // uint actually
|
||||
@JvmInline
|
||||
internal value class GuidSource private constructor(val id: Long) { // uint actually
|
||||
companion object {
|
||||
/**
|
||||
* 初始值
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Mamoe Technologies and contributors.
|
||||
* Copyright 2019-2021 Mamoe Technologies and contributors.
|
||||
*
|
||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||
@ -12,12 +12,14 @@ package net.mamoe.mirai.internal.utils
|
||||
/**
|
||||
* 连接类型
|
||||
*/
|
||||
internal inline class NetworkType(val value: Int) {
|
||||
@JvmInline
|
||||
internal value class NetworkType(val value: Int) {
|
||||
companion object {
|
||||
/**
|
||||
* 移动网络
|
||||
*/
|
||||
val MOBILE = NetworkType(1)
|
||||
|
||||
/**
|
||||
* Wifi
|
||||
*/
|
||||
|
@ -34,7 +34,7 @@ internal class ScheduledJob(
|
||||
fun notice() {
|
||||
if (intervalMillis == 0L) {
|
||||
launch { task() }
|
||||
} else channel.offer(Unit)
|
||||
} else channel.trySend(Unit)
|
||||
}
|
||||
|
||||
private suspend fun doTask() {
|
||||
|
@ -9,7 +9,8 @@
|
||||
|
||||
package net.mamoe.mirai.internal.utils
|
||||
|
||||
internal inline class MacOrAndroidIdChangeFlag(val value: Long = 0) {
|
||||
@JvmInline
|
||||
internal value class MacOrAndroidIdChangeFlag(val value: Long = 0) {
|
||||
fun macChanged(): MacOrAndroidIdChangeFlag =
|
||||
MacOrAndroidIdChangeFlag(this.value or 0x1)
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Mamoe Technologies and contributors.
|
||||
* Copyright 2019-2021 Mamoe Technologies and contributors.
|
||||
*
|
||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||
@ -20,7 +20,6 @@ import kotlinx.serialization.internal.TaggedDecoder
|
||||
import kotlinx.serialization.modules.SerializersModule
|
||||
import net.mamoe.mirai.internal.utils.io.serialization.tars.Tars
|
||||
import net.mamoe.mirai.internal.utils.io.serialization.tars.TarsId
|
||||
import net.mamoe.mirai.internal.utils.io.serialization.tars.internal.*
|
||||
|
||||
|
||||
@OptIn(InternalSerializationApi::class, ExperimentalSerializationApi::class)
|
||||
@ -110,7 +109,7 @@ internal class TarsDecoder(
|
||||
override fun decodeFloat(): Float = input.useHead { input.readTarsFloatValue(it) }
|
||||
override fun decodeDouble(): Double = input.useHead { input.readTarsDoubleValue(it) }
|
||||
override fun decodeBoolean(): Boolean = input.useHead { input.readTarsBooleanValue(it) }
|
||||
override fun decodeChar(): Char = decodeByte().toChar()
|
||||
override fun decodeChar(): Char = decodeByte().toInt().toChar()
|
||||
override fun decodeEnum(enumDescriptor: SerialDescriptor): Int = decodeInt()
|
||||
override fun decodeString(): String = input.useHead { input.readTarsStringValue(it) }
|
||||
|
||||
@ -158,7 +157,7 @@ internal class TarsDecoder(
|
||||
override fun decodeDouble(): Double = input.useHead { input.readTarsDoubleValue(it) }
|
||||
|
||||
override fun decodeBoolean(): Boolean = input.useHead { input.readTarsBooleanValue(it) }
|
||||
override fun decodeChar(): Char = decodeByte().toChar()
|
||||
override fun decodeChar(): Char = decodeByte().toInt().toChar()
|
||||
override fun decodeEnum(enumDescriptor: SerialDescriptor): Int = decodeInt()
|
||||
override fun decodeString(): String = input.useHead { head ->
|
||||
input.readTarsStringValue(head).also {
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Mamoe Technologies and contributors.
|
||||
* Copyright 2019-2021 Mamoe Technologies and contributors.
|
||||
*
|
||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||
@ -235,7 +235,7 @@ internal class TarsOld internal constructor(private val charset: Charset, overri
|
||||
}
|
||||
|
||||
public override fun encodeTaggedChar(tag: Int, value: Char) {
|
||||
encodeTaggedByte(tag, value.toByte())
|
||||
encodeTaggedByte(tag, value.code.toByte())
|
||||
}
|
||||
|
||||
public override fun encodeTaggedEnum(tag: Int, enumDescriptor: SerialDescriptor, ordinal: Int) {
|
||||
|
@ -179,7 +179,8 @@ internal fun <T : ProtoBuf> ByteReadPacket.readProtoBuf(
|
||||
): T = KtProtoBuf.decodeFromByteArray(serializer, this.readBytes(length))
|
||||
|
||||
@Suppress("NON_PUBLIC_PRIMARY_CONSTRUCTOR_OF_INLINE_CLASS")
|
||||
internal inline class OidbBodyOrFailure<T : ProtoBuf> private constructor(
|
||||
@JvmInline
|
||||
internal value class OidbBodyOrFailure<T : ProtoBuf> private constructor(
|
||||
private val v: Any
|
||||
) {
|
||||
internal class Failure(
|
||||
|
Loading…
Reference in New Issue
Block a user