alt version

This commit is contained in:
notnull 2021-03-11 15:08:27 -05:00
parent 044aaeef49
commit 8626850020

14
main.go
View File

@ -2,6 +2,7 @@ package main
import ( import (
"bufio" "bufio"
"fmt"
"io" "io"
"log" "log"
"net" "net"
@ -14,9 +15,9 @@ func main() {
log.Print(err) log.Print(err)
} }
rw := bufio.NewReadWriter(bufio.NewReader(conn), bufio.NewWriter(conn)) reader := bufio.NewReader(conn)
for { for {
ln, err := rw.ReadString('\n') ln, err := reader.ReadString('\n')
ln = strings.Trim(ln, "\n") ln = strings.Trim(ln, "\n")
// this switch statement handles cases where the connection is terminated // this switch statement handles cases where the connection is terminated
switch { switch {
@ -31,15 +32,14 @@ func main() {
switch { switch {
case strings.Contains(ln, "Looking up your hostname"): case strings.Contains(ln, "Looking up your hostname"):
rw.WriteString("NICK pathbbot\r\n") fmt.Fprintf(conn, "NICK pathbbot\r\n")
rw.WriteString("USER inhabitant 8 * : pathbwalker\r\n") fmt.Fprintf(conn, "USER inhabitant 8 * : pathbwalker\r\n")
case strings.Contains(ln, "PING"): case strings.Contains(ln, "PING"):
log.Print("sending PONG") log.Print("sending PONG")
rw.WriteString(strings.Replace(ln, "PING", "PONG", 1)) fmt.Fprintf(conn, strings.Replace(ln, "PING", "PONG", 1))
case strings.Contains(ln, "End of /MOTD command."): case strings.Contains(ln, "End of /MOTD command."):
log.Print("Joining #pathb") log.Print("Joining #pathb")
rw.WriteString("JOIN #pathb\n") fmt.Fprintf(conn, "JOIN #pathb\n")
rw.Flush()
} }
} }