Add utils for send packet

This commit is contained in:
Him188 2021-01-31 13:10:18 +08:00
parent 3643d8d4fd
commit e8dc06ebad

View File

@ -14,7 +14,9 @@ import kotlinx.io.core.BytePacketBuilder
import kotlinx.io.core.ByteReadPacket
import kotlinx.io.core.buildPacket
import kotlinx.io.core.writeFully
import net.mamoe.mirai.internal.QQAndroidBot
import net.mamoe.mirai.internal.network.Packet
import net.mamoe.mirai.internal.network.QQAndroidBotNetworkHandler
import net.mamoe.mirai.internal.network.QQAndroidClient
import net.mamoe.mirai.internal.utils.io.encryptAndWrite
import net.mamoe.mirai.internal.utils.io.writeHex
@ -37,6 +39,43 @@ internal open class OutgoingPacket constructor(
val name: String = name ?: commandName
}
internal suspend inline fun <E : Packet> OutgoingPacketWithRespType<E>.sendAndExpect(
network: QQAndroidBotNetworkHandler,
timeoutMillis: Long = 5000,
retry: Int = 2
): E = network.run {
return (this@sendAndExpect as OutgoingPacket).sendAndExpect(timeoutMillis, retry)
}
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
@kotlin.internal.LowPriorityInOverloadResolution
internal suspend inline fun <E : Packet> OutgoingPacket.sendAndExpect(
network: QQAndroidBotNetworkHandler,
timeoutMillis: Long = 5000,
retry: Int = 2
): E = network.run {
return this@sendAndExpect.sendAndExpect(timeoutMillis, retry)
}
internal suspend inline fun <E : Packet> OutgoingPacketWithRespType<E>.sendAndExpect(
bot: QQAndroidBot,
timeoutMillis: Long = 5000,
retry: Int = 2
): E = bot.network.run {
return (this@sendAndExpect as OutgoingPacket).sendAndExpect(timeoutMillis, retry)
}
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
@kotlin.internal.LowPriorityInOverloadResolution
internal suspend inline fun <E : Packet> OutgoingPacket.sendAndExpect(
bot: QQAndroidBot,
timeoutMillis: Long = 5000,
retry: Int = 2
): E = bot.network.run {
return this@sendAndExpect.sendAndExpect(timeoutMillis, retry)
}
internal val KEY_16_ZEROS = ByteArray(16)
internal val EMPTY_BYTE_ARRAY = ByteArray(0)