Skip to content

Commit

Permalink
Add missing Client.FromChannel
Browse files Browse the repository at this point in the history
  • Loading branch information
belak committed Jan 17, 2017
1 parent ed3c9a9 commit f23d783
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
12 changes: 12 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,15 @@ func (c *Client) Run() error {
func (c *Client) CurrentNick() string {
return c.currentNick
}

// FromChannel takes a Message representing a PRIVMSG and returns if that
// message came from a channel or directly from a user.
func (c *Client) FromChannel(m *Message) bool {
if len(m.Params) < 1 {
return false
}

// The first param is the target, so if this doesn't match the current nick,
// the message came from a channel.
return m.Params[0] != c.currentNick
}
9 changes: 9 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,13 @@ func TestClientHandler(t *testing.T) {
Params: []string{"\x01VERSION"},
},
}, handler.Messages())

m := MustParseMessage("PRIVMSG test_nick :hello world")
assert.False(t, c.FromChannel(m))

m = MustParseMessage("PRIVMSG #a_channel :hello world")
assert.True(t, c.FromChannel(m))

m = MustParseMessage("PING")
assert.False(t, c.FromChannel(m))
}

0 comments on commit f23d783

Please sign in to comment.