Got basic last command memory working

This commit is contained in:
2026-01-21 20:33:17 -07:00
parent b2f088d4e1
commit 1758961a66
2 changed files with 36 additions and 9 deletions

2
.gitignore vendored
View File

@@ -1 +1,3 @@
/bin /bin
/result
sox

43
main.go
View File

@@ -33,6 +33,8 @@ type BotMessage struct {
} `json:"message"` } `json:"message"`
} }
var userLastCommandType = make(map[string]string)
func main() { func main() {
fmt.Println("Sox started") fmt.Println("Sox started")
http.HandleFunc("/", commandHandler) http.HandleFunc("/", commandHandler)
@@ -63,23 +65,46 @@ func commandHandler(w http.ResponseWriter, r *http.Request) {
return return
} }
fmt.Fprintln(w, executeCommand(msg, "-999nopreviouscommand", ""))
return
}
func executeCommand(msg BotMessage, c string, b string)(string) {
fmt.Println("Last command: " + c)
command, arguments := SplitFirstWord(msg.Message.Body.Plain) command, arguments := SplitFirstWord(msg.Message.Body.Plain)
// value, exists := userLastCommandType[msg.User.Name]
if c != "-999nopreviouscommand" {
command = c
}
switch command { switch command {
case "ping": case "ping":
fmt.Println("ping command received") fmt.Println("ping command received")
fmt.Fprintln(w, "Pong!") userLastCommandType[msg.User.Name] = command;
case "trace": return "Pong!"
fmt.Println("trace command received") // case "trace":
var j = traceHandler(w, r, arguments, msg.User.Name) // fmt.Println("trace command received")
fmt.Fprintln(w, j) // var j = traceHandler(w, r, arguments, msg.User.Name)
// return j
case "math": case "math":
fmt.Fprintln(w, runMath(arguments)) userLastCommandType[msg.User.Name] = command;
return runMath(b+arguments)
case "hi": case "hi":
fmt.Fprintln(w, "Hello " + msg.User.Name + "! How are you doing today?") userLastCommandType[msg.User.Name] = command;
return "Hello " + msg.User.Name + "! How are you doing today?"
default: default:
fmt.Fprintln(w, "Command is: " + command + " arguments are: " + arguments + ". Not sure what to do...") value, exists := userLastCommandType[msg.User.Name]
if exists {
return executeCommand(msg, value, command)
} else {
c = "-999invalidcommand"
return "Command is: " + command + " arguments are: " + arguments + ". Not sure what to do..."
}
} }
return // if c != "-999invalidcommand" {
// userLastCommandType[msg.User.Name] = command;
// }
return "error"
} }
func runMath(s string)(string){ func runMath(s string)(string){