kunt

golang IRC bot
git clone git://git.2f30.org/kunt
Log | Files | Refs | LICENSE

commit 722d1e5de5c686c653e3b05099592ba52e68683c
parent a5aaff19f49aaae4e010aa6ca70a7b0c9d63cc93
Author: sin <sin@2f30.org>
Date:   Wed,  8 May 2013 16:34:11 +0100

add channel iterator

Diffstat:
Msrc/irc/irc.go | 17+++++++++++++++++
1 file changed, 17 insertions(+), 0 deletions(-)

diff --git a/src/irc/irc.go b/src/irc/irc.go @@ -96,6 +96,23 @@ func (i *IrcContext) DelIntercept(ap *chan IrcMessage) error { return fmt.Errorf("Intercept not found") } +type ChanIter func() (channel string, key string, joined bool, ok bool) + +func MakeChanIter(i *IrcContext) ChanIter { + j := 0 + return func() (channel string, key string, joined bool, ok bool) { + i.Lock() + defer i.Unlock() + if j < len(i.network.channels) { + c := i.network.channels[j] + j++ + return c.name, c.key, c.joined, true + } else { + return "", "", false, false + } + } +} + func (i *IrcContext) JoinChannel(channel string, key string) error { i.Lock() defer i.Unlock()