From 044aaeef4910adb349d8e7fd8cab9e38cbaaa515 Mon Sep 17 00:00:00 2001 From: notnull Date: Thu, 11 Mar 2021 14:20:26 -0500 Subject: [PATCH] first commit --- .gitignore | 1 + main.go | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 .gitignore create mode 100644 main.go diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3367afd --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +old diff --git a/main.go b/main.go new file mode 100644 index 0000000..4ad68d8 --- /dev/null +++ b/main.go @@ -0,0 +1,46 @@ +package main + +import ( + "bufio" + "io" + "log" + "net" + "strings" +) + +func main() { + conn, err := net.Dial("tcp", "pathb.net:6667") + if err != nil { + log.Print(err) + } + + rw := bufio.NewReadWriter(bufio.NewReader(conn), bufio.NewWriter(conn)) + for { + ln, err := rw.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"): + rw.WriteString("NICK pathbbot\r\n") + rw.WriteString("USER inhabitant 8 * : pathbwalker\r\n") + case strings.Contains(ln, "PING"): + log.Print("sending PONG") + rw.WriteString(strings.Replace(ln, "PING", "PONG", 1)) + case strings.Contains(ln, "End of /MOTD command."): + log.Print("Joining #pathb") + rw.WriteString("JOIN #pathb\n") + rw.Flush() + } + + } +}