ref: 78e3bc4908c7b6c2d7b5e39ba485fb0f8e0113f7
dir: /commands.go/
package main
import (
"strings"
)
var commands = []string{"examine", "reply", "like", "thread", "open", "preview", "dm", "rt", "parent", "children", "thread", "rm"}
func processInput(input string) (command string, arguments string) {
if input == "" {
command = ""
arguments = ""
return
}
if input[0] != '/' {
command = ""
arguments = input
return
}
input = input[1:]
command = "Command not found"
arguments = ""
commandInput := ""
firstSpaceIdx := strings.Index(input, " ")
if firstSpaceIdx == -1 {
commandInput = input
arguments = ""
} else {
commandInput = input[:firstSpaceIdx]
arguments = strings.TrimSpace(input[firstSpaceIdx+1:])
}
for _, cmd := range commands {
if strings.HasPrefix(cmd, commandInput) {
if command == "" || len(cmd) < len(command) {
command = cmd
}
}
}
return
}