add Client.HasCapability() method
This commit is contained in:
parent
9517b2fb8c
commit
7cadb56183
24
client.go
24
client.go
@ -652,6 +652,30 @@ func (c *Client) Latency() time.Duration {
|
|||||||
return delta
|
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
|
// panicIfNotTracking will throw a panic when it's called, and tracking is
|
||||||
// disabled. Adds useful info like what function specifically, and where it
|
// disabled. Adds useful info like what function specifically, and where it
|
||||||
// was called from.
|
// was called from.
|
||||||
|
Loading…
Reference in New Issue
Block a user