From 2e3925035509c9a0daed9296411182fd5046f497 Mon Sep 17 00:00:00 2001 From: Alex Bramley Date: Tue, 23 Dec 2014 18:21:53 +0000 Subject: [PATCH] Allow Join command to take an optional key. --- client/commands.go | 10 ++++++++-- client/commands_test.go | 2 ++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/client/commands.go b/client/commands.go index 20e3a66..164e04e 100644 --- a/client/commands.go +++ b/client/commands.go @@ -96,8 +96,14 @@ func (conn *Conn) User(ident, name string) { conn.Raw(USER + " " + ident + " 12 * :" + name) } -// Join() sends a JOIN command to the server -func (conn *Conn) Join(channel string) { conn.Raw(JOIN + " " + channel) } +// Join() sends a JOIN command to the server with an optional key +func (conn *Conn) Join(channel string, key ...string) { + k := "" + if len(key) > 0 { + k = " " + key[0] + } + conn.Raw(JOIN + " " + channel + k) +} // Part() sends a PART command to the server with an optional part message func (conn *Conn) Part(channel string, message ...string) { diff --git a/client/commands_test.go b/client/commands_test.go index dabaf61..a4d457e 100644 --- a/client/commands_test.go +++ b/client/commands_test.go @@ -97,6 +97,8 @@ func TestClientCommands(t *testing.T) { c.Join("#foo") s.nc.Expect("JOIN #foo") + c.Join("#foo bar") + s.nc.Expect("JOIN #foo bar") c.Part("#foo") s.nc.Expect("PART #foo")