Support other chantypes in (*Line).Public. Fixes #65.

This commit is contained in:
Alex Bramley 2015-07-28 18:10:23 +01:00
parent 8101dbaedd
commit fdb1c8229d
2 changed files with 10 additions and 9 deletions

View File

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

View File

@ -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"},
}