Lift of 'return'

This commit is contained in:
Benoit Marty 2019-11-04 16:53:51 +01:00
parent 7206d84a6b
commit e4b829f0cf
1 changed files with 17 additions and 16 deletions

View File

@ -56,11 +56,12 @@ object CommandParser {
return ParsedCommand.ErrorEmptySlashCommand return ParsedCommand.ErrorEmptySlashCommand
} }
when (val slashCommand = messageParts.first()) {
return when (val slashCommand = messageParts.first()) {
Command.CHANGE_DISPLAY_NAME.command -> { Command.CHANGE_DISPLAY_NAME.command -> {
val newDisplayName = textMessage.substring(Command.CHANGE_DISPLAY_NAME.command.length).trim() val newDisplayName = textMessage.substring(Command.CHANGE_DISPLAY_NAME.command.length).trim()
return if (newDisplayName.isNotEmpty()) { if (newDisplayName.isNotEmpty()) {
ParsedCommand.ChangeDisplayName(newDisplayName) ParsedCommand.ChangeDisplayName(newDisplayName)
} else { } else {
ParsedCommand.ErrorSyntax(Command.CHANGE_DISPLAY_NAME) ParsedCommand.ErrorSyntax(Command.CHANGE_DISPLAY_NAME)
@ -69,7 +70,7 @@ object CommandParser {
Command.TOPIC.command -> { Command.TOPIC.command -> {
val newTopic = textMessage.substring(Command.TOPIC.command.length).trim() val newTopic = textMessage.substring(Command.TOPIC.command.length).trim()
return if (newTopic.isNotEmpty()) { if (newTopic.isNotEmpty()) {
ParsedCommand.ChangeTopic(newTopic) ParsedCommand.ChangeTopic(newTopic)
} else { } else {
ParsedCommand.ErrorSyntax(Command.TOPIC) ParsedCommand.ErrorSyntax(Command.TOPIC)
@ -78,12 +79,12 @@ object CommandParser {
Command.EMOTE.command -> { Command.EMOTE.command -> {
val message = textMessage.substring(Command.EMOTE.command.length).trim() val message = textMessage.substring(Command.EMOTE.command.length).trim()
return ParsedCommand.SendEmote(message) ParsedCommand.SendEmote(message)
} }
Command.JOIN_ROOM.command -> { Command.JOIN_ROOM.command -> {
val roomAlias = textMessage.substring(Command.JOIN_ROOM.command.length).trim() val roomAlias = textMessage.substring(Command.JOIN_ROOM.command.length).trim()
return if (roomAlias.isNotEmpty()) { if (roomAlias.isNotEmpty()) {
ParsedCommand.JoinRoom(roomAlias) ParsedCommand.JoinRoom(roomAlias)
} else { } else {
ParsedCommand.ErrorSyntax(Command.JOIN_ROOM) ParsedCommand.ErrorSyntax(Command.JOIN_ROOM)
@ -92,14 +93,14 @@ object CommandParser {
Command.PART.command -> { Command.PART.command -> {
val roomAlias = textMessage.substring(Command.PART.command.length).trim() val roomAlias = textMessage.substring(Command.PART.command.length).trim()
return if (roomAlias.isNotEmpty()) { if (roomAlias.isNotEmpty()) {
ParsedCommand.PartRoom(roomAlias) ParsedCommand.PartRoom(roomAlias)
} else { } else {
ParsedCommand.ErrorSyntax(Command.PART) ParsedCommand.ErrorSyntax(Command.PART)
} }
} }
Command.INVITE.command -> { Command.INVITE.command -> {
return if (messageParts.size == 2) { if (messageParts.size == 2) {
val userId = messageParts[1] val userId = messageParts[1]
if (MatrixPatterns.isUserId(userId)) { if (MatrixPatterns.isUserId(userId)) {
@ -112,7 +113,7 @@ object CommandParser {
} }
} }
Command.KICK_USER.command -> { Command.KICK_USER.command -> {
return if (messageParts.size >= 2) { if (messageParts.size >= 2) {
val userId = messageParts[1] val userId = messageParts[1]
if (MatrixPatterns.isUserId(userId)) { if (MatrixPatterns.isUserId(userId)) {
val reason = textMessage.substring(Command.KICK_USER.command.length val reason = textMessage.substring(Command.KICK_USER.command.length
@ -128,7 +129,7 @@ object CommandParser {
} }
} }
Command.BAN_USER.command -> { Command.BAN_USER.command -> {
return if (messageParts.size >= 2) { if (messageParts.size >= 2) {
val userId = messageParts[1] val userId = messageParts[1]
if (MatrixPatterns.isUserId(userId)) { if (MatrixPatterns.isUserId(userId)) {
val reason = textMessage.substring(Command.BAN_USER.command.length val reason = textMessage.substring(Command.BAN_USER.command.length
@ -144,7 +145,7 @@ object CommandParser {
} }
} }
Command.UNBAN_USER.command -> { Command.UNBAN_USER.command -> {
return if (messageParts.size == 2) { if (messageParts.size == 2) {
val userId = messageParts[1] val userId = messageParts[1]
if (MatrixPatterns.isUserId(userId)) { if (MatrixPatterns.isUserId(userId)) {
@ -157,7 +158,7 @@ object CommandParser {
} }
} }
Command.SET_USER_POWER_LEVEL.command -> { Command.SET_USER_POWER_LEVEL.command -> {
return if (messageParts.size == 3) { if (messageParts.size == 3) {
val userId = messageParts[1] val userId = messageParts[1]
if (MatrixPatterns.isUserId(userId)) { if (MatrixPatterns.isUserId(userId)) {
val powerLevelsAsString = messageParts[2] val powerLevelsAsString = messageParts[2]
@ -177,7 +178,7 @@ object CommandParser {
} }
} }
Command.RESET_USER_POWER_LEVEL.command -> { Command.RESET_USER_POWER_LEVEL.command -> {
return if (messageParts.size == 2) { if (messageParts.size == 2) {
val userId = messageParts[1] val userId = messageParts[1]
if (MatrixPatterns.isUserId(userId)) { if (MatrixPatterns.isUserId(userId)) {
@ -190,7 +191,7 @@ object CommandParser {
} }
} }
Command.MARKDOWN.command -> { Command.MARKDOWN.command -> {
return if (messageParts.size == 2) { if (messageParts.size == 2) {
when { when {
"on".equals(messageParts[1], true) -> ParsedCommand.SetMarkdown(true) "on".equals(messageParts[1], true) -> ParsedCommand.SetMarkdown(true)
"off".equals(messageParts[1], true) -> ParsedCommand.SetMarkdown(false) "off".equals(messageParts[1], true) -> ParsedCommand.SetMarkdown(false)
@ -201,7 +202,7 @@ object CommandParser {
} }
} }
Command.CLEAR_SCALAR_TOKEN.command -> { Command.CLEAR_SCALAR_TOKEN.command -> {
return if (messageParts.size == 1) { if (messageParts.size == 1) {
ParsedCommand.ClearScalarToken ParsedCommand.ClearScalarToken
} else { } else {
ParsedCommand.ErrorSyntax(Command.CLEAR_SCALAR_TOKEN) ParsedCommand.ErrorSyntax(Command.CLEAR_SCALAR_TOKEN)
@ -210,11 +211,11 @@ object CommandParser {
Command.SPOILER.command -> { Command.SPOILER.command -> {
val message = textMessage.substring(Command.SPOILER.command.length).trim() val message = textMessage.substring(Command.SPOILER.command.length).trim()
return ParsedCommand.SendSpoiler(message) ParsedCommand.SendSpoiler(message)
} }
else -> { else -> {
// Unknown command // Unknown command
return ParsedCommand.ErrorUnknownSlashCommand(slashCommand) ParsedCommand.ErrorUnknownSlashCommand(slashCommand)
} }
} }
} }