Commit 35669b28 authored by Him188's avatar Him188

Add BotOfflineEvent

parent 0d505e51
......@@ -3,6 +3,8 @@
package net.mamoe.mirai
import kotlinx.coroutines.*
import net.mamoe.mirai.event.broadcast
import net.mamoe.mirai.event.events.BotOfflineEvent
import net.mamoe.mirai.network.BotNetworkHandler
import net.mamoe.mirai.utils.*
import net.mamoe.mirai.utils.io.logStacktrace
......@@ -41,6 +43,7 @@ abstract class BotImpl<N : BotNetworkHandler> constructor(
fun instanceWhose(qq: Long): Bot {
instances.forEach {
@Suppress("PropertyName")
if (it.uin == qq) {
return it
}
......@@ -55,6 +58,7 @@ abstract class BotImpl<N : BotNetworkHandler> constructor(
final override val network: N get() = _network
@Suppress("PropertyName")
internal lateinit var _network: N
final override suspend fun login() = reinitializeNetworkHandler(null)
......@@ -86,6 +90,7 @@ abstract class BotImpl<N : BotNetworkHandler> constructor(
logger.info("Initializing BotNetworkHandler")
try {
if (::_network.isInitialized) {
BotOfflineEvent(this).broadcast()
_network.dispose(cause)
}
} catch (e: Exception) {
......
......@@ -15,4 +15,6 @@ abstract class BotEvent : Event {
constructor() : super()
}
class BotLoginSucceedEvent(bot: Bot) : BotEvent(bot)
\ No newline at end of file
class BotLoginSucceedEvent(bot: Bot) : BotEvent(bot)
class BotOfflineEvent(bot: Bot) : BotEvent(bot)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment