package main import ( "bufio" "fmt" "io" "log" "net" "strings" ) func main() { conn, err := net.Dial("tcp", "pathb.net:6667") if err != nil { log.Print(err) } reader := bufio.NewReader(conn) for { ln, err := reader.ReadString('\n') ln = strings.Trim(ln, "\n") // this switch statement handles cases where the connection is terminated switch { case err == io.EOF: log.Println("Reached EOF - closing this connection.\n") return case err != nil: log.Println("error.") return } log.Println(ln) switch { case strings.Contains(ln, "Looking up your hostname"): fmt.Fprintf(conn, "NICK pathbbot\r\n") fmt.Fprintf(conn, "USER inhabitant 8 * : pathbwalker\r\n") case strings.Contains(ln, "PING"): log.Print("sending PONG") fmt.Fprintf(conn, strings.Replace(ln, "PING", "PONG", 1)) case strings.Contains(ln, "End of /MOTD command."): log.Print("Joining #pathb") fmt.Fprintf(conn, "JOIN #pathb\n") } } }