This commit is contained in:
tj 2010-09-29 10:07:33 +02:00
commit e9248114a7
6 changed files with 31 additions and 13 deletions

View File

@ -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

View File

@ -50,8 +50,11 @@ AddCallback Example
Commands
--------
irc.IRC("<nick>", "<user>") //Create new ircobj
ircobj.Password = "[server password]"
ircobj.Connect("irc.someserver.com:6667") //Connect to server
ircobj.Sendraw("<string>") //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("<nickname | #channel>", "msg")

View File

@ -1,7 +1,7 @@
package main
import (
"irc"
irc "github.com/thoj/Go-IRC-Client-Library"
"fmt"
"os"
)

10
irc.go
View File

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

View File

@ -91,7 +91,11 @@ func (irc *IRCConnection) setupCallbacks() {
})
irc.AddCallback("433", func(e *IRCEvent) {
if len(irc.nick) > 8 {
irc.nick = "_" + irc.nick;
} else {
irc.nick = irc.nick + "_"
}
irc.SendRaw(fmt.Sprintf("NICK %s", irc.nick))
})

View File

@ -18,6 +18,7 @@ type IRCConnection struct {
user string
registered bool
server string
Password string
events map[string][]func(*IRCEvent)