Skip to content

Instantly share code, notes, and snippets.

@deadprogram
Created September 7, 2018 08:39
Show Gist options
  • Save deadprogram/7c36454ffe188ab3d9803233ee046fe7 to your computer and use it in GitHub Desktop.
Save deadprogram/7c36454ffe188ab3d9803233ee046fe7 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"time"
"gobot.io/x/gobot"
"gobot.io/x/gobot/api"
)
func NewEventBot() *gobot.Robot {
var robot *gobot.Robot
work := func() {
gobot.After(1*time.Second, func() {
fmt.Println("hi")
gobot.Every(1*time.Second, func() {
robot.Publish("hello", "hi there")
fmt.Println("yo")
})
})
}
robot = gobot.NewRobot("testBot",
work,
)
robot.AddEvent("hello")
return robot
}
func main() {
master := gobot.NewMaster()
api.NewAPI(master).Start()
testBot := NewEventBot()
testBot.On("hello", func(data interface{}) {
fmt.Println("Hello detected")
})
master.AddRobot(testBot)
master.Start()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment