fix command sender flush bug

This commit is contained in:
jiahua.liu 2020-02-25 18:01:10 +08:00
parent a126e3f660
commit 9ff70b0dbb
2 changed files with 8 additions and 2 deletions

View File

@ -106,13 +106,13 @@ interface CommandSender {
}
abstract class CommandSenderImpl : CommandSender {
private val builder = StringBuilder()
internal val builder = StringBuilder()
override fun appendMessage(message: String) {
builder.append(message).append("\n")
}
internal suspend fun flushMessage() {
internal open suspend fun flushMessage() {
if (!builder.isEmpty()) {
sendMessage(builder.toString().removeSuffix("\n"))
}
@ -127,6 +127,11 @@ object ConsoleCommandSender : CommandSenderImpl() {
override suspend fun sendMessage(message: String) {
MiraiConsole.logger("[Command]", 0, message)
}
override suspend fun flushMessage() {
super.flushMessage()
builder.clear()
}
}
open class ContactCommandSender(val contact: Contact) : CommandSenderImpl() {

View File

@ -237,6 +237,7 @@ object DefaultCommands {
onCommand {
CommandManager.getCommands().let {
var size = 0
appendMessage("")//\n
it.toSet().forEach {
++size
appendMessage("-> " + it.name + " :" + it.description)