first commit

This commit is contained in:
notnull 2021-03-11 14:20:26 -05:00
commit 044aaeef49
2 changed files with 47 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
old

46
main.go Normal file
View File

@ -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()
}
}
}