Skip to content

Commit

Permalink
fix #38, wrong loading order
Browse files Browse the repository at this point in the history
  • Loading branch information
MrXiaoM committed Apr 19, 2024
1 parent 0bb5503 commit 4029f15
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,6 @@ internal fun addBotListeners() {
UnsolvedEventListener(),

).forEach(EventBus::addListener)

GlobalEventChannel
.parentScope(Overflow.scope)
.context(Overflow.scope.coroutineContext)
.subscribeAlways<UnsolvedOnebotEvent>(priority = EventPriority.LOWEST) {
if (!isCancelled) {
logger.warning("接收到来自协议端的未知事件 $messageRaw")
}
}
}

internal class UnsolvedEventListener : EventListener<UnsolvedEvent> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package top.mrxiaom.overflow.internal.plugin

import kotlinx.coroutines.CoroutineName
import kotlinx.coroutines.runBlocking
import net.mamoe.mirai.Bot
import net.mamoe.mirai.console.ConsoleFrontEndImplementation
import net.mamoe.mirai.console.MiraiConsole
import net.mamoe.mirai.console.MiraiConsoleImplementation
import net.mamoe.mirai.console.command.*
import net.mamoe.mirai.console.command.CommandManager.INSTANCE.register
import net.mamoe.mirai.console.events.StartupEvent
import net.mamoe.mirai.console.extensions.PostStartupExtension
import net.mamoe.mirai.console.internal.data.builtins.AutoLoginConfig
import net.mamoe.mirai.console.permission.Permission
import net.mamoe.mirai.console.permission.PermissionId
Expand All @@ -21,7 +18,8 @@ import net.mamoe.mirai.console.plugin.loader.PluginLoader
import net.mamoe.mirai.console.util.ConsoleExperimentalApi
import net.mamoe.mirai.console.util.SemVersion
import net.mamoe.mirai.console.util.sendAnsiMessage
import net.mamoe.mirai.event.ConcurrencyKind
import net.mamoe.mirai.event.Event
import net.mamoe.mirai.event.EventChannel
import net.mamoe.mirai.event.EventPriority
import net.mamoe.mirai.event.GlobalEventChannel
import net.mamoe.mirai.utils.MiraiLogger
Expand All @@ -30,6 +28,7 @@ import org.java_websocket.client.WebSocketClient
import org.slf4j.Logger
import top.mrxiaom.overflow.OverflowAPI
import top.mrxiaom.overflow.contact.RemoteBot.Companion.asRemoteBot
import top.mrxiaom.overflow.event.UnsolvedOnebotEvent
import top.mrxiaom.overflow.internal.Overflow
import top.mrxiaom.overflow.internal.asOnebot
import top.mrxiaom.overflow.internal.message.OnebotMessages
Expand All @@ -46,8 +45,11 @@ internal object OverflowCoreAsPlugin : Plugin, CommandOwner {
override val parentPermission: Permission
get() = ConsoleCommandOwner.parentPermission

private val logger: MiraiLogger
get() = OverflowAPI.logger
private lateinit var miraiLogger: MiraiLogger
private lateinit var oneBotLogger: Logger
internal lateinit var channel: EventChannel<Event>

override fun permissionId(name: String): PermissionId {
return ConsoleCommandOwner.permissionId(name)
Expand All @@ -58,13 +60,20 @@ internal object OverflowCoreAsPlugin : Plugin, CommandOwner {
miraiLogger = LoggerInFolder(Overflow::class, "Onebot", File("logs/onebot"), 1.weeksToMillis)
oneBotLogger = net.mamoe.mirai.console.internal.logging.externalbind.slf4j.SLF4JAdapterLogger(miraiLogger)

GlobalEventChannel
channel = GlobalEventChannel
.parentScope(MiraiConsole.INSTANCE)
.context(MiraiConsole.INSTANCE.coroutineContext)
.subscribeOnce<StartupEvent>(

channel.subscribeOnce<StartupEvent>(
priority = EventPriority.HIGHEST,
) { onPostStartup() }

channel.subscribeAlways<UnsolvedOnebotEvent>(priority = EventPriority.LOWEST) {
if (!isCancelled) {
logger.warning("接收到来自协议端的未知事件 $messageRaw")
}
}

OnebotMessages.registerSerializers()

// No AutoLogin
Expand All @@ -77,7 +86,7 @@ internal object OverflowCoreAsPlugin : Plugin, CommandOwner {
val backup = File(configFolder, "Console/AutoLogin.yml.overflow.${System.currentTimeMillis()}.old")
file.copyTo(backup)
accounts.clear()
OverflowAPI.logger.warning("由于 mirai 端不再需要处理登录,Overflow 已清空自动登录配置,旧配置已备份到 ${backup.name}")
logger.warning("由于 mirai 端不再需要处理登录,Overflow 已清空自动登录配置,旧配置已备份到 ${backup.name}")
}
}

Expand Down Expand Up @@ -162,7 +171,7 @@ internal object OverflowCoreAsPlugin : Plugin, CommandOwner {
private suspend fun StartupEvent.onPostStartup() {
runCatching {
net.mamoe.mirai.internal.spi.EncryptService.factory?.also {
OverflowAPI.logger.apply {
logger.apply {
warning("-------------------------------------------")
warning("你的 mirai-console 中已安装签名服务!")
warning("这在 overflow 中是不必要的,请移除签名服务相关插件")
Expand Down

0 comments on commit 4029f15

Please sign in to comment.