diff --git a/client/line.go b/client/line.go index 1877196..21d4dea 100644 --- a/client/line.go +++ b/client/line.go @@ -62,13 +62,14 @@ func (line *Line) Target() string { // a message to a channel the client has joined instead of directly // to the client. // -// NOTE: This makes the (poor) assumption that all channels start with #. +// NOTE: This is very permissive, allowing all 4 RFC channel types even if +// your server doesn't technically support them. func (line *Line) Public() bool { switch line.Cmd { case PRIVMSG, NOTICE, ACTION: - if strings.HasPrefix(line.Args[0], "#") { - return true - } + switch line.Args[0][0] { + case '#', '&', '+', '!': return true + } case CTCP, CTCPREPLY: // CTCP prepends the CTCP verb to line.Args, thus for the message // :nick!user@host PRIVMSG #foo :\001BAR baz\001 @@ -76,9 +77,9 @@ func (line *Line) Public() bool { // TODO(fluffle): Arguably this is broken, and we should have // line.Args containing: []string{"#foo", "BAR", "baz"} // ... OR change conn.Ctcp()'s argument order to be consistent. - if strings.HasPrefix(line.Args[1], "#") { - return true - } + switch line.Args[1][0] { + case '#', '&', '+', '!': return true + } } return false } diff --git a/client/line_test.go b/client/line_test.go index 61370f8..2a69782 100644 --- a/client/line_test.go +++ b/client/line_test.go @@ -69,8 +69,8 @@ func TestLineTarget(t *testing.T) { {&Line{Cmd: CTCP, Args: []string{"PING", "Me", "1"}, Nick: "Them"}, "Them"}, {&Line{Cmd: CTCPREPLY, Args: []string{"PONG", "Me", "2"}, Nick: "Them"}, "Them"}, {&Line{Cmd: PRIVMSG, Args: []string{"#foo", "la"}, Nick: "Them"}, "#foo"}, - {&Line{Cmd: NOTICE, Args: []string{"#foo", "la"}, Nick: "Them"}, "#foo"}, - {&Line{Cmd: ACTION, Args: []string{"#foo", "la"}, Nick: "Them"}, "#foo"}, + {&Line{Cmd: NOTICE, Args: []string{"&foo", "la"}, Nick: "Them"}, "&foo"}, + {&Line{Cmd: ACTION, Args: []string{"!foo", "la"}, Nick: "Them"}, "!foo"}, {&Line{Cmd: CTCP, Args: []string{"PING", "#foo", "1"}, Nick: "Them"}, "#foo"}, {&Line{Cmd: CTCPREPLY, Args: []string{"PONG", "#foo", "2"}, Nick: "Them"}, "#foo"}, }