From 7cadb5618377a47258cdea61498a73bd9862af9e Mon Sep 17 00:00:00 2001 From: Liam Stanley Date: Sat, 27 Jan 2018 20:01:27 -0500 Subject: [PATCH] add Client.HasCapability() method --- client.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/client.go b/client.go index 29d7c02..ee5f669 100644 --- a/client.go +++ b/client.go @@ -652,6 +652,30 @@ func (c *Client) Latency() time.Duration { return delta } +// HasCapability checks if the client connection has the given capability. If +// you want the full list of capabilities, listen for the girc.CAP_ACK event. +// Will panic if used when tracking has been disabled. +func (c *Client) HasCapability(name string) (has bool) { + c.panicIfNotTracking() + + if !c.IsConnected() { + return false + } + + name = strings.ToLower(name) + + c.state.RLock() + for i := 0; i < len(c.state.enabledCap); i++ { + if strings.ToLower(c.state.enabledCap[i]) == name { + has = true + break + } + } + c.state.RUnlock() + + return has +} + // panicIfNotTracking will throw a panic when it's called, and tracking is // disabled. Adds useful info like what function specifically, and where it // was called from.