mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-10 18:40:15 +08:00
Misc improvements
This commit is contained in:
parent
39f0eeb508
commit
21ca9f9fb9
@ -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 许可证的约束, 可以在以下链接找到该许可证.
|
* 此源代码的使用受 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.
|
* 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
|
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)
|
throw IllegalStateException("Failed to init command ${command}.", it)
|
||||||
}
|
}
|
||||||
|
|
||||||
this@CommandManagerImpl.modifyLock.withLock {
|
modifyLock.withLock {
|
||||||
if (!override) {
|
if (!override) {
|
||||||
if (command.findDuplicate() != null) return false
|
if (command.findDuplicate() != null) return false
|
||||||
}
|
}
|
||||||
this@CommandManagerImpl._registeredCommands.add(command)
|
_registeredCommands.add(command)
|
||||||
if (command.prefixOptional) {
|
if (command.prefixOptional) {
|
||||||
for (name in command.allNames) {
|
for (name in command.allNames) {
|
||||||
val lowerCaseName = name.toLowerCase()
|
val lowerCaseName = name.toLowerCase()
|
||||||
this@CommandManagerImpl.optionalPrefixCommandMap[lowerCaseName] = command
|
optionalPrefixCommandMap[lowerCaseName] = command
|
||||||
this@CommandManagerImpl.requiredPrefixCommandMap[lowerCaseName] = command
|
requiredPrefixCommandMap[lowerCaseName] = command
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (name in command.allNames) {
|
for (name in command.allNames) {
|
||||||
val lowerCaseName = name.toLowerCase()
|
val lowerCaseName = name.toLowerCase()
|
||||||
this@CommandManagerImpl.optionalPrefixCommandMap.remove(lowerCaseName) // ensure resolution consistency
|
optionalPrefixCommandMap.remove(lowerCaseName) // ensure resolution consistency
|
||||||
this@CommandManagerImpl.requiredPrefixCommandMap[lowerCaseName] = command
|
requiredPrefixCommandMap[lowerCaseName] = command
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
@ -9,7 +9,8 @@
|
|||||||
|
|
||||||
package net.mamoe.mirai.console
|
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.JvmPluginDescription
|
||||||
import net.mamoe.mirai.console.plugin.jvm.KotlinPlugin
|
import net.mamoe.mirai.console.plugin.jvm.KotlinPlugin
|
||||||
import org.junit.jupiter.api.AfterEach
|
import org.junit.jupiter.api.AfterEach
|
||||||
@ -25,6 +26,6 @@ abstract class AbstractConsoleTest {
|
|||||||
|
|
||||||
@AfterEach
|
@AfterEach
|
||||||
fun afterTest() {
|
fun afterTest() {
|
||||||
MiraiConsole.cancel()
|
runBlocking { MiraiConsole.job.cancelAndJoin() }
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user