diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..0b5d58e --- /dev/null +++ b/.travis.yml @@ -0,0 +1,20 @@ +--- +language: go + +go: + - 1.18 + - 1.17.8 + - 1.16.15 + - 1.15.15 + +sudo : false + +notifications: + irc: + channels: + - "irc.pl0rt.org#sp0rklf" + skip_join: true + +script: + - if [ "$TRAVIS_REPO_SLUG" != "fluffle/goirc" ] ; then ln -s "$HOME/gopath/src/github.com/$TRAVIS_REPO_SLUG" /home/travis/gopath/src/github.com/fluffle/goirc ; fi + - go test -v ./... diff --git a/README.md b/README.md index 765707e..5c1108c 100644 --- a/README.md +++ b/README.md @@ -97,7 +97,7 @@ indebted to Matt Gruen for his work on the re-organisation and channel-based communication structure of `*Conn.send()` and `*Conn.recv()`. I'm sure things could be more asynchronous, still. -This code is (c) 2009-26 Alex Bramley, and released under the same licence terms +This code is (c) 2009-23 Alex Bramley, and released under the same licence terms as Go itself. Contributions gratefully received from: @@ -117,7 +117,6 @@ Contributions gratefully received from: - [shammash](https://github.com/shammash) - [ostafen](https://github.com/ostafen) - [supertassu](https://github.com/supertassu) - - [slymas](https://github.com/slymas) And thanks to the following for minor doc/fix PRs: diff --git a/client/commands.go b/client/commands.go index 93b462c..f5d4c58 100644 --- a/client/commands.go +++ b/client/commands.go @@ -6,37 +6,36 @@ import ( ) const ( - REGISTER = "REGISTER" - CONNECTED = "CONNECTED" - DISCONNECTED = "DISCONNECTED" - ACTION = "ACTION" - AUTHENTICATE = "AUTHENTICATE" - AWAY = "AWAY" - CAP = "CAP" - CTCP = "CTCP" - CTCPREPLY = "CTCPREPLY" - ERROR = "ERROR" - INVITE = "INVITE" - JOIN = "JOIN" - KICK = "KICK" - MODE = "MODE" - NICK = "NICK" - NOTICE = "NOTICE" - OPER = "OPER" - PART = "PART" - PASS = "PASS" - PING = "PING" - PONG = "PONG" - PRIVMSG = "PRIVMSG" - QUIT = "QUIT" - TOPIC = "TOPIC" - USER = "USER" - VERSION = "VERSION" - VHOST = "VHOST" - WHO = "WHO" - WHOIS = "WHOIS" - defaultSplit = 450 - defaultMarker = "..." + REGISTER = "REGISTER" + CONNECTED = "CONNECTED" + DISCONNECTED = "DISCONNECTED" + ACTION = "ACTION" + AUTHENTICATE = "AUTHENTICATE" + AWAY = "AWAY" + CAP = "CAP" + CTCP = "CTCP" + CTCPREPLY = "CTCPREPLY" + ERROR = "ERROR" + INVITE = "INVITE" + JOIN = "JOIN" + KICK = "KICK" + MODE = "MODE" + NICK = "NICK" + NOTICE = "NOTICE" + OPER = "OPER" + PART = "PART" + PASS = "PASS" + PING = "PING" + PONG = "PONG" + PRIVMSG = "PRIVMSG" + QUIT = "QUIT" + TOPIC = "TOPIC" + USER = "USER" + VERSION = "VERSION" + VHOST = "VHOST" + WHO = "WHO" + WHOIS = "WHOIS" + defaultSplit = 450 ) // cutNewLines() pares down a string to the part before the first "\r" or "\n". @@ -66,34 +65,21 @@ func indexFragment(s string) int { return -1 } -// SplitDefaults permits read-only access to goirc's default split params. -func SplitDefaults() (int, string) { - return defaultSplit, defaultMarker -} - // splitMessage splits a message > splitLen chars at: // 1. the end of the last sentence fragment before splitLen // 2. the end of the last word before splitLen // 3. splitLen itself -func splitMessage(msg string, splitLen int, marker string) (msgs []string) { +func splitMessage(msg string, splitLen int) (msgs []string) { // This is quite short ;-) if splitLen < 13 { splitLen = defaultSplit } - - markerLen := len(marker) - if markerLen >= splitLen { - // This will end badly otherwise :-) - markerLen = len(defaultMarker) - marker = defaultMarker - } - for len(msg) > splitLen { - idx := indexFragment(msg[:splitLen-markerLen]) + idx := indexFragment(msg[:splitLen-3]) if idx < 0 { - idx = splitLen - markerLen + idx = splitLen - 3 } - msgs = append(msgs, msg[:idx]+marker) + msgs = append(msgs, msg[:idx]+"...") msg = msg[idx:] } return append(msgs, msg) @@ -191,7 +177,7 @@ func (conn *Conn) Who(nick string) { conn.Raw(WHO + " " + nick) } // PRIVMSG t :msg func (conn *Conn) Privmsg(t, msg string) { prefix := PRIVMSG + " " + t + " :" - for _, s := range splitMessage(msg, conn.cfg.SplitLen, conn.cfg.SplitMarker) { + for _, s := range splitMessage(msg, conn.cfg.SplitLen) { conn.Raw(prefix + s) } } @@ -221,7 +207,7 @@ func (conn *Conn) Privmsgf(t, format string, a ...interface{}) { // will be sent to the target containing sequential parts of msg. // NOTICE t :msg func (conn *Conn) Notice(t, msg string) { - for _, s := range splitMessage(msg, conn.cfg.SplitLen, conn.cfg.SplitMarker) { + for _, s := range splitMessage(msg, conn.cfg.SplitLen) { conn.Raw(NOTICE + " " + t + " :" + s) } } @@ -231,7 +217,7 @@ func (conn *Conn) Notice(t, msg string) { // PRIVMSG t :\001CTCP arg\001 func (conn *Conn) Ctcp(t, ctcp string, arg ...string) { // We need to split again here to ensure - for _, s := range splitMessage(strings.Join(arg, " "), conn.cfg.SplitLen, conn.cfg.SplitMarker) { + for _, s := range splitMessage(strings.Join(arg, " "), conn.cfg.SplitLen) { if s != "" { s = " " + s } @@ -244,7 +230,7 @@ func (conn *Conn) Ctcp(t, ctcp string, arg ...string) { // or channel t, with an optional argument. // NOTICE t :\001CTCP arg\001 func (conn *Conn) CtcpReply(t, ctcp string, arg ...string) { - for _, s := range splitMessage(strings.Join(arg, " "), conn.cfg.SplitLen, conn.cfg.SplitMarker) { + for _, s := range splitMessage(strings.Join(arg, " "), conn.cfg.SplitLen) { if s != "" { s = " " + s } diff --git a/client/commands_test.go b/client/commands_test.go index 0e39c43..25af371 100644 --- a/client/commands_test.go +++ b/client/commands_test.go @@ -53,44 +53,23 @@ func TestIndexFragment(t *testing.T) { } } -var ( - longString = strings.Repeat("long ", 100) - longIdx = indexFragment(longString[:defaultSplit-3]) -) - func TestSplitMessage(t *testing.T) { tests := []struct { in string sp int - mk string out []string }{ - {"", 0, "...", []string{""}}, - {"foo", 0, "...", []string{"foo"}}, - {"foo bar baz beep", 0, "...", []string{"foo bar baz beep"}}, - {"foo bar baz beep", 15, "...", []string{"foo bar baz ...", "beep"}}, - {"foo bar, baz beep", 15, "...", []string{"foo bar, ...", "baz beep"}}, - {"01234567890123456", 0, "...", []string{"01234567890123456"}}, - {"01234567890123456", 13, "", []string{"0123456789012", "3456"}}, - {"01234567890123456", 14, ".", []string{"0123456789012.", "3456"}}, - {"01234567890123456", 15, "..", []string{"0123456789012..", "3456"}}, - {"01234567890123456", 16, "...", []string{"0123456789012...", "3456"}}, - {"01234567890123456", 17, "...", []string{"01234567890123456"}}, - {"01234567890123456", 14, "abcdefg", []string{"0123456abcdefg", "7890123456"}}, - {"01234567890123456", 14, "abcdefghijkl", []string{ - "01abcdefghijkl", - "23abcdefghijkl", - "4567890123456", - }}, - // splitlen = markerlen => reset to default marker - {"01234567890123456", 14, "abcdefghijklmn", []string{"01234567890...", "123456"}}, - {longString, 0, "...", []string{longString[:longIdx] + "...", longString[longIdx:]}}, - {longString[:defaultSplit-1], 0, "...", []string{longString[:defaultSplit-1]}}, - {longString[:defaultSplit], 0, "...", []string{longString[:defaultSplit]}}, - {longString[:defaultSplit+1], 0, "...", []string{longString[:longIdx] + "...", longString[longIdx : defaultSplit+1]}}, + {"", 0, []string{""}}, + {"foo", 0, []string{"foo"}}, + {"foo bar baz beep", 0, []string{"foo bar baz beep"}}, + {"foo bar baz beep", 15, []string{"foo bar baz ...", "beep"}}, + {"foo bar, baz beep", 15, []string{"foo bar, ...", "baz beep"}}, + {"0123456789012345", 0, []string{"0123456789012345"}}, + {"0123456789012345", 15, []string{"012345678901...", "2345"}}, + {"0123456789012345", 16, []string{"0123456789012345"}}, } for i, test := range tests { - out := splitMessage(test.in, test.sp, test.mk) + out := splitMessage(test.in, test.sp) if !reflect.DeepEqual(test.out, out) { t.Errorf("test %d: expected %q, got %q", i, test.out, out) } diff --git a/client/connection.go b/client/connection.go index f4709f1..534ea2a 100644 --- a/client/connection.go +++ b/client/connection.go @@ -108,13 +108,9 @@ type Config struct { Sasl sasl.Client // Replaceable function to customise the 433 handler's new nick. - // By default the current nick's last character is "incremented". - // See DefaultNewNick implementation below for details. + // By default an underscore "_" is appended to the current nick. NewNick func(string) string - // A delay in NewNick before actually sending the new nick command. Default is not set, so it's 0. - ReNickDelay time.Duration - // Client->server ping frequency, in seconds. Defaults to 3m. // Set to 0 to disable client-side pings. PingFreq time.Duration @@ -139,8 +135,6 @@ type Config struct { // Split PRIVMSGs, NOTICEs and CTCPs longer than SplitLen characters // over multiple lines. Default to 450 if not set. SplitLen int - // Defaults to appending "..." to a split line to indicate a split. - SplitMarker string } // NewConfig creates a Config struct containing sensible defaults. @@ -154,7 +148,6 @@ func NewConfig(nick string, args ...string) *Config { NewNick: DefaultNewNick, Recover: (*Conn).LogPanic, // in dispatch.go SplitLen: defaultSplit, - SplitMarker: defaultMarker, Timeout: 60 * time.Second, EnableCapabilityNegotiation: false, } diff --git a/client/handlers.go b/client/handlers.go index 4a838ec..3920c02 100644 --- a/client/handlers.go +++ b/client/handlers.go @@ -310,9 +310,6 @@ func (conn *Conn) h_001(line *Line) { // Handler to deal with "433 :Nickname already in use" func (conn *Conn) h_433(line *Line) { - // Delay trying again if a non-zero delay was set - time.Sleep(conn.cfg.ReNickDelay) - // Args[1] is the new nick we were attempting to acquire me := conn.Me() neu := conn.cfg.NewNick(line.Args[1]) diff --git a/go.mod b/go.mod index 5475261..c87e5fb 100644 --- a/go.mod +++ b/go.mod @@ -3,9 +3,9 @@ module github.com/fluffle/goirc require ( github.com/emersion/go-sasl v0.0.0-20220912192320-0145f2c60ead github.com/fluffle/golog/logging v0.0.0-20180928190033-7d99e85061cb - github.com/golang/glog v1.2.5 + github.com/golang/glog v1.0.0 github.com/golang/mock v1.5.0 - golang.org/x/net v0.43.0 + golang.org/x/net v0.18.0 ) -go 1.23.0 +go 1.13 diff --git a/go.sum b/go.sum index fae7f50..6b12740 100644 --- a/go.sum +++ b/go.sum @@ -2,25 +2,56 @@ github.com/emersion/go-sasl v0.0.0-20220912192320-0145f2c60ead h1:fI1Jck0vUrXT8b github.com/emersion/go-sasl v0.0.0-20220912192320-0145f2c60ead/go.mod h1:iL2twTeMvZnrg54ZoPDNfJaJaqy0xIQFuBdrLsmspwQ= github.com/fluffle/golog/logging v0.0.0-20180928190033-7d99e85061cb h1:r//eMD/5sdzxVy34UP5fFvRWIL2L8QZtaDgVCKfVQLI= github.com/fluffle/golog/logging v0.0.0-20180928190033-7d99e85061cb/go.mod h1:w8+az2+kPHMcsaKnTnGapWTNToJK8BogkHiAncvqKsM= -github.com/golang/glog v1.2.5 h1:DrW6hGnjIhtvhOIiAKT6Psh/Kd/ldepEa81DKeiRJ5I= -github.com/golang/glog v1.2.5/go.mod h1:6AhwSGph0fcJtXVM/PEHPqZlFeoLxhs7/t5UDAwmO+w= +github.com/golang/glog v1.0.0 h1:nfP3RFugxnNRyKgeWd4oI1nYvXpxrx8ck8ZrcizshdQ= +github.com/golang/glog v1.0.0/go.mod h1:EWib/APOK0SL3dFbYqvxE3UYd8E6s1ouQ7iEp/0LWV4= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/mock v1.5.0 h1:jlYHihg//f7RRwuPfptm04yp4s7O6Kw8EZiVYIGcH0g= github.com/golang/mock v1.5.0/go.mod h1:CWnOUgYIOo4TcNZ0wHX3YZCqsaM1I1Jvs6v3mP3KVu8= -github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= -github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.15.0/go.mod h1:4ChreQoLWfG3xLDer1WdlH5NdlQ3+mwnQq1YTKY+72g= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20180926154720-4dfa2610cdf3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.43.0 h1:lat02VYK2j4aLzMzecihNvTlJNQUq316m2Mr9rnM6YE= -golang.org/x/net v0.43.0/go.mod h1:vhO1fvI4dGsIjh73sWfUVjj3N7CA9WkKJNQm2svM6Jg= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g= +golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= +golang.org/x/net v0.18.0 h1:mIYleuAkSbHh0tCv7RvjL3F6ZVbLjq4+R7zbOn3Kokg= +golang.org/x/net v0.18.0/go.mod h1:/czyP5RqHAH4odGYxBJ1qz0+CE5WZ+2j1YgoEo8F2jQ= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= +golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= +golang.org/x/term v0.14.0/go.mod h1:TySc+nGkYR6qt8km8wUhuFRTVSMIX3XPR58y2lC8vww= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=