goircbot/main.go
2021-03-11 15:08:27 -05:00

47 lines
969 B
Go

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")
}
}
}