diff --git a/irc/commands.go b/irc/commands.go index 3b74a7b..51e655b 100644 --- a/irc/commands.go +++ b/irc/commands.go @@ -3,9 +3,6 @@ package irc // this file contains the various commands you can // send to the server using an Conn connection -import ( - "reflect" -) // This could be a lot less ugly with the ability to manipulate // the symbol table and add methods/functions on the fly @@ -30,8 +27,8 @@ func (conn *Conn) User(ident, name string) { func (conn *Conn) Join(channel string) { conn.out <- "JOIN "+channel } // Part() sends a PART command to the server with an optional part message -func (conn *Conn) Part(channel string, message ...) { - msg := getStringMsg(message) +func (conn *Conn) Part(channel string, message string) { + msg := message if msg != "" { msg = " :" + msg } @@ -39,8 +36,8 @@ func (conn *Conn) Part(channel string, message ...) { } // Kick() sends a KICK command to remove a nick from a channel -func (conn *Conn) Kick(channel, nick string, message ...) { - msg := getStringMsg(message) +func (conn *Conn) Kick(channel, nick string, message string) { + msg := message if msg != "" { msg = " :" + msg } @@ -48,8 +45,8 @@ func (conn *Conn) Kick(channel, nick string, message ...) { } // Quit() sends a QUIT command to the server with an optional quit message -func (conn *Conn) Quit(message ...) { - msg := getStringMsg(message) +func (conn *Conn) Quit(message string) { + msg := message if msg == "" { msg = "GoBye!" } @@ -70,8 +67,8 @@ func (conn *Conn) Notice(t, msg string) { conn.out <- "NOTICE "+t+" :"+msg } // Ctcp() sends a (generic) CTCP message to the target t // with an optional argument -func (conn *Conn) Ctcp(t, ctcp string, arg ...) { - msg := getStringMsg(arg) +func (conn *Conn) Ctcp(t, ctcp,arg string) { + msg := arg if msg != "" { msg = " " + msg } @@ -80,8 +77,8 @@ func (conn *Conn) Ctcp(t, ctcp string, arg ...) { // CtcpReply() sends a generic CTCP reply to the target t // with an optional argument -func (conn *Conn) CtcpReply(t, ctcp string, arg ...) { - msg := getStringMsg(arg) +func (conn *Conn) CtcpReply(t, ctcp string, arg string) { + msg := arg if msg != "" { msg = " " + msg } @@ -89,7 +86,7 @@ func (conn *Conn) CtcpReply(t, ctcp string, arg ...) { } // Version() sends a CTCP "VERSION" to the target t -func (conn *Conn) Version(t string) { conn.Ctcp(t, "VERSION") } +func (conn *Conn) Version(t string) { conn.Ctcp(t, "VERSION","") } // Action() sends a CTCP "ACTION" to the target t func (conn *Conn) Action(t, msg string) { conn.Ctcp(t, "ACTION", msg) } @@ -97,8 +94,8 @@ func (conn *Conn) Action(t, msg string) { conn.Ctcp(t, "ACTION", msg) } // Topic() sends a TOPIC command to the channel // Topic(channel) retrieves the current channel topic (see "332" handler) // Topic(channel, topic) sets the topic for the channel -func (conn *Conn) Topic(channel string, topic ...) { - t := getStringMsg(topic) +func (conn *Conn) Topic(channel string, topic string) { + t := topic if t != "" { t = " :" + t } @@ -112,8 +109,8 @@ func (conn *Conn) Topic(channel string, topic ...) { // modestring == e.g. "+o " or "+ntk " or "-is" // This means you'll need to do your own mode work. It may be linked in with // the state tracking and ChanMode/NickMode/ChanPrivs objects later... -func (conn *Conn) Mode(t string, modestring ...) { - mode := getStringMsg(modestring) +func (conn *Conn) Mode(t string, modestring string) { + mode := modestring if mode != "" { mode = " " + mode } @@ -123,8 +120,8 @@ func (conn *Conn) Mode(t string, modestring ...) { // Away() sends an AWAY command to the server // Away() resets away status // Away(message) sets away with the given message -func (conn *Conn) Away(message ...) { - msg := getStringMsg(message) +func (conn *Conn) Away(message string) { + msg := message if msg != "" { msg = " :"+msg } @@ -141,16 +138,3 @@ func (conn *Conn) Oper(user, pass string) { conn.out <- "OPER "+user+" "+pass } -func getStringMsg(a ...) (msg string) { - // dealing with functions with a variable parameter list is nasteeh :-( - // the below stolen and munged from fmt/print.go func getString() - if v := reflect.NewValue(a).(*reflect.StructValue); v.NumField() > 0 { - if s, ok := v.Field(0).(*reflect.StringValue); ok { - return s.Get() - } - if b, ok := v.Interface().([]byte); ok { - return string(b) - } - } - return "" -} diff --git a/irc/connection.go b/irc/connection.go index c3f71dc..d6aaf16 100644 --- a/irc/connection.go +++ b/irc/connection.go @@ -80,7 +80,7 @@ func (conn *Conn) initialise() { // Connect the IRC connection object to "host[:port]" which should be either // a hostname or an IP address, with an optional port defaulting to 6667. // You can also provide an optional connect password. -func (conn *Conn) Connect(host string, pass ...) os.Error { +func (conn *Conn) Connect(host string, pass string) os.Error { if conn.connected { return os.NewError(fmt.Sprintf("irc.Connect(): already connected to %s, cannot connect to %s", conn.Host, host)) } @@ -102,8 +102,8 @@ func (conn *Conn) Connect(host string, pass ...) os.Error { go conn.recv() // see getStringMsg() in commands.go for what this does - if p := getStringMsg(pass); p != "" { - conn.Pass(p) + if pass != "" { + conn.Pass(pass) } conn.Nick(conn.Me.Nick) conn.User(conn.Me.Ident, conn.Me.Name) @@ -113,7 +113,7 @@ func (conn *Conn) Connect(host string, pass ...) os.Error { } // dispatch a nicely formatted os.Error to the error channel -func (conn *Conn) error(s string, a ...) { conn.Err <- os.NewError(fmt.Sprintf(s, a)) } +func (conn *Conn) error(s string, a ...interface{}) { conn.Err <- os.NewError(fmt.Sprintf(s, a)) } // copied from http.client for great justice func hasPort(s string) bool { return strings.LastIndex(s, ":") > strings.LastIndex(s, "]") } @@ -142,7 +142,7 @@ func (conn *Conn) send() { // so sleep for the current line's time value before sending it time.Sleep(linetime) } - if err := conn.io.WriteString(line + "\r\n"); err != nil { + if _,err := conn.io.WriteString(line + "\r\n"); err != nil { conn.error("irc.send(): %s", err.String()) conn.shutdown() break diff --git a/irc/handlers.go b/irc/handlers.go index dec82fd..c04fd6d 100644 --- a/irc/handlers.go +++ b/irc/handlers.go @@ -168,7 +168,7 @@ func (conn *Conn) setupEvents() { // since we don't know much about this channel, ask server for info // we get the channel users automatically in 353 and the channel // topic in 332 on join, so we just need to get the modes - conn.Mode(ch.Name) + conn.Mode(ch.Name,"") // sending a WHO for the channel is MUCH more efficient than // triggering a WHOIS on every nick from the 353 handler conn.Who(ch.Name)