diff --git a/Makefile b/Makefile index 393ab31..e4909e2 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,8 @@ +<<<<<<< HEAD:Makefile include $(GOROOT)/src/Make.inc +======= +include $(GOROOT)/src/Make.${GOARCH} +>>>>>>> 6f3c572eae2c00aaaf57248b767adf74b571ed01:Makefile TARG=irc GOFILES=irc.go irc_struct.go irc_callback.go diff --git a/README.markdown b/README.markdown index 9ef1bee..5ccd47d 100644 --- a/README.markdown +++ b/README.markdown @@ -50,8 +50,11 @@ AddCallback Example Commands -------- + irc.IRC("", "") //Create new ircobj + ircobj.Password = "[server password]" + ircobj.Connect("irc.someserver.com:6667") //Connect to server ircobj.Sendraw("") //sends string to server. Adds \r\n ircobj.Join("#channel [password]") ircobj.Privmsg("#channel", "msg") ircobj.Privmsg("nickname", "msg") - ircobj.Notice("nickname or #channel", "msg") + ircobj.Notice("", "msg") diff --git a/example/test.go b/example/test.go index 4759dbc..7022235 100644 --- a/example/test.go +++ b/example/test.go @@ -1,7 +1,7 @@ package main import ( - "irc" + irc "github.com/thoj/Go-IRC-Client-Library" "fmt" "os" ) diff --git a/irc.go b/irc.go index 14517db..e11626c 100644 --- a/irc.go +++ b/irc.go @@ -48,7 +48,7 @@ func reader(irc *IRCConnection) { if len(args) > 1 { event.Message = args[1] } - args = strings.Split(args[0], " ", 0) + args = strings.Split(args[0], " ", -1) event.Code = strings.ToUpper(args[0]) if len(args) > 1 { event.Arguments = args[1:len(args)] @@ -61,6 +61,9 @@ func reader(irc *IRCConnection) { func writer(irc *IRCConnection) { for !error { b := []byte(<-irc.pwrite) + if b == nil || irc.socket == nil { + return + } _, err := irc.socket.Write(b) if err != nil { fmt.Printf("%s\n", err) @@ -153,10 +156,13 @@ func (i *IRCConnection) Connect(server string) os.Error { go pinger(i) i.pwrite <- fmt.Sprintf("NICK %s\r\n", i.nick) i.pwrite <- fmt.Sprintf("USER %s 0.0.0.0 0.0.0.0 :%s\r\n", i.user, i.user) + if len(i.Password) > 0 { + i.pwrite <- fmt.Sprintf("PASS %s\r\n", i.Password) + } return nil } -func IRC(nick string, user string) *IRCConnection { +func IRC(nick, user string) *IRCConnection { irc := new(IRCConnection) irc.registered = false irc.pread = make(chan string, 100) diff --git a/irc_callback.go b/irc_callback.go index 83dcbd5..10ff827 100644 --- a/irc_callback.go +++ b/irc_callback.go @@ -91,7 +91,11 @@ func (irc *IRCConnection) setupCallbacks() { }) irc.AddCallback("433", func(e *IRCEvent) { - irc.nick = irc.nick + "_" + if len(irc.nick) > 8 { + irc.nick = "_" + irc.nick; + } else { + irc.nick = irc.nick + "_" + } irc.SendRaw(fmt.Sprintf("NICK %s", irc.nick)) }) diff --git a/irc_struct.go b/irc_struct.go index 4ca8105..8d33ec9 100644 --- a/irc_struct.go +++ b/irc_struct.go @@ -10,15 +10,16 @@ import ( ) type IRCConnection struct { - socket net.Conn - pread, pwrite chan string - Error chan os.Error + socket net.Conn + pread, pwrite chan string + Error chan os.Error syncreader, syncwriter chan bool - nick string - user string - registered bool - server string - + nick string + user string + registered bool + server string + Password string + events map[string][]func(*IRCEvent) lastMessage int64