From f3dd8e174ed545ddcb9b9a73d6ffccad44a80bca Mon Sep 17 00:00:00 2001 From: raylu Date: Wed, 13 Oct 2010 15:10:24 -0400 Subject: [PATCH] Strip down the client, rename to rbot --- .gitignore | 2 +- Makefile | 4 +-- client.go | 90 ------------------------------------------------------ rbot.go | 30 ++++++++++++++++++ 4 files changed, 33 insertions(+), 93 deletions(-) delete mode 100644 client.go create mode 100644 rbot.go diff --git a/.gitignore b/.gitignore index 93233d9..b3472a3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -/gobot +/rbot *.[568] _obj/ _test/ diff --git a/Makefile b/Makefile index b46474f..e34f6e3 100644 --- a/Makefile +++ b/Makefile @@ -4,9 +4,9 @@ include $(GOROOT)/src/Make.inc -TARG=gobot +TARG=rbot GOFILES=\ - client.go\ + rbot.go\ include $(GOROOT)/src/Make.cmd diff --git a/client.go b/client.go deleted file mode 100644 index c2dc7e3..0000000 --- a/client.go +++ /dev/null @@ -1,90 +0,0 @@ -package main - -import ( - "irc" - "fmt" - "os" - "bufio" - "strings" -) - -func main() { - // create new IRC connection - c := irc.New("GoTest", "gotest", "GoBot") - c.AddHandler("connected", - func(conn *irc.Conn, line *irc.Line) { conn.Join("#go-nuts") }) - - // connect to server - if err := c.Connect("irc.freenode.net", ""); err != nil { - fmt.Printf("Connection error: %s\n", err) - return - } - - // set up a goroutine to read commands from stdin - in := make(chan string, 4) - reallyquit := false - go func() { - con := bufio.NewReader(os.Stdin) - for { - s, err := con.ReadString('\n') - if err != nil { - // wha?, maybe ctrl-D... - close(in) - break - } - // no point in sending empty lines down the channel - if len(s) > 2 { - in <- s[0:len(s)-1] - } - } - }() - - // set up a goroutine to do parsey things with the stuff from stdin - go func() { - for cmd := range in { - if cmd[0] == ':' { - switch idx := strings.Index(cmd, " "); { - case cmd[1] == 'd': - fmt.Printf(c.String()) - case cmd[1] == 'f': - if len(cmd) > 2 && cmd[2] == 'e' { - // enable flooding - c.Flood = true - } else if len(cmd) > 2 && cmd[2] == 'd' { - // disable flooding - c.Flood = false - } - for i := 0; i < 20; i++ { - c.Privmsg("#", "flood test!") - } - case idx == -1: - continue - case cmd[1] == 'q': - reallyquit = true - c.Quit(cmd[idx+1 : len(cmd)]) - case cmd[1] == 'j': - c.Join(cmd[idx+1 : len(cmd)]) - case cmd[1] == 'p': - c.Part(cmd[idx+1 : len(cmd)]) - } - } else { - c.Raw(cmd) - } - } - }() - - // stall here waiting for asplode on error channel - for { - for err := range c.Err { - fmt.Printf("goirc error: %s\n", err) - } - if reallyquit { - break - } - fmt.Println("Reconnecting...") - if err := c.Connect("irc.freenode.net", ""); err != nil { - fmt.Printf("Connection error: %s\n", err) - break - } - } -} diff --git a/rbot.go b/rbot.go new file mode 100644 index 0000000..d80cece --- /dev/null +++ b/rbot.go @@ -0,0 +1,30 @@ +package main + +import ( + "irc" + "fmt" +) + +func main() { + server := "irc.rizon.net" + channel := "#vn-meta" + ssl := false + + c := irc.New("raylu[BOT]", "rayluBOT", "rayluBOT") + c.AddHandler("connected", + func(conn *irc.Conn, line *irc.Line) { + conn.Join(channel) + }) + + for { + fmt.Printf("Connecting to %s...\n", server) + if err := c.Connect(server, ssl, ""); err != nil { + fmt.Printf("Connection error: %s\n", err) + break + } + fmt.Println("Connected!") + for err := range c.Err { + fmt.Printf("goirc error: %s\n", err) + } + } +}