diff --git a/pkg/irc/client.go b/pkg/irc/client.go index ecb1a292..7e73d051 100644 --- a/pkg/irc/client.go +++ b/pkg/irc/client.go @@ -119,6 +119,7 @@ func (c *Client) Join(channels ...string) { func (c *Client) Part(channels ...string) { c.Write("PART " + strings.Join(channels, ",")) + c.removeChannels(channels...) } func (c *Client) Topic(channel string, topic ...string) { @@ -183,6 +184,18 @@ func (c *Client) addChannel(channel string) { c.lock.Unlock() } +func (c *Client) removeChannels(channels ...string) { + c.lock.Lock() + for _, removeCh := range channels { + for i, ch := range c.channels { + if c.EqualFold(removeCh, ch) { + c.channels = append(c.channels[:i], c.channels[i+1:]...) + } + } + } + c.lock.Unlock() +} + func (c *Client) flushChannels() { c.lock.Lock() if len(c.channels) > 0 { diff --git a/pkg/irc/client_test.go b/pkg/irc/client_test.go index 5a025db4..3e724656 100644 --- a/pkg/irc/client_test.go +++ b/pkg/irc/client_test.go @@ -162,6 +162,8 @@ func TestFlushChannels(t *testing.T) { c.flushChannels() assert.Equal(t, <-out, "JOIN #chan1\r\n") c.addChannel("#chan2") + c.addChannel("#chan4") + c.removeChannels("#chan4") c.addChannel("#chan3") c.flushChannels() assert.Equal(t, <-out, "JOIN #chan2,#chan3\r\n")