From 2cc4e94acb1d6d8f7d389981b734463d05a947fa Mon Sep 17 00:00:00 2001 From: StalkR Date: Sun, 6 Jan 2013 20:13:06 +0100 Subject: [PATCH] state: nick: add Channels/ChannelsStr accessors to get channels a nick is on --- state/nick.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/state/nick.go b/state/nick.go index 457bec1..aad0988 100644 --- a/state/nick.go +++ b/state/nick.go @@ -110,6 +110,24 @@ func (nk *Nick) ParseModes(modes string) { } } +// Channels returns a list of *Channel the nick is on. +func (nk *Nick) Channels() []*Channel { + channels := make([]*Channel, 0, len(nk.lookup)) + for _, channel := range nk.lookup { + channels = append(channels, channel) + } + return channels +} + +// ChannelsStr returns a list of channel strings the nick is on. +func (nk *Nick) ChannelsStr() []string { + channels := make([]string, 0, len(nk.lookup)) + for _, channel := range nk.lookup { + channels = append(channels, channel.Name) + } + return channels +} + // Returns a string representing the nick. Looks like: // Nick: e.g. CowMaster // Hostmask: e.g. moo@cows.org