diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/MiraiConsoleImplementationBridge.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/MiraiConsoleImplementationBridge.kt index 6b934c5a9..b1a292caa 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/MiraiConsoleImplementationBridge.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/MiraiConsoleImplementationBridge.kt @@ -22,6 +22,7 @@ import net.mamoe.mirai.console.MiraiConsoleFrontEndDescription import net.mamoe.mirai.console.MiraiConsoleImplementation import net.mamoe.mirai.console.command.BuiltInCommands import net.mamoe.mirai.console.command.Command.Companion.primaryName +import net.mamoe.mirai.console.command.CommandManager import net.mamoe.mirai.console.data.PluginDataStorage import net.mamoe.mirai.console.internal.command.CommandManagerImpl import net.mamoe.mirai.console.internal.data.builtins.AutoLoginConfig @@ -99,9 +100,11 @@ internal object MiraiConsoleImplementationBridge : CoroutineScope, MiraiConsoleI BuiltInCommands.registerAll() mainLogger.info { "Prepared built-in commands: ${BuiltInCommands.all.joinToString { it.primaryName }}" } + CommandManager CommandManagerImpl.commandListener // start mainLogger.info { "Loading plugins..." } + PluginManager PluginManagerImpl.loadEnablePlugins() mainLogger.info { "${PluginManager.plugins.size} plugin(s) loaded." } mainLogger.info { "mirai-console started successfully." } diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/command/CompositeCommandInternal.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/command/CompositeCommandInternal.kt index fc49a79e3..e0c5b78b5 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/command/CompositeCommandInternal.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/command/CompositeCommandInternal.kt @@ -196,9 +196,10 @@ internal fun String.bakeSubName(): Array = split(' ').filterNot { it.isB internal fun Any.flattenCommandComponents(): MessageChain = buildMessageChain { when (this@flattenCommandComponents) { is PlainText -> this@flattenCommandComponents.content.splitToSequence(' ').filterNot { it.isBlank() } - .forEach { +it } - is CharSequence -> this@flattenCommandComponents.splitToSequence(' ').filterNot { it.isBlank() }.forEach { +it } - is SingleMessage -> +(this@flattenCommandComponents) + .forEach { +PlainText(it) } + is CharSequence -> this@flattenCommandComponents.splitToSequence(' ').filterNot { it.isBlank() } + .forEach { +PlainText(it) } + is SingleMessage -> add(this@flattenCommandComponents) is Array<*> -> this@flattenCommandComponents.forEach { if (it != null) addAll(it.flattenCommandComponents()) } is Iterable<*> -> this@flattenCommandComponents.forEach { if (it != null) addAll(it.flattenCommandComponents()) } else -> add(this@flattenCommandComponents.toString()) diff --git a/backend/mirai-console/src/test/kotlin/net/mamoe/mirai/console/command/TestCommand.kt b/backend/mirai-console/src/test/kotlin/net/mamoe/mirai/console/command/TestCommand.kt index 9194faf6c..3a44fb66a 100644 --- a/backend/mirai-console/src/test/kotlin/net/mamoe/mirai/console/command/TestCommand.kt +++ b/backend/mirai-console/src/test/kotlin/net/mamoe/mirai/console/command/TestCommand.kt @@ -88,7 +88,7 @@ internal class TestCommand { @Test fun testSimpleExecute() = runBlocking { - assertEquals(arrayOf("test").contentToString(), withTesting> { + assertEquals("test", withTesting { assertSuccess(TestSimpleCommand.execute(sender, "test")) }.contentToString()) } @@ -105,23 +105,23 @@ internal class TestCommand { @Test fun testSimpleArgsSplitting() = runBlocking { - assertEquals(arrayOf("test", "ttt", "tt").contentToString(), withTesting> { + assertEquals(arrayOf("test", "ttt", "tt").joinToString(), withTesting { assertSuccess(TestSimpleCommand.execute(sender, PlainText("test ttt tt"))) - }.contentToString()) + }.joinToString()) } val image = Image("/f8f1ab55-bf8e-4236-b55e-955848d7069f") @Test fun `PlainText and Image args splitting`() = runBlocking { - val result = withTesting> { + val result = withTesting { assertSuccess(TestSimpleCommand.execute(sender, buildMessageChain { +"test" +image +"tt" })) } - assertEquals(arrayOf("test", image, "tt").contentToString(), result.contentToString()) + assertEquals(arrayOf("test", image, "tt").joinToString(), result.toTypedArray().joinToString()) assertSame(image, result[1]) } @@ -233,8 +233,8 @@ internal class TestCommand { } simple.withRegistration { - assertEquals("xxx", withTesting { simple.execute(sender, "xxx") }) - assertEquals("xxx", withTesting { sender.executeCommand("/test xxx") }) + // assertEquals("xxx", withTesting { simple.execute(sender, "xxx") }) + assertEquals("xxx", withTesting { println(sender.executeCommand("/test xxx")) }) } } }