mirror of
https://github.com/mamoe/mirai.git
synced 2025-03-28 00:20:14 +08:00
Remove debugConf
This commit is contained in:
parent
71b128b06c
commit
b5db147985
@ -34,7 +34,6 @@ import net.mamoe.mirai.internal.network.handler.selector.NetworkException
|
|||||||
import net.mamoe.mirai.internal.network.handler.selector.SelectorNetworkHandler
|
import net.mamoe.mirai.internal.network.handler.selector.SelectorNetworkHandler
|
||||||
import net.mamoe.mirai.internal.network.handler.state.StateChangedObserver
|
import net.mamoe.mirai.internal.network.handler.state.StateChangedObserver
|
||||||
import net.mamoe.mirai.internal.network.handler.state.StateObserver
|
import net.mamoe.mirai.internal.network.handler.state.StateObserver
|
||||||
import net.mamoe.mirai.internal.network.handler.state.StateObserver.Companion.LOGGING
|
|
||||||
import net.mamoe.mirai.internal.network.handler.state.safe
|
import net.mamoe.mirai.internal.network.handler.state.safe
|
||||||
import net.mamoe.mirai.internal.network.impl.netty.NettyNetworkHandlerFactory
|
import net.mamoe.mirai.internal.network.impl.netty.NettyNetworkHandlerFactory
|
||||||
import net.mamoe.mirai.internal.utils.subLogger
|
import net.mamoe.mirai.internal.utils.subLogger
|
||||||
@ -50,16 +49,10 @@ internal fun Bot.asQQAndroidBot(): QQAndroidBot {
|
|||||||
return this as QQAndroidBot
|
return this as QQAndroidBot
|
||||||
}
|
}
|
||||||
|
|
||||||
// for tests
|
|
||||||
internal class BotDebugConfiguration(
|
|
||||||
var stateObserver: StateObserver? = LOGGING,
|
|
||||||
)
|
|
||||||
|
|
||||||
@Suppress("INVISIBLE_MEMBER", "BooleanLiteralArgument", "OverridingDeprecatedMember")
|
@Suppress("INVISIBLE_MEMBER", "BooleanLiteralArgument", "OverridingDeprecatedMember")
|
||||||
internal open class QQAndroidBot constructor(
|
internal open class QQAndroidBot constructor(
|
||||||
internal val account: BotAccount,
|
internal val account: BotAccount,
|
||||||
configuration: BotConfiguration,
|
configuration: BotConfiguration,
|
||||||
private val debugConfiguration: BotDebugConfiguration = BotDebugConfiguration(),
|
|
||||||
) : AbstractBot(configuration, account.id) {
|
) : AbstractBot(configuration, account.id) {
|
||||||
override val bot: QQAndroidBot get() = this
|
override val bot: QQAndroidBot get() = this
|
||||||
val client get() = components[SsoProcessor].client
|
val client get() = components[SsoProcessor].client
|
||||||
@ -69,11 +62,10 @@ internal open class QQAndroidBot constructor(
|
|||||||
// network
|
// network
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
private val ComponentStorage.eventDispatcher get() = this[EventDispatcher]
|
|
||||||
|
|
||||||
// also called by tests.
|
// also called by tests.
|
||||||
fun ComponentStorage.stateObserverChain(): StateObserver {
|
fun ComponentStorage.stateObserverChain(): StateObserver {
|
||||||
val components = this
|
val components = this
|
||||||
|
val eventDispatcher = this[EventDispatcher]
|
||||||
return StateObserver.chainOfNotNull(
|
return StateObserver.chainOfNotNull(
|
||||||
components[BotInitProcessor].asObserver(),
|
components[BotInitProcessor].asObserver(),
|
||||||
object : StateChangedObserver(State.OK) {
|
object : StateChangedObserver(State.OK) {
|
||||||
@ -84,9 +76,9 @@ internal open class QQAndroidBot constructor(
|
|||||||
previous: BaseStateImpl,
|
previous: BaseStateImpl,
|
||||||
new: BaseStateImpl
|
new: BaseStateImpl
|
||||||
) {
|
) {
|
||||||
components.eventDispatcher.broadcastAsync(BotOnlineEvent(bot)).onSuccess {
|
eventDispatcher.broadcastAsync(BotOnlineEvent(bot)).onSuccess {
|
||||||
if (!shouldBroadcastRelogin.compareAndSet(false, true)) {
|
if (!shouldBroadcastRelogin.compareAndSet(false, true)) {
|
||||||
components.eventDispatcher.broadcastAsync(BotReloginEvent(bot, new.getCause()))
|
eventDispatcher.broadcastAsync(BotReloginEvent(bot, new.getCause()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -94,9 +86,9 @@ internal open class QQAndroidBot constructor(
|
|||||||
StateChangedObserver(State.OK, State.CLOSED) { new ->
|
StateChangedObserver(State.OK, State.CLOSED) { new ->
|
||||||
val cause = new.getCause()
|
val cause = new.getCause()
|
||||||
if (cause is NetworkException && cause.recoverable) {
|
if (cause is NetworkException && cause.recoverable) {
|
||||||
components.eventDispatcher.broadcastAsync(BotOfflineEvent.Dropped(bot, new.getCause()))
|
eventDispatcher.broadcastAsync(BotOfflineEvent.Dropped(bot, new.getCause()))
|
||||||
} else {
|
} else {
|
||||||
components.eventDispatcher.broadcastAsync(BotOfflineEvent.Active(bot, new.getCause()))
|
eventDispatcher.broadcastAsync(BotOfflineEvent.Active(bot, new.getCause()))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
StateChangedObserver(to = State.OK) { new ->
|
StateChangedObserver(to = State.OK) { new ->
|
||||||
@ -110,7 +102,6 @@ internal open class QQAndroidBot constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
debugConfiguration.stateObserver
|
|
||||||
).safe(logger.subLogger("StateObserver"))
|
).safe(logger.subLogger("StateObserver"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,6 @@ internal val MockConfiguration = BotConfiguration {
|
|||||||
|
|
||||||
internal class MockBotBuilder(
|
internal class MockBotBuilder(
|
||||||
val conf: BotConfiguration = BotConfiguration(),
|
val conf: BotConfiguration = BotConfiguration(),
|
||||||
val debugConf: BotDebugConfiguration = BotDebugConfiguration(),
|
|
||||||
) {
|
) {
|
||||||
var nhProvider: (QQAndroidBot.(bot: QQAndroidBot) -> NetworkHandler)? = null
|
var nhProvider: (QQAndroidBot.(bot: QQAndroidBot) -> NetworkHandler)? = null
|
||||||
var componentsProvider: (QQAndroidBot.(bot: QQAndroidBot) -> ComponentStorage)? = null
|
var componentsProvider: (QQAndroidBot.(bot: QQAndroidBot) -> ComponentStorage)? = null
|
||||||
@ -38,12 +37,6 @@ internal class MockBotBuilder(
|
|||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
fun debugConf(action: BotDebugConfiguration.() -> Unit): MockBotBuilder {
|
|
||||||
contract { callsInPlace(action, InvocationKind.EXACTLY_ONCE) }
|
|
||||||
debugConf.apply(action)
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
fun networkHandlerProvider(provider: QQAndroidBot.(bot: QQAndroidBot) -> NetworkHandler): MockBotBuilder {
|
fun networkHandlerProvider(provider: QQAndroidBot.(bot: QQAndroidBot) -> NetworkHandler): MockBotBuilder {
|
||||||
this.nhProvider = provider
|
this.nhProvider = provider
|
||||||
return this
|
return this
|
||||||
@ -53,7 +46,7 @@ internal class MockBotBuilder(
|
|||||||
@Suppress("TestFunctionName")
|
@Suppress("TestFunctionName")
|
||||||
internal fun MockBot(conf: MockBotBuilder.() -> Unit = {}) =
|
internal fun MockBot(conf: MockBotBuilder.() -> Unit = {}) =
|
||||||
MockBotBuilder(MockConfiguration.copy()).apply(conf).run {
|
MockBotBuilder(MockConfiguration.copy()).apply(conf).run {
|
||||||
object : QQAndroidBot(MockAccount, this.conf, debugConf) {
|
object : QQAndroidBot(MockAccount, this.conf) {
|
||||||
override val components: ComponentStorage by lazy {
|
override val components: ComponentStorage by lazy {
|
||||||
componentsProvider?.invoke(this, this) ?: EMPTY_COMPONENT_STORAGE
|
componentsProvider?.invoke(this, this) ?: EMPTY_COMPONENT_STORAGE
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user