Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
}