runCommand handles a line that starts with "/". Returns true if handled, false if the line should fall through to the model as a normal message.
(line string)
| 94 | // runCommand handles a line that starts with "/". Returns true if handled, |
| 95 | // false if the line should fall through to the model as a normal message. |
| 96 | func runCommand(line string) bool { |
| 97 | if !strings.HasPrefix(line, "/") { |
| 98 | return false |
| 99 | } |
| 100 | parts := strings.SplitN(strings.TrimPrefix(line, "/"), " ", 2) |
| 101 | name := parts[0] |
| 102 | args := "" |
| 103 | if len(parts) > 1 { |
| 104 | args = strings.TrimSpace(parts[1]) |
| 105 | } |
| 106 | c, ok := commands[name] |
| 107 | if !ok { |
| 108 | fmt.Printf("unknown command: /%s (try /help)\n", name) |
| 109 | return true |
| 110 | } |
| 111 | c.run(args) |
| 112 | return true |
| 113 | } |
| 114 | |
| 115 | func cmdHelp(_ string) { |
| 116 | names := make([]string, 0, len(commands)) |