mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-25 15:40:28 +08:00
Fix commands
This commit is contained in:
parent
9ff9f94f5d
commit
a10e48cc36
@ -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." }
|
||||
|
@ -196,9 +196,10 @@ internal fun String.bakeSubName(): Array<String> = 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())
|
||||
|
@ -88,7 +88,7 @@ internal class TestCommand {
|
||||
|
||||
@Test
|
||||
fun testSimpleExecute() = runBlocking {
|
||||
assertEquals(arrayOf("test").contentToString(), withTesting<Array<String>> {
|
||||
assertEquals("test", withTesting<MessageChain> {
|
||||
assertSuccess(TestSimpleCommand.execute(sender, "test"))
|
||||
}.contentToString())
|
||||
}
|
||||
@ -105,23 +105,23 @@ internal class TestCommand {
|
||||
|
||||
@Test
|
||||
fun testSimpleArgsSplitting() = runBlocking {
|
||||
assertEquals(arrayOf("test", "ttt", "tt").contentToString(), withTesting<Array<String>> {
|
||||
assertEquals(arrayOf("test", "ttt", "tt").joinToString(), withTesting<MessageChain> {
|
||||
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<Array<Any>> {
|
||||
val result = withTesting<MessageChain> {
|
||||
assertSuccess(TestSimpleCommand.execute(sender, buildMessageChain {
|
||||
+"test"
|
||||
+image
|
||||
+"tt"
|
||||
}))
|
||||
}
|
||||
assertEquals(arrayOf("test", image, "tt").contentToString(), result.contentToString())
|
||||
assertEquals<Any>(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")) })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user