mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-09 18:00:33 +08:00
No broadcast for events from friend message syncing
This commit is contained in:
parent
32abb01861
commit
2deb1601a8
@ -20,10 +20,7 @@ import kotlinx.io.core.buildPacket
|
|||||||
import kotlinx.io.core.use
|
import kotlinx.io.core.use
|
||||||
import net.mamoe.mirai.data.MultiPacket
|
import net.mamoe.mirai.data.MultiPacket
|
||||||
import net.mamoe.mirai.data.Packet
|
import net.mamoe.mirai.data.Packet
|
||||||
import net.mamoe.mirai.event.BroadcastControllable
|
import net.mamoe.mirai.event.*
|
||||||
import net.mamoe.mirai.event.CancellableEvent
|
|
||||||
import net.mamoe.mirai.event.Event
|
|
||||||
import net.mamoe.mirai.event.broadcast
|
|
||||||
import net.mamoe.mirai.event.events.BotOfflineEvent
|
import net.mamoe.mirai.event.events.BotOfflineEvent
|
||||||
import net.mamoe.mirai.event.events.BotOnlineEvent
|
import net.mamoe.mirai.event.events.BotOnlineEvent
|
||||||
import net.mamoe.mirai.network.BotNetworkHandler
|
import net.mamoe.mirai.network.BotNetworkHandler
|
||||||
@ -296,7 +293,17 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
|
|||||||
heartbeatJob = startHeartbeatJobOrKill()
|
heartbeatJob = startHeartbeatJobOrKill()
|
||||||
|
|
||||||
joinAll(friendListJob, groupJob)
|
joinAll(friendListJob, groupJob)
|
||||||
MessageSvc.PbGetMsg(bot.client, MsgSvc.SyncFlag.START, currentTimeSeconds).sendAndExpect<MessageSvc.PbGetMsg.GetMsgSuccess>()
|
|
||||||
|
withTimeoutOrNull(5000) {
|
||||||
|
lateinit var listener: Listener<PacketReceivedEvent>
|
||||||
|
listener = this.subscribeAlways {
|
||||||
|
if (it.packet is MessageSvc.PbGetMsg.GetMsgSuccess) {
|
||||||
|
listener.complete()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MessageSvc.PbGetMsg(bot.client, MsgSvc.SyncFlag.START, currentTimeSeconds).sendWithoutExpect()
|
||||||
|
} ?: error("timeout syncing friend message history")
|
||||||
|
|
||||||
bot.firstLoginSucceed = true
|
bot.firstLoginSucceed = true
|
||||||
|
|
||||||
|
@ -17,6 +17,9 @@ import net.mamoe.mirai.Bot
|
|||||||
import net.mamoe.mirai.event.internal.Handler
|
import net.mamoe.mirai.event.internal.Handler
|
||||||
import net.mamoe.mirai.event.internal.subscribeInternal
|
import net.mamoe.mirai.event.internal.subscribeInternal
|
||||||
import net.mamoe.mirai.utils.MiraiInternalAPI
|
import net.mamoe.mirai.utils.MiraiInternalAPI
|
||||||
|
import kotlin.contracts.ExperimentalContracts
|
||||||
|
import kotlin.contracts.InvocationKind
|
||||||
|
import kotlin.contracts.contract
|
||||||
import kotlin.coroutines.CoroutineContext
|
import kotlin.coroutines.CoroutineContext
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -109,9 +112,13 @@ inline fun <reified E : Event> CoroutineScope.subscribe(crossinline handler: sus
|
|||||||
*
|
*
|
||||||
* @see subscribe 获取更多说明
|
* @see subscribe 获取更多说明
|
||||||
*/
|
*/
|
||||||
@UseExperimental(MiraiInternalAPI::class)
|
@UseExperimental(MiraiInternalAPI::class, ExperimentalContracts::class)
|
||||||
inline fun <reified E : Event> CoroutineScope.subscribeAlways(crossinline listener: suspend E.(E) -> Unit): Listener<E> =
|
inline fun <reified E : Event> CoroutineScope.subscribeAlways(crossinline listener: suspend E.(E) -> Unit): Listener<E> {
|
||||||
E::class.subscribeInternal(Handler { it.listener(it); ListeningStatus.LISTENING })
|
contract {
|
||||||
|
callsInPlace(listener, InvocationKind.UNKNOWN)
|
||||||
|
}
|
||||||
|
return E::class.subscribeInternal(Handler { it.listener(it); ListeningStatus.LISTENING })
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 在指定的 [CoroutineScope] 下订阅所有 [E] 及其子类事件.
|
* 在指定的 [CoroutineScope] 下订阅所有 [E] 及其子类事件.
|
||||||
|
Loading…
Reference in New Issue
Block a user