Small kotlin improvement

This commit is contained in:
Benoit Marty 2019-10-29 16:20:22 +01:00
parent 361427488f
commit 6567c5e6c7
1 changed files with 19 additions and 22 deletions

View File

@ -44,12 +44,11 @@ object CommandParser {
return ParsedCommand.ErrorNotACommand
}
var messageParts: List<String>? = null
try {
messageParts = textMessage.split("\\s+".toRegex()).dropLastWhile { it.isEmpty() }
val messageParts = try {
textMessage.split("\\s+".toRegex()).dropLastWhile { it.isEmpty() }
} catch (e: Exception) {
Timber.e(e, "## manageSplashCommand() : split failed")
null
}
// test if the string cut fails
@ -57,9 +56,7 @@ object CommandParser {
return ParsedCommand.ErrorEmptySlashCommand
}
val slashCommand = messageParts[0]
when (slashCommand) {
when (val slashCommand = messageParts.first()) {
Command.CHANGE_DISPLAY_NAME.command -> {
val newDisplayName = textMessage.substring(Command.CHANGE_DISPLAY_NAME.command.length).trim()