mirror of
https://github.com/mamoe/mirai.git
synced 2025-03-22 05:10:09 +08:00
misc
This commit is contained in:
parent
ca0d0969b9
commit
bd1a968db9
@ -468,12 +468,14 @@ internal class GroupImpl(
|
||||
|
||||
override var isAutoApproveEnabled: Boolean
|
||||
get() = _autoApprove
|
||||
@Suppress("UNUSED_PARAMETER")
|
||||
set(newValue) {
|
||||
TODO()
|
||||
}
|
||||
|
||||
override var isAnonymousChatEnabled: Boolean
|
||||
get() = _anonymousChat
|
||||
@Suppress("UNUSED_PARAMETER")
|
||||
set(newValue) {
|
||||
TODO()
|
||||
}
|
||||
|
@ -29,10 +29,10 @@ import kotlinx.io.InputStream
|
||||
import net.mamoe.mirai.qqandroid.io.serialization.readProtoBuf
|
||||
import net.mamoe.mirai.qqandroid.network.QQAndroidClient
|
||||
import net.mamoe.mirai.qqandroid.network.protocol.data.proto.CSDataHighwayHead
|
||||
import net.mamoe.mirai.qqandroid.network.protocol.packet.withUse
|
||||
import net.mamoe.mirai.utils.MiraiInternalAPI
|
||||
import net.mamoe.mirai.utils.io.ByteArrayPool
|
||||
import net.mamoe.mirai.utils.io.PlatformSocket
|
||||
import net.mamoe.mirai.utils.io.withUse
|
||||
|
||||
@UseExperimental(MiraiInternalAPI::class)
|
||||
@Suppress("SpellCheckingInspection")
|
||||
|
@ -42,7 +42,6 @@ internal fun createImageDataPacketSequence( // RequestDataTrans
|
||||
require(data is Input || data is InputStream || data is ByteReadChannel) { "unsupported data: ${data::class.simpleName}" }
|
||||
require(uKey.size == 128) { "bad uKey. Required size=128, got ${uKey.size}" }
|
||||
require(data !is ByteReadPacket || data.remaining.toInt() == dataSize) { "bad input. given dataSize=$dataSize, but actual readRemaining=${(data as ByteReadPacket).remaining}" }
|
||||
require(data !is IoBuffer || data.readRemaining == dataSize) { "bad input. given dataSize=$dataSize, but actual readRemaining=${(data as IoBuffer).readRemaining}" }
|
||||
|
||||
val flow = when (data) {
|
||||
is ByteReadPacket -> data.chunkedFlow(sizePerPacket)
|
||||
|
@ -30,8 +30,6 @@ import net.mamoe.mirai.utils.*
|
||||
import net.mamoe.mirai.utils.cryptor.TEA
|
||||
import net.mamoe.mirai.utils.cryptor.adjustToPublicKey
|
||||
import net.mamoe.mirai.utils.io.*
|
||||
import kotlin.contracts.ExperimentalContracts
|
||||
import kotlin.contracts.contract
|
||||
import kotlin.jvm.JvmName
|
||||
|
||||
|
||||
@ -386,28 +384,4 @@ internal object KnownPacketFactories {
|
||||
consumer(packetFactory, packet, packetFactory.commandName, ssoSequenceId)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@UseExperimental(ExperimentalContracts::class)
|
||||
internal inline fun <R> IoBuffer.withUse(block: IoBuffer.() -> R): R {
|
||||
contract {
|
||||
callsInPlace(block, kotlin.contracts.InvocationKind.EXACTLY_ONCE)
|
||||
}
|
||||
return try {
|
||||
block(this)
|
||||
} finally {
|
||||
this.release(IoBuffer.Pool)
|
||||
}
|
||||
}
|
||||
|
||||
@UseExperimental(ExperimentalContracts::class)
|
||||
internal inline fun <R> ByteReadPacket.withUse(block: ByteReadPacket.() -> R): R {
|
||||
contract {
|
||||
callsInPlace(block, kotlin.contracts.InvocationKind.EXACTLY_ONCE)
|
||||
}
|
||||
return try {
|
||||
block(this)
|
||||
} finally {
|
||||
this.close()
|
||||
}
|
||||
}
|
@ -67,7 +67,7 @@ internal class LongConn {
|
||||
}
|
||||
|
||||
object OffPicDown : OutgoingPacketFactory<OffPicDown.ImageDownPacketResponse>("LongConn.OffPicDown") {
|
||||
operator fun invoke(client: QQAndroidClient, req: GetImgUrlReq): OutgoingPacket {
|
||||
operator fun invoke(client: QQAndroidClient, @Suppress("UNUSED_PARAMETER") req: GetImgUrlReq): OutgoingPacket {
|
||||
return buildOutgoingUniPacket(client) {
|
||||
TODO()
|
||||
}
|
||||
|
@ -36,6 +36,7 @@ internal fun <E : Event> CoroutineScope.Handler(
|
||||
coroutineContext: CoroutineContext,
|
||||
handler: suspend (E) -> ListeningStatus
|
||||
): Handler<E> {
|
||||
@UseExperimental(ExperimentalCoroutinesApi::class) // don't remove
|
||||
val context = this.newCoroutineContext(coroutineContext)
|
||||
return Handler(context[Job], context, handler)
|
||||
}
|
||||
|
@ -20,6 +20,9 @@ import io.ktor.utils.io.pool.useInstance
|
||||
import kotlinx.io.OutputStream
|
||||
import net.mamoe.mirai.utils.MiraiDebugAPI
|
||||
import net.mamoe.mirai.utils.MiraiInternalAPI
|
||||
import kotlin.contracts.ExperimentalContracts
|
||||
import kotlin.contracts.InvocationKind
|
||||
import kotlin.contracts.contract
|
||||
import kotlin.jvm.JvmMultifileClass
|
||||
import kotlin.jvm.JvmName
|
||||
import kotlin.jvm.JvmSynthetic
|
||||
@ -47,6 +50,14 @@ inline fun ByteReadPacket.readPacketExact(
|
||||
n: Int = remaining.toInt()//not that safe but adequate
|
||||
): ByteReadPacket = this.readBytes(n).toReadPacket()
|
||||
|
||||
@UseExperimental(ExperimentalContracts::class)
|
||||
inline fun <C : Closeable, R> C.withUse(block: C.() -> R): R {
|
||||
contract {
|
||||
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
|
||||
}
|
||||
return use(block)
|
||||
}
|
||||
|
||||
private inline fun <R> inline(block: () -> R): R = block()
|
||||
|
||||
typealias TlvMap = MutableMap<Int, ByteArray>
|
||||
@ -61,7 +72,8 @@ inline fun TlvMap.getOrFail(tag: Int, lazyMessage: (tag: Int) -> String): ByteAr
|
||||
|
||||
@Suppress("FunctionName")
|
||||
@MiraiInternalAPI
|
||||
inline fun Input._readTLVMap(tagSize: Int = 2, suppressDuplication: Boolean = true): TlvMap = _readTLVMap(true, tagSize, suppressDuplication)
|
||||
inline fun Input._readTLVMap(tagSize: Int = 2, suppressDuplication: Boolean = true): TlvMap =
|
||||
_readTLVMap(true, tagSize, suppressDuplication)
|
||||
|
||||
@MiraiDebugAPI
|
||||
@Suppress("DuplicatedCode", "FunctionName")
|
||||
@ -122,10 +134,18 @@ fun Input._readTLVMap(expectingEOF: Boolean = true, tagSize: Int, suppressDuplic
|
||||
return map
|
||||
}
|
||||
|
||||
inline fun Input.readString(length: Int, charset: Charset = Charsets.UTF_8): String = String(this.readBytes(length), charset = charset)
|
||||
inline fun Input.readString(length: Long, charset: Charset = Charsets.UTF_8): String = String(this.readBytes(length.toInt()), charset = charset)
|
||||
inline fun Input.readString(length: Short, charset: Charset = Charsets.UTF_8): String = String(this.readBytes(length.toInt()), charset = charset)
|
||||
@JvmSynthetic
|
||||
inline fun Input.readString(length: UShort, charset: Charset = Charsets.UTF_8): String = String(this.readBytes(length.toInt()), charset = charset)
|
||||
inline fun Input.readString(length: Int, charset: Charset = Charsets.UTF_8): String =
|
||||
String(this.readBytes(length), charset = charset)
|
||||
|
||||
inline fun Input.readString(length: Byte, charset: Charset = Charsets.UTF_8): String = String(this.readBytes(length.toInt()), charset = charset)
|
||||
inline fun Input.readString(length: Long, charset: Charset = Charsets.UTF_8): String =
|
||||
String(this.readBytes(length.toInt()), charset = charset)
|
||||
|
||||
inline fun Input.readString(length: Short, charset: Charset = Charsets.UTF_8): String =
|
||||
String(this.readBytes(length.toInt()), charset = charset)
|
||||
|
||||
@JvmSynthetic
|
||||
inline fun Input.readString(length: UShort, charset: Charset = Charsets.UTF_8): String =
|
||||
String(this.readBytes(length.toInt()), charset = charset)
|
||||
|
||||
inline fun Input.readString(length: Byte, charset: Charset = Charsets.UTF_8): String =
|
||||
String(this.readBytes(length.toInt()), charset = charset)
|
@ -21,11 +21,11 @@ internal class CombinedMessageTest {
|
||||
@Test
|
||||
fun testAsSequence2() {
|
||||
var message: Message = "Hello ".toMessage()
|
||||
message += MessageChain(
|
||||
message += listOf(
|
||||
PlainText("W"),
|
||||
PlainText("o"),
|
||||
PlainText("r") + PlainText("ld")
|
||||
)
|
||||
).asMessageChain()
|
||||
|
||||
assertEquals(
|
||||
"Hello World",
|
||||
|
@ -7,6 +7,7 @@
|
||||
* https://github.com/mamoe/mirai/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
@file:JvmName("BotFactoryJvm")
|
||||
@file:Suppress("FunctionName", "unused")
|
||||
|
||||
package net.mamoe.mirai
|
||||
@ -44,6 +45,7 @@ internal val factory: BotFactory = run {
|
||||
/**
|
||||
* 加载现有协议的 [BotFactory], 并使用指定的 [配置][configuration] 构造 [Bot] 实例
|
||||
*/
|
||||
@JvmName("newBot")
|
||||
@JvmOverloads
|
||||
fun Bot(context: Context, qq: Long, password: String, configuration: BotConfiguration = BotConfiguration.Default): Bot =
|
||||
factory.Bot(context, qq, password, configuration)
|
||||
@ -51,6 +53,7 @@ fun Bot(context: Context, qq: Long, password: String, configuration: BotConfigur
|
||||
/**
|
||||
* 加载现有协议的 [BotFactory], 并使用指定的 [配置][configuration] 构造 [Bot] 实例
|
||||
*/
|
||||
@JvmSynthetic
|
||||
inline fun Bot(context: Context, qq: Long, password: String, configuration: (BotConfiguration.() -> Unit)): Bot =
|
||||
factory.Bot(context, qq, password, configuration)
|
||||
|
||||
@ -58,6 +61,7 @@ inline fun Bot(context: Context, qq: Long, password: String, configuration: (Bot
|
||||
/**
|
||||
* 加载现有协议的 [BotFactory], 并使用指定的 [配置][configuration] 构造 [Bot] 实例
|
||||
*/
|
||||
@JvmName("newBot")
|
||||
@JvmOverloads
|
||||
fun Bot(qq: Long, password: String, configuration: BotConfiguration = BotConfiguration.Default): Bot =
|
||||
factory.Bot(ContextImpl(), qq, password, configuration)
|
||||
@ -65,5 +69,6 @@ fun Bot(qq: Long, password: String, configuration: BotConfiguration = BotConfigu
|
||||
/**
|
||||
* 加载现有协议的 [BotFactory], 并使用指定的 [配置][configuration] 构造 [Bot] 实例
|
||||
*/
|
||||
@JvmSynthetic
|
||||
inline fun Bot(qq: Long, password: String, configuration: (BotConfiguration.() -> Unit)): Bot =
|
||||
factory.Bot(ContextImpl(), qq, password, configuration)
|
Loading…
Reference in New Issue
Block a user