mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-03 01:39:35 +08:00
Cleanup
This commit is contained in:
parent
01e887fff5
commit
1d0b42df73
@ -6,6 +6,7 @@
|
||||
*
|
||||
* https://github.com/mamoe/mirai/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||
|
||||
package net.mamoe.mirai.qqandroid.contact
|
||||
|
@ -6,6 +6,7 @@
|
||||
*
|
||||
* https://github.com/mamoe/mirai/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
@file:OptIn(LowLevelAPI::class)
|
||||
@file:Suppress("EXPERIMENTAL_API_USAGE", "DEPRECATION_ERROR")
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
*
|
||||
* https://github.com/mamoe/mirai/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
@file:Suppress("EXPERIMENTAL_API_USAGE", "EXPERIMENTAL_OVERRIDE", "INVISIBLE_REFERENCE", "INVISIBLE_MEMBER")
|
||||
|
||||
package net.mamoe.mirai.qqandroid.message
|
||||
|
@ -6,6 +6,7 @@
|
||||
*
|
||||
* https://github.com/mamoe/mirai/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
@file:Suppress("EXPERIMENTAL_API_USAGE", "EXPERIMENTAL_OVERRIDE", "INVISIBLE_REFERENCE", "INVISIBLE_MEMBER")
|
||||
|
||||
package net.mamoe.mirai.qqandroid.message
|
||||
|
@ -14,6 +14,7 @@ import net.mamoe.mirai.contact.Friend
|
||||
import net.mamoe.mirai.contact.Group
|
||||
import net.mamoe.mirai.data.*
|
||||
import net.mamoe.mirai.utils.MiraiExperimentalAPI
|
||||
import net.mamoe.mirai.utils.SinceMirai
|
||||
import net.mamoe.mirai.utils.WeakRef
|
||||
|
||||
/**
|
||||
@ -125,7 +126,6 @@ public interface LowLevelBotAPIAccessor {
|
||||
* 处理一个账号请求添加机器人为好友的事件
|
||||
*/
|
||||
@LowLevelAPI
|
||||
@MiraiExperimentalAPI
|
||||
public suspend fun _lowLevelSolveNewFriendRequestEvent(
|
||||
eventId: Long,
|
||||
fromId: Long,
|
||||
@ -138,7 +138,6 @@ public interface LowLevelBotAPIAccessor {
|
||||
* 处理被邀请加入一个群请求事件
|
||||
*/
|
||||
@LowLevelAPI
|
||||
@MiraiExperimentalAPI
|
||||
public suspend fun _lowLevelSolveBotInvitedJoinGroupRequestEvent(
|
||||
eventId: Long,
|
||||
invitorId: Long,
|
||||
@ -150,7 +149,7 @@ public interface LowLevelBotAPIAccessor {
|
||||
* 处理账号请求加入群事件
|
||||
*/
|
||||
@LowLevelAPI
|
||||
@MiraiExperimentalAPI
|
||||
@SinceMirai("1.2.0")
|
||||
public suspend fun _lowLevelSolveMemberJoinRequestEvent(
|
||||
eventId: Long,
|
||||
fromId: Long,
|
||||
@ -165,6 +164,20 @@ public interface LowLevelBotAPIAccessor {
|
||||
* 查询语音的下载连接
|
||||
*/
|
||||
@LowLevelAPI
|
||||
@MiraiExperimentalAPI
|
||||
public suspend fun _lowLevelQueryGroupVoiceDownloadUrl(md5: ByteArray, groupId: Long, dstUin: Long): String
|
||||
@SinceMirai("1.2.0")
|
||||
public suspend fun _lowLevelQueryGroupVoiceDownloadUrl(
|
||||
md5: ByteArray,
|
||||
groupId: Long,
|
||||
dstUin: Long
|
||||
): String
|
||||
|
||||
/**
|
||||
* 查询语音的上传连接
|
||||
*/
|
||||
@LowLevelAPI
|
||||
@SinceMirai("1.2.0")
|
||||
public suspend fun _lowLevelUploadVoice(
|
||||
md5: ByteArray,
|
||||
groupId: Long,
|
||||
)
|
||||
}
|
||||
|
@ -14,9 +14,7 @@ package net.mamoe.mirai.message.data
|
||||
import kotlinx.io.core.*
|
||||
import kotlinx.serialization.KSerializer
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.UnstableDefault
|
||||
import kotlinx.serialization.json.Json
|
||||
import kotlinx.serialization.json.JsonConfiguration
|
||||
import kotlinx.serialization.protobuf.ProtoBuf
|
||||
import kotlinx.serialization.protobuf.ProtoId
|
||||
import net.mamoe.mirai.utils.*
|
||||
@ -90,8 +88,8 @@ public sealed class CustomMessage : SingleMessage {
|
||||
*/
|
||||
public abstract fun serializer(): KSerializer<M>
|
||||
|
||||
public override fun dump(message: M): ByteArray = ProtoBuf.dump(serializer(), message)
|
||||
public override fun load(input: ByteArray): M = ProtoBuf.load(serializer(), input)
|
||||
public override fun dump(message: M): ByteArray = ProtoBuf.encodeToByteArray(serializer(), message)
|
||||
public override fun load(input: ByteArray): M = ProtoBuf.decodeFromByteArray(serializer(), input)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -106,11 +104,10 @@ public sealed class CustomMessage : SingleMessage {
|
||||
*/
|
||||
public abstract fun serializer(): KSerializer<M>
|
||||
|
||||
@OptIn(UnstableDefault::class)
|
||||
public open val json: Json = Json(JsonConfiguration.Default)
|
||||
public open val json: Json = Json.Default
|
||||
|
||||
public override fun dump(message: M): ByteArray = json.stringify(serializer(), message).toByteArray()
|
||||
public override fun load(input: ByteArray): M = json.parse(serializer(), String(input))
|
||||
public override fun dump(message: M): ByteArray = json.encodeToString(serializer(), message).toByteArray()
|
||||
public override fun load(input: ByteArray): M = json.decodeFromString(serializer(), String(input))
|
||||
}
|
||||
|
||||
public companion object Key : Message.Key<CustomMessage> {
|
||||
@ -143,7 +140,7 @@ public sealed class CustomMessage : SingleMessage {
|
||||
if (fullData.remaining != length.toLong()) {
|
||||
return null
|
||||
}
|
||||
ProtoBuf.load(CustomMessageFullData.serializer(), fullData.readBytes(length))
|
||||
ProtoBuf.decodeFromByteArray(CustomMessageFullData.serializer(), fullData.readBytes(length))
|
||||
}.getOrElse {
|
||||
throw CustomMessageFullDataDeserializeInternalException(it)
|
||||
}
|
||||
@ -158,7 +155,7 @@ public sealed class CustomMessage : SingleMessage {
|
||||
}
|
||||
|
||||
internal fun <M : CustomMessage> dump(factory: Factory<M>, message: M): ByteArray = buildPacket {
|
||||
ProtoBuf.dump(
|
||||
ProtoBuf.encodeToByteArray(
|
||||
CustomMessageFullData.serializer(), CustomMessageFullData(
|
||||
miraiVersionFlag = 1,
|
||||
typeName = factory.typeName,
|
||||
|
@ -15,16 +15,18 @@ import kotlinx.coroutines.flow.flow
|
||||
import kotlinx.coroutines.flow.flowOf
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.io.ByteReadChannel
|
||||
import kotlinx.io.InputStream
|
||||
import kotlinx.io.core.ByteReadPacket
|
||||
import kotlinx.io.core.Closeable
|
||||
import kotlinx.io.core.Input
|
||||
import kotlinx.serialization.InternalSerializationApi
|
||||
import net.mamoe.mirai.utils.MiraiExperimentalAPI
|
||||
import java.io.InputStream
|
||||
import kotlin.jvm.JvmField
|
||||
|
||||
|
||||
internal interface ChunkedFlowSession<T> : Closeable {
|
||||
val flow: Flow<T>
|
||||
@MiraiExperimentalAPI
|
||||
public interface ChunkedFlowSession<T> : Closeable {
|
||||
public val flow: Flow<T>
|
||||
override fun close()
|
||||
}
|
||||
|
||||
@ -39,7 +41,8 @@ internal inline fun <T, R> ChunkedFlowSession<T>.map(crossinline mapper: suspend
|
||||
/**
|
||||
* 由 [chunkedFlow] 分割得到的区块
|
||||
*/
|
||||
internal class ChunkedInput(
|
||||
@MiraiExperimentalAPI
|
||||
public class ChunkedInput(
|
||||
/**
|
||||
* 区块的数据.
|
||||
* 由 [ByteArrayPool] 缓存并管理, 只可在 [Flow.collect] 中访问.
|
||||
@ -47,13 +50,13 @@ internal class ChunkedInput(
|
||||
*
|
||||
* **注意**: 不要将他带出 [Flow.collect] 作用域, 否则将造成内存泄露
|
||||
*/
|
||||
@JvmField val buffer: ByteArray,
|
||||
@JvmField public val buffer: ByteArray,
|
||||
@JvmField internal var size: Int
|
||||
) {
|
||||
/**
|
||||
* [buffer] 的有效大小
|
||||
*/
|
||||
inline val bufferSize: Int get() = size
|
||||
public val bufferSize: Int get() = size
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -4,15 +4,7 @@ package net.mamoe.mirai.utils.internal
|
||||
|
||||
import kotlinx.io.pool.DefaultPool
|
||||
import kotlinx.io.pool.ObjectPool
|
||||
|
||||
internal expect abstract class InputStream {
|
||||
open fun available(): Int
|
||||
open fun close()
|
||||
abstract fun read(): Int
|
||||
open fun read(b: ByteArray): Int
|
||||
open fun read(b: ByteArray, offset: Int, len: Int): Int
|
||||
open fun skip(n: Long): Long
|
||||
}
|
||||
import java.io.InputStream
|
||||
|
||||
internal expect fun InputStream.md5(): ByteArray
|
||||
internal expect fun ByteArray.md5(offset: Int = 0, length: Int = this.size - offset): ByteArray
|
||||
|
@ -6,6 +6,7 @@
|
||||
*
|
||||
* https://github.com/mamoe/mirai/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
@file:Suppress("unused", "DEPRECATION_ERROR", "EXPOSED_SUPER_CLASS")
|
||||
|
||||
package net.mamoe.mirai.utils
|
||||
@ -63,7 +64,7 @@ public actual open class BotConfiguration : BotConfigurationBase() { // open for
|
||||
@SinceMirai("1.2.0")
|
||||
public actual fun loadDeviceInfoJson(json: String) {
|
||||
deviceInfo = { context ->
|
||||
this.json.parse(DeviceInfoData.serializer(), json).also { it.context = context }
|
||||
this.json.decodeFromString(DeviceInfoData.serializer(), json).also { it.context = context }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,13 +6,9 @@ import kotlinx.io.core.*
|
||||
import kotlinx.io.streams.asInput
|
||||
import kotlinx.io.streams.asOutput
|
||||
import net.mamoe.mirai.Bot
|
||||
import net.mamoe.mirai.utils.internal.InputStream
|
||||
import net.mamoe.mirai.utils.internal.asReusableInput
|
||||
import java.awt.image.BufferedImage
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
import java.io.OutputStream
|
||||
import java.io.*
|
||||
import java.net.URL
|
||||
import java.security.MessageDigest
|
||||
import java.util.*
|
||||
|
@ -30,9 +30,6 @@ import java.io.RandomAccessFile
|
||||
import javax.imageio.ImageIO
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
|
||||
@Suppress("ACTUAL_WITHOUT_EXPECT")
|
||||
internal actual typealias Throws = kotlin.jvm.Throws
|
||||
|
||||
/**
|
||||
* 自动选择 [SwingSolver] 或 [StandardCharImageLoginSolver]
|
||||
*/
|
||||
|
@ -24,10 +24,10 @@ import kotlin.random.nextInt
|
||||
public fun File.loadAsDeviceInfo(json: Json, context: Context = ContextImpl()): DeviceInfo {
|
||||
if (!this.exists() || this.length() == 0L) {
|
||||
return SystemDeviceInfo(context).also {
|
||||
this.writeText(json.stringify(SystemDeviceInfo.serializer(), it))
|
||||
this.writeText(json.encodeToString(SystemDeviceInfo.serializer(), it))
|
||||
}
|
||||
}
|
||||
return json.parse(DeviceInfoData.serializer(), this.readText()).also {
|
||||
return json.decodeFromString(DeviceInfoData.serializer(), this.readText()).also {
|
||||
it.context = context
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import kotlinx.coroutines.withContext
|
||||
import kotlinx.io.core.Input
|
||||
import net.mamoe.mirai.utils.FileCacheStrategy
|
||||
import java.awt.image.BufferedImage
|
||||
import java.io.InputStream
|
||||
import java.net.URL
|
||||
|
||||
internal actual class DeferredReusableInput actual constructor(
|
||||
@ -44,7 +45,7 @@ internal actual class DeferredReusableInput actual constructor(
|
||||
return delegate?.writeTo(out) ?: error("DeferredReusableInput not yet initialized")
|
||||
}
|
||||
|
||||
override fun asInput(): Input {
|
||||
override fun asInput(): InputStream {
|
||||
return delegate?.asInput() ?: error("DeferredReusableInput not yet initialized")
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@ import kotlinx.io.core.ByteReadPacket
|
||||
import kotlinx.io.core.Input
|
||||
import kotlinx.io.streams.asInput
|
||||
import net.mamoe.mirai.message.data.toLongUnsigned
|
||||
import java.io.ByteArrayInputStream
|
||||
import java.io.File
|
||||
import java.io.InputStream
|
||||
|
||||
@ -36,8 +37,8 @@ internal actual fun ByteArray.asReusableInput(): ReusableInput {
|
||||
return this@asReusableInput.size.toLongUnsigned()
|
||||
}
|
||||
|
||||
override fun asInput(): Input {
|
||||
return ByteReadPacket(this@asReusableInput)
|
||||
override fun asInput(): InputStream {
|
||||
return ByteArrayInputStream(this@asReusableInput)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -62,8 +63,8 @@ internal fun File.asReusableInput(deleteOnClose: Boolean): ReusableInput {
|
||||
return inputStream().use { it.copyTo(out) }
|
||||
}
|
||||
|
||||
override fun asInput(): Input {
|
||||
return inputStream().asInput()
|
||||
override fun asInput(): InputStream {
|
||||
return inputStream()
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -88,8 +89,8 @@ internal fun File.asReusableInput(deleteOnClose: Boolean, md5: ByteArray): Reusa
|
||||
return inputStream().use { it.copyTo(out) }
|
||||
}
|
||||
|
||||
override fun asInput(): Input {
|
||||
return inputStream().asInput()
|
||||
override fun asInput(): InputStream {
|
||||
return inputStream()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,4 @@ internal actual fun InputStream.md5(): ByteArray {
|
||||
digest.update(buf, 0, len)
|
||||
}
|
||||
return digest.digest()
|
||||
}
|
||||
|
||||
@Suppress("ACTUAL_WITHOUT_EXPECT")
|
||||
internal actual typealias InputStream = java.io.InputStream
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
package net.mamoe.mirai.utils.internal
|
||||
|
||||
private var isAddSuppressedSupported: Boolean = true
|
||||
|
||||
internal actual fun Throwable.addSuppressedMirai(e: Throwable) {
|
||||
if (this == e) {
|
||||
return
|
||||
}
|
||||
if (!isAddSuppressedSupported) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
this.addSuppressed(e)
|
||||
} catch (e: Exception) {
|
||||
isAddSuppressedSupported = false
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user