Skip to content

Commit f23d783

Browse files
committed
Add missing Client.FromChannel
1 parent ed3c9a9 commit f23d783

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

client.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,15 @@ func (c *Client) Run() error {
105105
func (c *Client) CurrentNick() string {
106106
return c.currentNick
107107
}
108+
109+
// FromChannel takes a Message representing a PRIVMSG and returns if that
110+
// message came from a channel or directly from a user.
111+
func (c *Client) FromChannel(m *Message) bool {
112+
if len(m.Params) < 1 {
113+
return false
114+
}
115+
116+
// The first param is the target, so if this doesn't match the current nick,
117+
// the message came from a channel.
118+
return m.Params[0] != c.currentNick
119+
}

client_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,4 +154,13 @@ func TestClientHandler(t *testing.T) {
154154
Params: []string{"\x01VERSION"},
155155
},
156156
}, handler.Messages())
157+
158+
m := MustParseMessage("PRIVMSG test_nick :hello world")
159+
assert.False(t, c.FromChannel(m))
160+
161+
m = MustParseMessage("PRIVMSG #a_channel :hello world")
162+
assert.True(t, c.FromChannel(m))
163+
164+
m = MustParseMessage("PING")
165+
assert.False(t, c.FromChannel(m))
157166
}

0 commit comments

Comments
 (0)