Small cleanup
This commit is contained in:
parent
eb4475b4d9
commit
4f1de34d4c
|
@ -35,11 +35,9 @@ class CommandParser @Inject constructor() {
|
||||||
*/
|
*/
|
||||||
fun parseSlashCommand(textMessage: CharSequence): ParsedCommand {
|
fun parseSlashCommand(textMessage: CharSequence): ParsedCommand {
|
||||||
// check if it has the Slash marker
|
// check if it has the Slash marker
|
||||||
if (!textMessage.startsWith("/")) {
|
return if (!textMessage.startsWith("/")) {
|
||||||
return ParsedCommand.ErrorNotACommand
|
ParsedCommand.ErrorNotACommand
|
||||||
} else {
|
} else {
|
||||||
Timber.v("parseSlashCommand")
|
|
||||||
|
|
||||||
// "/" only
|
// "/" only
|
||||||
if (textMessage.length == 1) {
|
if (textMessage.length == 1) {
|
||||||
return ParsedCommand.ErrorEmptySlashCommand
|
return ParsedCommand.ErrorEmptySlashCommand
|
||||||
|
@ -53,7 +51,7 @@ class CommandParser @Inject constructor() {
|
||||||
val messageParts = try {
|
val messageParts = try {
|
||||||
textMessage.split("\\s+".toRegex()).dropLastWhile { it.isEmpty() }
|
textMessage.split("\\s+".toRegex()).dropLastWhile { it.isEmpty() }
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Timber.e(e, "## manageSlashCommand() : split failed")
|
Timber.e(e, "## parseSlashCommand() : split failed")
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,7 +63,7 @@ class CommandParser @Inject constructor() {
|
||||||
val slashCommand = messageParts.first()
|
val slashCommand = messageParts.first()
|
||||||
val message = textMessage.substring(slashCommand.length).trim()
|
val message = textMessage.substring(slashCommand.length).trim()
|
||||||
|
|
||||||
return when {
|
when {
|
||||||
Command.PLAIN.matches(slashCommand) -> {
|
Command.PLAIN.matches(slashCommand) -> {
|
||||||
if (message.isNotEmpty()) {
|
if (message.isNotEmpty()) {
|
||||||
ParsedCommand.SendPlainText(message = message)
|
ParsedCommand.SendPlainText(message = message)
|
||||||
|
|
Loading…
Reference in New Issue