Beispiel #1
0
// Connect() takes a string with url:port of the irc server, and a channel
// that accepts strings.  It connects to the irc server specified and
// identifies with the nick "spectator."  It connects to every room specified
// in the rooms variable.
func Connect(hostname string, c chan string) {
	rooms := []string{
		"#Node.js", "##javascript",
		"#python", "#haskell", "#vim", "#go-nuts", "#ruby",
		"#clojure", "#perl", "##php",
		"#erlang", "#scheme", "#lisp", "#R", "#swift-lang",
	}

	fmt.Printf("connecting to %s\n", hostname)
	conn, err := irc.Dial(hostname)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println("Connected!")

	go func() {
		for {
			msg, _ := conn.Decode()
			if msg.Command == "PING" {
				conn.Encode(&irc.Message{
					Command:  "PONG",
					Params:   msg.Params,
					Trailing: msg.Trailing,
				})
			}
			c <- msg.String()
		}
	}()

	identify(conn)
	fmt.Println("Identified")

	joinRooms(conn, rooms)
	fmt.Printf("Join: %s\n", rooms)
}
Beispiel #2
0
// connect starts the IRC connection and stores the handler in conn.
func (a *Amigo) connect() error {
	log.Println("Connecting to " + a.Host)

	c, err := irc.Dial(a.Host)

	if err != nil {
		errMsg := "AMIGO ERROR: " + err.Error()
		return errors.New(errMsg)
	}

	a.conn = c

	return nil
}