func main() { //Create a chatbot session. chatbot := beam.Session{ UseCookies: true, Debug: true, } //subscribe to events chatbot.AddHandler(userJoin) chatbot.AddHandler(userLeave) chatbot.AddHandler(userChat) //Log in log.Println("[Chatbot] Logging in") err := chatbot.Login() if err != nil { log.Println("[Chatbot] Error logging in:", err.Error()) return } //Create a robot session, copy auth data from chatbot robot := beam.Session{ Debug: true, UseCookies: true, CsrfToken: chatbot.CsrfToken, Cookies: chatbot.Cookies, LoginPayload: chatbot.LoginPayload, } //subscribe to robot events robot.AddHandler(reportRobot) robot.AddHandler(errorRobot) // Open chatbot websocket log.Println("[Chatbot] Connecting") err = chatbot.Open() if err != nil { log.Println("[Chatbot] Error opening winsock:", err.Error()) return } log.Println("[Chatbot] Success!") //Open robot websocket log.Println("[Robot] Connecting") err = robot.OpenRobot() if err != nil { log.Println("[Robot] Error opening winsock:", err) return } log.Println("[Robot] Success!") // Simple way to keep program running until any key press. var input string fmt.Scanln(&input) return }
func main() { //Create a chatbot session. chatbot := beam.Session{ Debug: false, } //subscribe to events chatbot.AddHandler(userJoin) chatbot.AddHandler(userLeave) chatbot.AddHandler(userChat) chatbot.AddHandler(pollStart) chatbot.AddHandler(pollEnd) //Log in log.Println("[Chatbot] Logging in") err := chatbot.Login() if err != nil { log.Println("[Chatbot] Error logging in:", err.Error()) return } // Open chatbot websocket log.Println("[Chatbot] Connecting") err = chatbot.Open() if err != nil { log.Println("[Chatbot] Error opening winsock:", err.Error()) return } log.Println("[Chatbot] Success!") time.Sleep(1 * time.Second) //Send a message /* err = chatbot.Whisper("xackery", "Test!") if err != nil { log.Println("[Chatbot] Error sending message:", err.Error()) return } */ // Simple way to keep program running until any key press. var input string fmt.Scanln(&input) return }
func main() { //Create a robot session robot := beam.Session{ UseCookies: true, Debug: true, } //subscribe to robot events //robot.AddHandler(reportRobot) robot.AddHandler(errorRobot) //Log in log.Println("[Robot] Logging in") err := robot.Login() if err != nil { log.Println("[Chatbot] Error logging in:", err.Error()) return } //Open robot websocket log.Println("[Robot] Connecting") err = robot.OpenRobot() if err != nil { log.Println("[Robot] Error opening winsock:", err) return } log.Println("[Robot] Success!") id := uint32(0) isFired := true //cooldown := uint32(1000) progress := float64(0.1) jid := uint32(9) jangle := float64(0.1) intensity := float64(0.1) for { time.Sleep(1500 * time.Millisecond) progress += 0.1 if progress > 1 { progress = 0 } jangle += 0.1 if jangle > 1 { jangle = 0 } intensity += 0.1 if intensity > 1 { intensity = 1 } err = robot.ProgressUpdate(&beam.ProgressUpdate{ Tactile: []*beam.ProgressUpdate_TactileUpdate{ &beam.ProgressUpdate_TactileUpdate{ Id: &id, Fired: &isFired, // Cooldown: &cooldown, Progress: &progress, }, }, Joystick: []*beam.ProgressUpdate_JoystickUpdate{ &beam.ProgressUpdate_JoystickUpdate{ Id: &jid, Angle: &jangle, Intensity: &intensity, }, }, }) if err != nil { fmt.Println("error sending progress update:", err.Error()) } } // Simple way to keep program running until any key press. var input string fmt.Scanln(&input) return }
func main() { var err error //Create a chatbot session. chatbot := beam.Session{ Debug: false, UseCookies: true, TimeoutDuration: 2 * time.Second, } //subscribe to events chatbot.AddHandler(userJoin) chatbot.AddHandler(userLeave) chatbot.AddHandler(userChat) //Log in log.Println("[Chatbot] Logging in") err = chatbot.Login() if err != nil { log.Println("[Chatbot] Error logging in:", err.Error()) return } //Create a robot session, copy auth data from chatbot robot := beam.Session{ Debug: false, UseCookies: true, Cookies: chatbot.Cookies, LoginPayload: chatbot.LoginPayload, CsrfToken: chatbot.CsrfToken, } //Make a robot service provider, and a channel rs := &robotService{ session: &robot, } //subscribe to robot events robot.AddHandler(errorRobot) // Open chatbot websocket log.Println("[Chatbot] Connecting") err = chatbot.Open() if err != nil { log.Println("[Chatbot] Error opening winsock:", err.Error()) return } log.Println("[Chatbot] Success!") //Open robot websocket log.Println("[Robot] Connecting") err = robot.OpenRobot() if err != nil { log.Println("[Robot] Error opening winsock:", err) return } log.Println("[Robot] Success!") //Start grpc listener addr := "127.0.0.1:50051" log.Println("[gRPC] Listening on", addr) lis, err := net.Listen("tcp", addr) if err != nil { log.Println("[gRPC] Failed to listen:", err.Error()) return } s := grpc.NewServer() beam.RegisterRobotServiceServer(s, rs) go s.Serve(lis) webbot := &WebServer{ Robot: &robot, Chatbot: &chatbot, } go webbot.ListenAndServe("127.0.0.1:1234") /*chanResp, err := chatbot.Channels(0) if err != nil { fmt.Println("Error getting channel repsonse", err.Error()) } fmt.Println(chanResp) */ // Simple way to keep program running until any key press. var input string fmt.Scanln(&input) return }
func main() { //Create a chatbot session. chatbot := beam.Session{ Debug: false, UseCookies: true, } //subscribe to events chatbot.AddHandler(userJoin) chatbot.AddHandler(userLeave) chatbot.AddHandler(userChat) //Log in log.Println("[Chatbot] Logging in") err := chatbot.Login() if err != nil { log.Println("[Chatbot] Error logging in:", err.Error()) return } //Create a robot session, copy auth data from chatbot robot := beam.Session{ Debug: false, UseCookies: true, Cookies: chatbot.Cookies, LoginPayload: chatbot.LoginPayload, CsrfToken: chatbot.CsrfToken, } //Make a robot service provider, and a channel rs := &robotService{ session: &robot, } //subscribe to robot events robot.AddHandler(errorRobot) // Open chatbot websocket log.Println("[Chatbot] Connecting") err = chatbot.Open() if err != nil { log.Println("[Chatbot] Error opening winsock:", err.Error()) return } log.Println("[Chatbot] Success!") //Open robot websocket log.Println("[Robot] Connecting") err = robot.OpenRobot() if err != nil { log.Println("[Robot] Error opening winsock:", err) return } log.Println("[Robot] Success!") //Start grpc listener addr := "127.0.0.1:50051" log.Println("[gRPC] Listening on", addr) lis, err := net.Listen("tcp", addr) if err != nil { log.Println("[gRPC] Failed to listen:", err.Error()) return } s := grpc.NewServer() beam.RegisterRobotServiceServer(s, rs) err = s.Serve(lis) if err != nil { log.Println("[gRPC] Error on serve: ", err.Error()) return } return }