2023-05-20 14:25:21 +02:00
|
|
|
//go:build example
|
2017-03-13 11:01:39 -04:00
|
|
|
// +build example
|
2023-05-20 14:25:21 +02:00
|
|
|
|
2017-03-13 11:01:39 -04:00
|
|
|
//
|
|
|
|
// Do not build by default.
|
|
|
|
|
2013-11-27 20:05:45 -08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2014-07-21 22:19:04 -07:00
|
|
|
"html"
|
|
|
|
"net/http"
|
2014-07-10 17:21:21 -07:00
|
|
|
|
2023-05-20 14:25:21 +02:00
|
|
|
"gobot.io/x/gobot/v2"
|
|
|
|
"gobot.io/x/gobot/v2/api"
|
2013-11-27 20:05:45 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2024-02-13 16:30:25 +01:00
|
|
|
manager := gobot.NewManager()
|
2013-11-27 20:05:45 -08:00
|
|
|
|
2024-02-13 16:30:25 +01:00
|
|
|
a := api.NewAPI(manager)
|
2014-07-21 22:19:04 -07:00
|
|
|
a.AddHandler(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
fmt.Fprintf(w, "Hello, %q \n", html.EscapeString(r.URL.Path))
|
2014-06-12 20:58:54 -07:00
|
|
|
})
|
2014-09-18 20:12:49 -07:00
|
|
|
a.Debug()
|
2014-07-21 22:19:04 -07:00
|
|
|
a.Start()
|
|
|
|
|
2024-02-13 16:30:25 +01:00
|
|
|
manager.AddCommand("custom_gobot_command",
|
2014-07-21 22:19:04 -07:00
|
|
|
func(params map[string]interface{}) interface{} {
|
|
|
|
return "This command is attached to the mcp!"
|
|
|
|
})
|
2014-06-11 16:44:23 -07:00
|
|
|
|
2024-02-13 16:30:25 +01:00
|
|
|
hello := manager.AddRobot(gobot.NewRobot("hello"))
|
2014-07-08 18:36:14 -07:00
|
|
|
|
|
|
|
hello.AddCommand("hi_there", func(params map[string]interface{}) interface{} {
|
2014-07-10 19:28:00 -07:00
|
|
|
return fmt.Sprintf("This command is attached to the robot %v", hello.Name)
|
2014-06-11 16:44:23 -07:00
|
|
|
})
|
2013-11-27 20:05:45 -08:00
|
|
|
|
2024-02-13 16:30:25 +01:00
|
|
|
if err := manager.Start(); err != nil {
|
2024-02-11 15:34:50 +01:00
|
|
|
panic(err)
|
|
|
|
}
|
2013-11-27 20:05:45 -08:00
|
|
|
}
|