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 {
105
105
func (c * Client ) CurrentNick () string {
106
106
return c .currentNick
107
107
}
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) {
154
154
Params : []string {"\x01 VERSION" },
155
155
},
156
156
}, 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 ))
157
166
}
You can’t perform that action at this time.
0 commit comments