first commit
This commit is contained in:
commit
044aaeef49
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
old
|
46
main.go
Normal file
46
main.go
Normal 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()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user