mirror of
https://github.com/mamoe/mirai.git
synced 2025-04-15 07:37:08 +08:00
Use BotConfiguration
This commit is contained in:
parent
308988faae
commit
4261e20103
mirai-core-timpc/src
commonMain/kotlin/net.mamoe.mirai.timpc/network
jvmTest/kotlin
mirai-core/src/commonMain/kotlin/net.mamoe.mirai
mirai-demos/mirai-demo-android/src/main/kotlin/net/mamoe/mirai/demo
@ -255,9 +255,8 @@ internal class TIMPCBotNetworkHandler internal constructor(coroutineContext: Cor
|
||||
if (e.cause !is CancellationException) {
|
||||
bot.logger.error("Caught SendPacketInternalException: ${e.cause?.message}")
|
||||
}
|
||||
val configuration = bot.configuration
|
||||
delay(configuration.firstReconnectDelayMillis)
|
||||
bot.tryReinitializeNetworkHandler(configuration, e)
|
||||
delay(bot.configuration.firstReconnectDelayMillis)
|
||||
bot.tryReinitializeNetworkHandler(e)
|
||||
return@withContext
|
||||
} finally {
|
||||
buffer.release(IoBuffer.Pool)
|
||||
@ -468,7 +467,7 @@ internal class TIMPCBotNetworkHandler internal constructor(coroutineContext: Cor
|
||||
} == null) {
|
||||
bot.logger.warning("Heartbeat timed out")
|
||||
delay(configuration.firstReconnectDelayMillis)
|
||||
bot.tryReinitializeNetworkHandler(configuration, HeartbeatTimeoutException())
|
||||
bot.tryReinitializeNetworkHandler(HeartbeatTimeoutException())
|
||||
return@launch
|
||||
}
|
||||
}
|
||||
|
@ -379,7 +379,7 @@ when (idHex.substring(0, 5)) {
|
||||
internal object DebugNetworkHandler : BotNetworkHandler(), CoroutineScope {
|
||||
override val supervisor: CompletableJob = SupervisorJob()
|
||||
|
||||
override val bot: Bot = TIMPC.run { this@DebugNetworkHandler.Bot(qq ?: 0L, "", null) }
|
||||
override val bot: Bot = TIMPC.Bot(qq ?: 0L, "", null)
|
||||
|
||||
override suspend fun login() {}
|
||||
|
||||
|
@ -22,6 +22,6 @@ class ReceiveFriendAddRequestEvent(
|
||||
*
|
||||
* @param remark 备注名, 不设置则需为 `null`
|
||||
*/
|
||||
@JvmOverloads // TODO: 2019/12/17 协议抽象
|
||||
@JvmOverloads
|
||||
suspend fun approve(remark: String? = null): Unit = qq.bot.approveFriendAddRequest(qq.id, remark)
|
||||
}
|
||||
|
@ -33,11 +33,13 @@ fun BytePacketBuilder.writeShortLVByteArray(byteArray: ByteArray) {
|
||||
this.writeFully(byteArray)
|
||||
}
|
||||
|
||||
fun BytePacketBuilder.writeShortLVPacket(tag: UByte? = null, lengthOffset: ((Long) -> Long)? = null, builder: BytePacketBuilder.() -> Unit) =
|
||||
fun BytePacketBuilder.writeShortLVPacket(tag: UByte? = null, lengthOffset: ((Long) -> Long)? = null, builder: BytePacketBuilder.() -> Unit): Int =
|
||||
BytePacketBuilder().apply(builder).build().use {
|
||||
if (tag != null) writeUByte(tag)
|
||||
writeUShort((lengthOffset?.invoke(it.remaining) ?: it.remaining).coerceAtMostOrFail(0xFFFFL).toUShort())
|
||||
val length = (lengthOffset?.invoke(it.remaining) ?: it.remaining).coerceAtMostOrFail(0xFFFFL)
|
||||
writeUShort(length.toUShort())
|
||||
writePacket(it)
|
||||
return length.toInt()
|
||||
}
|
||||
|
||||
fun BytePacketBuilder.writeUVarIntLVPacket(tag: UByte? = null, lengthOffset: ((Long) -> Long)? = null, builder: BytePacketBuilder.() -> Unit) =
|
||||
|
@ -41,17 +41,17 @@ class MiraiService : Service() {
|
||||
|
||||
private fun login(qq: Long, pwd: String) {
|
||||
GlobalScope.launch {
|
||||
mBot = TIMPC.Bot(qq, pwd).apply {
|
||||
mBot = TIMPC.Bot(qq, pwd) {
|
||||
captchaSolver = {
|
||||
val bytes = it.readBytes()
|
||||
val bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.size)
|
||||
mCaptchaDeferred = CompletableDeferred()
|
||||
mCallback?.get()?.onCaptcha(bitmap)
|
||||
mCaptchaDeferred.await()
|
||||
}
|
||||
}.apply {
|
||||
try {
|
||||
login {
|
||||
captchaSolver = {
|
||||
val bytes = it.readBytes()
|
||||
val bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.size)
|
||||
mCaptchaDeferred = CompletableDeferred()
|
||||
mCallback?.get()?.onCaptcha(bitmap)
|
||||
mCaptchaDeferred.await()
|
||||
}
|
||||
}
|
||||
login()
|
||||
mCallback?.get()?.onSuccess()
|
||||
} catch (e: LoginFailedException) {
|
||||
mCallback?.get()?.onFailed()
|
||||
|
Loading…
Reference in New Issue
Block a user