kunt

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

commit 83ac9fa45b48f071df7285e2124887f79ef7601a
parent 333c1c8ba96c788dee816981185f3dca0a85937c
Author: sin <sin@2f30.org>
Date:   Thu,  2 May 2013 18:12:08 +0100

update error handling in irc.go

Diffstat:
Msrc/irc/irc.go | 25++++++++++++++++++-------
1 file changed, 18 insertions(+), 7 deletions(-)

diff --git a/src/irc/irc.go b/src/irc/irc.go @@ -88,18 +88,18 @@ func (i *IrcContext) DelIntercept(ap *chan IrcMessage) int { } // Add a channel to the set of channels -func (i *IrcContext) AddChannel(s string) int { +func (i *IrcContext) AddChannel(s string) error { for c := 0; c < i.network.channum; c++ { if i.network.channels[c].name == s { - return -1 + return fmt.Errorf("Channel %s already added", s) } } if i.network.channum+1 < len(i.network.channels) { i.network.channels[i.network.channum] = ircChan{s, false} i.network.channum++ - return 0 + return nil } - return -1 + return fmt.Errorf("Too many channels added") } // Join all channels @@ -112,17 +112,28 @@ func (i *IrcContext) JoinChannels() { } } -func (i *IrcContext) PartChannel(s string) int { +func (i *IrcContext) PartChannel(s string) error { for c := 0; c < i.network.channum; c++ { if i.network.channels[c].name == s { if i.network.channels[c].joined { i.Part(s) i.network.channels[c].joined = false - return 0 + return nil + } else { + return fmt.Errorf("Channel %s is not joined\n", s) } } } - return -1 + return fmt.Errorf("Can't find channel %s", s) +} + +func (i *IrcContext) PartChannels(s []string) error { + for _, v := range s { + if err := i.PartChannel(v); err != nil { + return err + } + } + return nil } // Connect to the server. Do not join any channels by default.