package main import ( "bufio" "fmt" "io" "log" "net" "strings" ) func sendData(conn net.Conn, message string) { log.Print(message + "\n") fmt.Fprintf(conn, "%s\n", message) } func logon(conn net.Conn) { sendData(conn, "NICK pathbbot") sendData(conn, "User inhabitant 8 * : pathbwalker") } func sendPong(conn net.Conn, ping string) { sendData(conn, strings.Replace(ping, "PING", "PONG", 1)) } func join(conn net.Conn) { sendData(conn, "JOIN #pathb") } 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") log.Println(ln) switch { case err == io.EOF: log.Println("Reached EOF - closing this connection.\n") return case err != nil: log.Println("error.\n") return case strings.Contains(ln, "Looking up your hostname"): logon(conn) case strings.Contains(ln, "PING"): sendPong(conn, ln) case strings.Contains(ln, "End of /MOTD command."): join(conn) } } }