File tree Expand file tree Collapse file tree 2 files changed +21
-0
lines changed
Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -105,3 +105,15 @@ func (c *Client) Run() error {
105105func (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+ }
Original file line number Diff line number Diff line change @@ -154,4 +154,13 @@ func TestClientHandler(t *testing.T) {
154154 Params : []string {"\x01 VERSION" },
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}
You can’t perform that action at this time.
0 commit comments