Exemplo n.º 1
0
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
}
Exemplo n.º 2
0
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
}
Exemplo n.º 3
0
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
}
Exemplo n.º 4
0
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
}