From eb92a84e96061ffb82cc81d9530f45b031ef8122 Mon Sep 17 00:00:00 2001 From: StalkR Date: Sun, 6 Jan 2013 19:29:53 +0100 Subject: [PATCH 1/2] state: channel: add Nicks() and NicksStr() accessors for nicks on channel --- state/channel.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/state/channel.go b/state/channel.go index e25c4b9..2efa424 100644 --- a/state/channel.go +++ b/state/channel.go @@ -210,6 +210,24 @@ func (ch *Channel) ParseModes(modes string, modeargs ...string) { } } +// Nicks returns a list of *Nick that are on the channel. +func (ch *Channel) Nicks() []*Nick { + nicks := make([]*Nick, 0, len(ch.lookup)) + for _, nick := range ch.lookup { + nicks = append(nicks, nick) + } + return nicks +} + +// NicksStr returns a list of nick strings that are on the channel. +func (ch *Channel) NicksStr() []string { + nicks := make([]string, 0, len(ch.lookup)) + for _, nick := range ch.lookup { + nicks = append(nicks, nick.Nick) + } + return nicks +} + // Returns a string representing the channel. Looks like: // Channel: e.g. #moo // Topic: e.g. Discussing the merits of cows! From 2cc4e94acb1d6d8f7d389981b734463d05a947fa Mon Sep 17 00:00:00 2001 From: StalkR Date: Sun, 6 Jan 2013 20:13:06 +0100 Subject: [PATCH 2/2] 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