Example #1
0
func main() {
	// command line flags
	publicId := flag.String("publicId", "", "room you want to join to")
	key := flag.String("key", "", "key")
	secret := flag.String("secret", "", "secret")
	host := flag.String("host", "pds.dev.ifi.tv:2020", "bot chat host")

	flag.Parse()

	// Create a bot
	b, err := bot.New(*host, *key, *secret, *publicId)
	if err != nil {
		log.Fatal(err)
	}
	if err := b.JoinRoom(); err != nil {
		log.Fatal(err)
	}

	// handle LEAVE on server shutdown
	done := make(chan os.Signal)
	signal.Notify(done, syscall.SIGINT, syscall.SIGTERM)

	go func() {
		for {
			// Wait for a command to come from the chat server
			cmd, err := b.Read()
			if err != nil {
				log.Println("read error:", err)
				continue
			}

			// handle say commands that are not from bots
			switch cmd.Name {
			case commands.LSay:
				if cmd.Get("bot") == "false" {
					if err := b.Say(cmd.Get("message")); err != nil {
						log.Println("write error:", err)
					}
				}
			}
		}
	}()

	<-done
	fmt.Println("Leaving chat room")
	b.Leave()
}
Example #2
0
func main() {
	// command line flags
	publicId := flag.String("userPublicId", "", "User's public ID of the room you want to join")
	key := flag.String("bot-key", "", "bot key")
	secret := flag.String("bot-secret", "", "bot secret")
	host := flag.String("host", "www.stream.me:2020", "bot chat host")

	flag.Parse()

	// Create a bot
	b, err := bot.New(*host, *key, *secret, *publicId)
	if err != nil {
		log.Fatal(err)
	}
	if err := b.JoinRoom(); err != nil {
		log.Fatal(err)
	}

	if err := b.Say("Hello, World!"); err != nil {
		log.Println("Say error:", err)
	}

	b.Leave()
}