Got basic last command memory working
This commit is contained in:
parent
b2f088d4e1
commit
1758961a66
2
.gitignore
vendored
2
.gitignore
vendored
@ -1 +1,3 @@
|
||||
/bin
|
||||
/result
|
||||
sox
|
||||
|
||||
43
main.go
43
main.go
@ -33,6 +33,8 @@ type BotMessage struct {
|
||||
} `json:"message"`
|
||||
}
|
||||
|
||||
var userLastCommandType = make(map[string]string)
|
||||
|
||||
func main() {
|
||||
fmt.Println("Sox started")
|
||||
http.HandleFunc("/", commandHandler)
|
||||
@ -63,23 +65,46 @@ func commandHandler(w http.ResponseWriter, r *http.Request) {
|
||||
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)
|
||||
// value, exists := userLastCommandType[msg.User.Name]
|
||||
if c != "-999nopreviouscommand" {
|
||||
command = c
|
||||
}
|
||||
switch command {
|
||||
case "ping":
|
||||
fmt.Println("ping command received")
|
||||
fmt.Fprintln(w, "Pong!")
|
||||
case "trace":
|
||||
fmt.Println("trace command received")
|
||||
var j = traceHandler(w, r, arguments, msg.User.Name)
|
||||
fmt.Fprintln(w, j)
|
||||
userLastCommandType[msg.User.Name] = command;
|
||||
return "Pong!"
|
||||
// case "trace":
|
||||
// fmt.Println("trace command received")
|
||||
// var j = traceHandler(w, r, arguments, msg.User.Name)
|
||||
// return j
|
||||
case "math":
|
||||
fmt.Fprintln(w, runMath(arguments))
|
||||
userLastCommandType[msg.User.Name] = command;
|
||||
return runMath(b+arguments)
|
||||
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:
|
||||
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){
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user