diff --git a/backend/mirai-console/src/internal/command/CommandManagerImpl.kt b/backend/mirai-console/src/internal/command/CommandManagerImpl.kt index 5cc8e49cb..fe9e81570 100644 --- a/backend/mirai-console/src/internal/command/CommandManagerImpl.kt +++ b/backend/mirai-console/src/internal/command/CommandManagerImpl.kt @@ -1,10 +1,10 @@ /* - * Copyright 2019-2020 Mamoe Technologies and contributors. + * Copyright 2019-2021 Mamoe Technologies and contributors. * - * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AFFERO GENERAL PUBLIC LICENSE version 3 license that can be found through the following link. + * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. + * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. * - * https://github.com/mamoe/mirai/blob/master/LICENSE + * https://github.com/mamoe/mirai/blob/master/LICENSE */ package net.mamoe.mirai.console.internal.command @@ -83,22 +83,22 @@ internal object CommandManagerImpl : CommandManager, CoroutineScope by MiraiCons throw IllegalStateException("Failed to init command ${command}.", it) } - this@CommandManagerImpl.modifyLock.withLock { + modifyLock.withLock { if (!override) { if (command.findDuplicate() != null) return false } - this@CommandManagerImpl._registeredCommands.add(command) + _registeredCommands.add(command) if (command.prefixOptional) { for (name in command.allNames) { val lowerCaseName = name.toLowerCase() - this@CommandManagerImpl.optionalPrefixCommandMap[lowerCaseName] = command - this@CommandManagerImpl.requiredPrefixCommandMap[lowerCaseName] = command + optionalPrefixCommandMap[lowerCaseName] = command + requiredPrefixCommandMap[lowerCaseName] = command } } else { for (name in command.allNames) { val lowerCaseName = name.toLowerCase() - this@CommandManagerImpl.optionalPrefixCommandMap.remove(lowerCaseName) // ensure resolution consistency - this@CommandManagerImpl.requiredPrefixCommandMap[lowerCaseName] = command + optionalPrefixCommandMap.remove(lowerCaseName) // ensure resolution consistency + requiredPrefixCommandMap[lowerCaseName] = command } } return true diff --git a/backend/mirai-console/test/AbstractConsoleTest.kt b/backend/mirai-console/test/AbstractConsoleTest.kt index 60f7e19fc..54e58265b 100644 --- a/backend/mirai-console/test/AbstractConsoleTest.kt +++ b/backend/mirai-console/test/AbstractConsoleTest.kt @@ -9,7 +9,8 @@ package net.mamoe.mirai.console -import kotlinx.coroutines.cancel +import kotlinx.coroutines.cancelAndJoin +import kotlinx.coroutines.runBlocking import net.mamoe.mirai.console.plugin.jvm.JvmPluginDescription import net.mamoe.mirai.console.plugin.jvm.KotlinPlugin import org.junit.jupiter.api.AfterEach @@ -25,6 +26,6 @@ abstract class AbstractConsoleTest { @AfterEach fun afterTest() { - MiraiConsole.cancel() + runBlocking { MiraiConsole.job.cancelAndJoin() } } } \ No newline at end of file