mirror of https://github.com/fluffle/goirc
Removed varadics in functions and updated for changes to Go standard library
This commit is contained in:
parent
cc35817517
commit
06f7cdd19b
|
@ -3,9 +3,6 @@ package irc
|
||||||
// this file contains the various commands you can
|
// this file contains the various commands you can
|
||||||
// send to the server using an Conn connection
|
// send to the server using an Conn connection
|
||||||
|
|
||||||
import (
|
|
||||||
"reflect"
|
|
||||||
)
|
|
||||||
|
|
||||||
// This could be a lot less ugly with the ability to manipulate
|
// This could be a lot less ugly with the ability to manipulate
|
||||||
// the symbol table and add methods/functions on the fly
|
// 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 }
|
func (conn *Conn) Join(channel string) { conn.out <- "JOIN "+channel }
|
||||||
|
|
||||||
// Part() sends a PART command to the server with an optional part message
|
// Part() sends a PART command to the server with an optional part message
|
||||||
func (conn *Conn) Part(channel string, message ...) {
|
func (conn *Conn) Part(channel string, message string) {
|
||||||
msg := getStringMsg(message)
|
msg := message
|
||||||
if msg != "" {
|
if msg != "" {
|
||||||
msg = " :" + 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
|
// Kick() sends a KICK command to remove a nick from a channel
|
||||||
func (conn *Conn) Kick(channel, nick string, message ...) {
|
func (conn *Conn) Kick(channel, nick string, message string) {
|
||||||
msg := getStringMsg(message)
|
msg := message
|
||||||
if msg != "" {
|
if msg != "" {
|
||||||
msg = " :" + 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
|
// Quit() sends a QUIT command to the server with an optional quit message
|
||||||
func (conn *Conn) Quit(message ...) {
|
func (conn *Conn) Quit(message string) {
|
||||||
msg := getStringMsg(message)
|
msg := message
|
||||||
if msg == "" {
|
if msg == "" {
|
||||||
msg = "GoBye!"
|
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
|
// Ctcp() sends a (generic) CTCP message to the target t
|
||||||
// with an optional argument
|
// with an optional argument
|
||||||
func (conn *Conn) Ctcp(t, ctcp string, arg ...) {
|
func (conn *Conn) Ctcp(t, ctcp,arg string) {
|
||||||
msg := getStringMsg(arg)
|
msg := arg
|
||||||
if msg != "" {
|
if msg != "" {
|
||||||
msg = " " + 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
|
// CtcpReply() sends a generic CTCP reply to the target t
|
||||||
// with an optional argument
|
// with an optional argument
|
||||||
func (conn *Conn) CtcpReply(t, ctcp string, arg ...) {
|
func (conn *Conn) CtcpReply(t, ctcp string, arg string) {
|
||||||
msg := getStringMsg(arg)
|
msg := arg
|
||||||
if msg != "" {
|
if msg != "" {
|
||||||
msg = " " + msg
|
msg = " " + msg
|
||||||
}
|
}
|
||||||
|
@ -89,7 +86,7 @@ func (conn *Conn) CtcpReply(t, ctcp string, arg ...) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Version() sends a CTCP "VERSION" to the target t
|
// 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
|
// Action() sends a CTCP "ACTION" to the target t
|
||||||
func (conn *Conn) Action(t, msg string) { conn.Ctcp(t, "ACTION", msg) }
|
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() sends a TOPIC command to the channel
|
||||||
// Topic(channel) retrieves the current channel topic (see "332" handler)
|
// Topic(channel) retrieves the current channel topic (see "332" handler)
|
||||||
// Topic(channel, topic) sets the topic for the channel
|
// Topic(channel, topic) sets the topic for the channel
|
||||||
func (conn *Conn) Topic(channel string, topic ...) {
|
func (conn *Conn) Topic(channel string, topic string) {
|
||||||
t := getStringMsg(topic)
|
t := topic
|
||||||
if t != "" {
|
if t != "" {
|
||||||
t = " :" + t
|
t = " :" + t
|
||||||
}
|
}
|
||||||
|
@ -112,8 +109,8 @@ func (conn *Conn) Topic(channel string, topic ...) {
|
||||||
// modestring == e.g. "+o <nick>" or "+ntk <key>" or "-is"
|
// modestring == e.g. "+o <nick>" or "+ntk <key>" or "-is"
|
||||||
// This means you'll need to do your own mode work. It may be linked in with
|
// 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...
|
// the state tracking and ChanMode/NickMode/ChanPrivs objects later...
|
||||||
func (conn *Conn) Mode(t string, modestring ...) {
|
func (conn *Conn) Mode(t string, modestring string) {
|
||||||
mode := getStringMsg(modestring)
|
mode := modestring
|
||||||
if mode != "" {
|
if mode != "" {
|
||||||
mode = " " + mode
|
mode = " " + mode
|
||||||
}
|
}
|
||||||
|
@ -123,8 +120,8 @@ func (conn *Conn) Mode(t string, modestring ...) {
|
||||||
// Away() sends an AWAY command to the server
|
// Away() sends an AWAY command to the server
|
||||||
// Away() resets away status
|
// Away() resets away status
|
||||||
// Away(message) sets away with the given message
|
// Away(message) sets away with the given message
|
||||||
func (conn *Conn) Away(message ...) {
|
func (conn *Conn) Away(message string) {
|
||||||
msg := getStringMsg(message)
|
msg := message
|
||||||
if msg != "" {
|
if msg != "" {
|
||||||
msg = " :"+msg
|
msg = " :"+msg
|
||||||
}
|
}
|
||||||
|
@ -141,16 +138,3 @@ func (conn *Conn) Oper(user, pass string) {
|
||||||
conn.out <- "OPER "+user+" "+pass
|
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 ""
|
|
||||||
}
|
|
||||||
|
|
|
@ -80,7 +80,7 @@ func (conn *Conn) initialise() {
|
||||||
// Connect the IRC connection object to "host[:port]" which should be either
|
// 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.
|
// a hostname or an IP address, with an optional port defaulting to 6667.
|
||||||
// You can also provide an optional connect password.
|
// 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 {
|
if conn.connected {
|
||||||
return os.NewError(fmt.Sprintf("irc.Connect(): already connected to %s, cannot connect to %s", conn.Host, host))
|
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()
|
go conn.recv()
|
||||||
|
|
||||||
// see getStringMsg() in commands.go for what this does
|
// see getStringMsg() in commands.go for what this does
|
||||||
if p := getStringMsg(pass); p != "" {
|
if pass != "" {
|
||||||
conn.Pass(p)
|
conn.Pass(pass)
|
||||||
}
|
}
|
||||||
conn.Nick(conn.Me.Nick)
|
conn.Nick(conn.Me.Nick)
|
||||||
conn.User(conn.Me.Ident, conn.Me.Name)
|
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
|
// 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
|
// copied from http.client for great justice
|
||||||
func hasPort(s string) bool { return strings.LastIndex(s, ":") > strings.LastIndex(s, "]") }
|
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
|
// so sleep for the current line's time value before sending it
|
||||||
time.Sleep(linetime)
|
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.error("irc.send(): %s", err.String())
|
||||||
conn.shutdown()
|
conn.shutdown()
|
||||||
break
|
break
|
||||||
|
|
|
@ -168,7 +168,7 @@ func (conn *Conn) setupEvents() {
|
||||||
// since we don't know much about this channel, ask server for info
|
// since we don't know much about this channel, ask server for info
|
||||||
// we get the channel users automatically in 353 and the channel
|
// we get the channel users automatically in 353 and the channel
|
||||||
// topic in 332 on join, so we just need to get the modes
|
// 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
|
// sending a WHO for the channel is MUCH more efficient than
|
||||||
// triggering a WHOIS on every nick from the 353 handler
|
// triggering a WHOIS on every nick from the 353 handler
|
||||||
conn.Who(ch.Name)
|
conn.Who(ch.Name)
|
||||||
|
|
Loading…
Reference in New Issue